15 #include "xFileDataDef.h" 17 #include "xLexerDefs.h" 18 #include "xFileParseData.h" 19 #include "xFileDataObjectInteger.h" 20 #include "xFileDataObjectDouble.h" 21 #include "xFileDataObjectString.h" 22 #include "xFileDataNodeTemplate.h" 23 #include "xFileDataObjectArray.h" 24 #include "string_utils.h" 57 _array_def.push_back(array_def);
68 indent(out, indent_level);
70 if (!_array_def.empty()) {
120 out << _template->get_name();
125 out <<
" " << get_name();
128 ArrayDef::const_iterator ai;
129 for (ai = _array_def.begin(); ai != _array_def.end(); ++ai) {
153 size_t &index,
size_t &sub_index)
const {
166 data_value = unpack_value(parse_data_list, 0,
167 prev_data, index, sub_index,
168 &XFileDataDef::unpack_integer_value);
173 data_value = unpack_value(parse_data_list, 0,
174 prev_data, index, sub_index,
175 &XFileDataDef::unpack_double_value);
181 data_value = unpack_value(parse_data_list, 0,
182 prev_data, index, sub_index,
183 &XFileDataDef::unpack_string_value);
187 data_value = unpack_value(parse_data_list, 0,
188 prev_data, index, sub_index,
189 &XFileDataDef::unpack_template_value);
194 object->add_element(data_value);
195 prev_data[
this] = data_value;
199 prev_data, index, sub_index);
221 data_value = zero_fill_value(0, &XFileDataDef::zero_fill_integer_value);
226 data_value = zero_fill_value(0, &XFileDataDef::zero_fill_double_value);
232 data_value = zero_fill_value(0, &XFileDataDef::zero_fill_string_value);
236 data_value = zero_fill_value(0, &XFileDataDef::zero_fill_template_value);
241 object->add_element(data_value);
296 size_t &index,
size_t &sub_index)
const {
297 nassertr(index < parse_data_list._list.size(), NULL);
302 if ((parse_data._parse_flags & XFileParseData::PF_int) != 0) {
303 nassertr(sub_index < parse_data._int_list.size(), NULL);
304 int value = parse_data._int_list[sub_index];
308 if (sub_index >= parse_data._int_list.size()) {
314 parse_data.yyerror(
"Expected integer data for " + get_name());
329 size_t &index,
size_t &sub_index)
const {
330 nassertr(index < parse_data_list._list.size(), NULL);
335 if ((parse_data._parse_flags & XFileParseData::PF_double) != 0) {
336 nassertr(sub_index < parse_data._double_list.size(), NULL);
337 double value = parse_data._double_list[sub_index];
341 if (sub_index >= parse_data._double_list.size()) {
346 }
else if ((parse_data._parse_flags & XFileParseData::PF_int) != 0) {
347 nassertr(sub_index < parse_data._int_list.size(), NULL);
348 int value = parse_data._int_list[sub_index];
352 if (sub_index >= parse_data._int_list.size()) {
358 parse_data.yyerror(
"Expected floating-point data for " + get_name());
373 size_t &index,
size_t &sub_index)
const {
374 nassertr(index < parse_data_list._list.size(), NULL);
379 if ((parse_data._parse_flags & XFileParseData::PF_string) != 0) {
385 parse_data.yyerror(
"Expected string data for " + get_name());
399 size_t &index,
size_t &sub_index)
const {
403 PrevData nested_prev_data(prev_data);
404 if (!_template->repack_data(data_value, parse_data_list,
405 nested_prev_data, index, sub_index)) {
409 return data_value.p();
423 size_t &index,
size_t &sub_index,
424 XFileDataDef::UnpackMethod unpack_method)
const {
427 if (array_index == (
int)_array_def.size()) {
428 if (index >= parse_data_list._list.size()) {
429 xyyerror(
"Not enough data elements in structure at " + get_name());
432 data_value = (this->*unpack_method)(parse_data_list, prev_data,
437 int array_size = _array_def[array_index].get_size(prev_data);
439 for (
int i = 0; i < array_size; i++) {
440 if (index >= parse_data_list._list.size()) {
441 xyyerror(
string(
"Expected ") + format_string(array_size)
442 +
" array elements, found " + format_string(i));
447 unpack_value(parse_data_list, array_index + 1,
448 prev_data, index, sub_index,
453 data_value->add_element(array_element);
466 zero_fill_integer_value()
const {
476 zero_fill_double_value()
const {
486 zero_fill_string_value()
const {
497 zero_fill_template_value()
const {
500 if (!_template->fill_zero_data(data_value)) {
516 zero_fill_value(
int array_index,
517 XFileDataDef::ZeroFillMethod zero_fill_method)
const {
520 if (array_index == (
int)_array_def.size()) {
521 data_value = (this->*zero_fill_method)();
526 if (_array_def[array_index].is_fixed_size()) {
527 array_size = _array_def[array_index].get_fixed_size();
530 for (
int i = 0; i < array_size; i++) {
532 zero_fill_value(array_index + 1, zero_fill_method);
This is our own Panda specialization on the default STL map.
virtual bool matches(const XFileNode *other) const
Returns true if the node, particularly a template node, is structurally equivalent to the other node ...
virtual bool add_element(XFileDataObject *element)
Adds the indicated element as a nested data element, if this data object type supports it...
void add_array_def(const XFileArrayDef &array_def)
Adds an additional array dimension to the data description.
virtual void write_text(ostream &out, int indent_level) const
Writes a suitable representation of this node to an .x file in text mode.
virtual bool matches(const XFileNode *other) const
Returns true if the node, particularly a template node, is structurally equivalent to the other node ...
Defines one level of array bounds for an associated XFileDataDef element.
An string-valued data element.
This class is used to fill up the data into an XFileDataNodeTemplate object as the data values are pa...
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...
A definition of a single data element appearing within a template record.
This is a node which contains all of the data elements defined by a template.
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...
A single node of an X file.
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...
An integer-valued data element.
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.
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...
virtual void clear()
Removes all children from the node, and otherwise resets it to its initial state. ...
An double-valued data element.
virtual void clear()
Removes all children from the node, and otherwise resets it to its initial state. ...
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...
bool has_name() const
Returns true if the Namable has a nonempty name set, false if the name is empty.
An array of nested data elements.
TypeHandle is the identifier used to differentiate C++ class types.
const XFileArrayDef & get_array_def(int i) const
Returns the description of the nth dimension of array elements on this data object.
bool matches(const XFileArrayDef &other, const XFileDataDef *parent, const XFileDataDef *other_parent) const
Returns true if the node, particularly a template node, is structurally equivalent to the other node ...
The abstract base class for a number of different types of data elements that may be stored in the X ...