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