Panda3D
Loading...
Searching...
No Matches
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 */
31class XFileDataDef : public XFileNode {
32public:
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
72private:
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
81 unpack_integer_value(const XFileParseDataList &parse_data_list,
82 const PrevData &prev_data,
83 size_t &index, size_t &sub_index) const;
85 unpack_double_value(const XFileParseDataList &parse_data_list,
86 const PrevData &prev_data,
87 size_t &index, size_t &sub_index) const;
89 unpack_string_value(const XFileParseDataList &parse_data_list,
90 const PrevData &prev_data,
91 size_t &index, size_t &sub_index) const;
93 unpack_template_value(const XFileParseDataList &parse_data_list,
94 const PrevData &prev_data,
95 size_t &index, size_t &sub_index) const;
96
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;
108 zero_fill_value(int array_index, ZeroFillMethod zero_fill_method) const;
109
110private:
111 Type _type;
112 PT(XFileTemplate) _template;
113
115 ArrayDef _array_def;
116
117public:
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
131private:
132 static TypeHandle _type_handle;
133};
134
135#include "xFileDataDef.I"
136
137#endif
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Defines one level of array bounds for an associated XFileDataDef element.
A definition of a single data element appearing within a template record.
Type get_data_type() const
Returns the primitive type of this element, or T_template if this represents a nested template object...
const XFileArrayDef & get_array_def(int i) const
Returns the description of the nth dimension of array elements on this data object.
void add_array_def(const XFileArrayDef &array_def)
Adds an additional array dimension to the data description.
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.
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...
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...
virtual void clear()
Removes all children from the node, and otherwise resets it to its initial state.
virtual bool matches(const XFileNode *other) const
Returns true if the node, particularly a template node, is structurally equivalent to the other node ...
XFileTemplate * get_template() const
If get_data_type() returned T_template, this returns the particular template pointer that this object...
The abstract base class for a number of different types of data elements that may be stored in the X ...
A single node of an X file.
Definition xFileNode.h:40
A container for a pvector of the above objects.
A template definition in the X file.
This represents the complete contents of an X file (file.x) in memory.
Definition xFile.h:32
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.