packed_data_container.h
1 /*************************************************************************/
2 /* packed_data_container.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef PACKED_DATA_CONTAINER_H
30 #define PACKED_DATA_CONTAINER_H
31 
32 
33 #include "resource.h"
34 
35 
36 
37 class PackedDataContainer : public Resource {
38 
39  OBJ_TYPE(PackedDataContainer,Resource);
40 
41  enum {
42  TYPE_DICT=0xFFFFFFFF,
43  TYPE_ARRAY=0xFFFFFFFE,
44  };
45 
46  struct DictKey {
47  uint32_t hash;
48  Variant key;
49  bool operator<(const DictKey& p_key) const { return hash < p_key.hash; }
50  };
51 
52 
53  DVector<uint8_t> data;
54  int datalen;
55 
56 
57  uint32_t _pack(const Variant& p_data,Vector<uint8_t>& tmpdata,Map<String,uint32_t>& string_cache);
58 
59 
60  Variant _iter_init_ofs(const Array& p_iter,uint32_t p_offset);
61  Variant _iter_next_ofs(const Array& p_iter,uint32_t p_offset);
62  Variant _iter_get_ofs(const Variant& p_iter,uint32_t p_offset);
63 
64  Variant _iter_init(const Array& p_iter);
65  Variant _iter_next(const Array& p_iter);
66  Variant _iter_get(const Variant& p_iter);
67 
68 friend class PackedDataContainerRef;
69  Variant _key_at_ofs(uint32_t p_ofs,const Variant& p_key,bool &err) const;
70  Variant _get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, bool &err) const;
71  uint32_t _type_at_ofs(uint32_t p_ofs) const;
72  int _size(uint32_t p_ofs) const;
73 
74 protected:
75 
76  void _set_data(const DVector<uint8_t>& p_data);
77  DVector<uint8_t> _get_data() const;
78  static void _bind_methods();
79 public:
80 
81  virtual Variant getvar(const Variant& p_key, bool *r_valid=NULL) const;
82  Error pack(const Variant& p_data);
83 
84  int size() const;
85 
87 };
88 
91 
92 friend class PackedDataContainer;
93  uint32_t offset;
95 
96 protected:
97  static void _bind_methods();
98 
99 public:
100 
101  Variant _iter_init(const Array& p_iter);
102  Variant _iter_next(const Array& p_iter);
103  Variant _iter_get(const Variant& p_iter);
104  bool _is_dictionary() const;
105 
106  int size() const;
107  virtual Variant getvar(const Variant& p_key, bool *r_valid=NULL) const;
108 
110 };
111 
112 #endif // PACKED_DATA_CONTAINER_H
Definition: packed_data_container.h:89
Definition: array.h:38
Definition: variant.h:74
Definition: packed_data_container.h:37
Definition: reference.h:40
Definition: resource.h:89
Definition: map.h:41