Panda3D
 All Classes Functions Variables Enumerations
xFileDataDef.h
1 // Filename: xFileDataDef.h
2 // Created by: drose (03Oct04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef XFILEDATADEF_H
16 #define XFILEDATADEF_H
17 
18 #include "pandatoolbase.h"
19 #include "namable.h"
20 #include "xFileNode.h"
21 #include "xFileArrayDef.h"
22 #include "xFileTemplate.h"
23 #include "xFileDataObject.h"
24 #include "pvector.h"
25 #include "pointerTo.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : XFileDataDef
29 // Description : A definition of a single data element appearing
30 // within a template record. This class represents the
31 // *definition* of the data element (e.g. DWORD
32 // nVertices); see XFileDataObject for its *value*
33 // (e.g. 12).
34 ////////////////////////////////////////////////////////////////////
35 class XFileDataDef : public XFileNode {
36 public:
37  enum Type {
38  T_word,
39  T_dword,
40  T_float,
41  T_double,
42  T_char,
43  T_uchar,
44  T_sword,
45  T_sdword,
46  T_string,
47  T_cstring,
48  T_unicode,
49  T_template,
50  };
51 
52  INLINE XFileDataDef(XFile *x_file, const string &name,
53  Type type, XFileTemplate *xtemplate = NULL);
54  virtual ~XFileDataDef();
55 
56  virtual void clear();
57  void add_array_def(const XFileArrayDef &array_def);
58 
59  INLINE Type get_data_type() const;
60  INLINE XFileTemplate *get_template() const;
61 
62  INLINE int get_num_array_defs() const;
63  INLINE const XFileArrayDef &get_array_def(int i) const;
64 
65  virtual void write_text(ostream &out, int indent_level) const;
66 
67  virtual bool repack_data(XFileDataObject *object,
68  const XFileParseDataList &parse_data_list,
69  PrevData &prev_data,
70  size_t &index, size_t &sub_index) const;
71 
72  virtual bool fill_zero_data(XFileDataObject *object) const;
73 
74  virtual bool matches(const XFileNode *other) const;
75 
76 private:
77  typedef PT(XFileDataObject)
78  (XFileDataDef::*UnpackMethod)(const XFileParseDataList &parse_data_list,
79  const PrevData &prev_data,
80  size_t &index, size_t &sub_index) const;
81  typedef PT(XFileDataObject)
82  (XFileDataDef::*ZeroFillMethod)() const;
83 
84  PT(XFileDataObject)
85  unpack_integer_value(const XFileParseDataList &parse_data_list,
86  const PrevData &prev_data,
87  size_t &index, size_t &sub_index) const;
88  PT(XFileDataObject)
89  unpack_double_value(const XFileParseDataList &parse_data_list,
90  const PrevData &prev_data,
91  size_t &index, size_t &sub_index) const;
92  PT(XFileDataObject)
93  unpack_string_value(const XFileParseDataList &parse_data_list,
94  const PrevData &prev_data,
95  size_t &index, size_t &sub_index) const;
96  PT(XFileDataObject)
97  unpack_template_value(const XFileParseDataList &parse_data_list,
98  const PrevData &prev_data,
99  size_t &index, size_t &sub_index) const;
100 
101  PT(XFileDataObject)
102  unpack_value(const XFileParseDataList &parse_data_list, int array_index,
103  const PrevData &prev_data,
104  size_t &index, size_t &sub_index,
105  UnpackMethod unpack_method) const;
106 
107  PT(XFileDataObject) zero_fill_integer_value() const;
108  PT(XFileDataObject) zero_fill_double_value() const;
109  PT(XFileDataObject) zero_fill_string_value() const;
110  PT(XFileDataObject) zero_fill_template_value() const;
111  PT(XFileDataObject)
112  zero_fill_value(int array_index, ZeroFillMethod zero_fill_method) const;
113 
114 private:
115  Type _type;
116  PT(XFileTemplate) _template;
117 
119  ArrayDef _array_def;
120 
121 public:
122  static TypeHandle get_class_type() {
123  return _type_handle;
124  }
125  static void init_type() {
126  XFileNode::init_type();
127  register_type(_type_handle, "XFileDataDef",
128  XFileNode::get_class_type());
129  }
130  virtual TypeHandle get_type() const {
131  return get_class_type();
132  }
133  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
134 
135 private:
136  static TypeHandle _type_handle;
137 };
138 
139 #include "xFileDataDef.I"
140 
141 #endif
142 
143 
144 
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
virtual void write_text(ostream &out, int indent_level) const
Writes a suitable representation of this node to an .x file in text mode.
void add_array_def(const XFileArrayDef &array_def)
Adds an additional array dimension to the data description.
virtual bool fill_zero_data(XFileDataObject *object) const
This is similar to repack_data(), except it is used to fill the initial values for a newly-created te...
Defines one level of array bounds for an associated XFileDataDef element.
Definition: xFileArrayDef.h:29
virtual bool matches(const XFileNode *other) const
Returns true if the node, particularly a template node, is structurally equivalent to the other node ...
A definition of a single data element appearing within a template record.
Definition: xFileDataDef.h:35
A single node of an X file.
Definition: xFileNode.h:42
XFileTemplate * get_template() const
If get_data_type() returned T_template, this returns the particular template pointer that this object...
Definition: xFileDataDef.I:50
virtual bool repack_data(XFileDataObject *object, const XFileParseDataList &parse_data_list, PrevData &prev_data, size_t &index, size_t &sub_index) const
This is called on the template that defines an object, once the data for the object has been parsed...
int get_num_array_defs() const
Returns the number of dimensions of array elements on this data object, or 0 if the data object is no...
Definition: xFileDataDef.I:62
A container for a pvector of the above objects.
const XFileArrayDef & get_array_def(int i) const
Returns the description of the nth dimension of array elements on this data object.
Definition: xFileDataDef.I:73
virtual void clear()
Removes all children from the node, and otherwise resets it to its initial state. ...
This represents the complete contents of an X file (file.x) in memory.
Definition: xFile.h:35
A template definition in the X file.
Definition: xFileTemplate.h:29
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
Type get_data_type() const
Returns the primitive type of this element, or T_template if this represents a nested template object...
Definition: xFileDataDef.I:38
The abstract base class for a number of different types of data elements that may be stored in the X ...