49 _array_def.push_back(array_def);
59 if (!_array_def.empty()) {
109 out << _template->get_name();
114 out <<
" " << get_name();
117 ArrayDef::const_iterator ai;
118 for (ai = _array_def.begin(); ai != _array_def.end(); ++ai) {
138 size_t &index,
size_t &sub_index)
const {
151 data_value = unpack_value(parse_data_list, 0,
152 prev_data, index, sub_index,
153 &XFileDataDef::unpack_integer_value);
158 data_value = unpack_value(parse_data_list, 0,
159 prev_data, index, sub_index,
160 &XFileDataDef::unpack_double_value);
166 data_value = unpack_value(parse_data_list, 0,
167 prev_data, index, sub_index,
168 &XFileDataDef::unpack_string_value);
172 data_value = unpack_value(parse_data_list, 0,
173 prev_data, index, sub_index,
174 &XFileDataDef::unpack_template_value);
178 if (data_value !=
nullptr) {
179 object->add_element(data_value);
180 prev_data[
this] = data_value;
184 prev_data, index, sub_index);
203 data_value = zero_fill_value(0, &XFileDataDef::zero_fill_integer_value);
208 data_value = zero_fill_value(0, &XFileDataDef::zero_fill_double_value);
214 data_value = zero_fill_value(0, &XFileDataDef::zero_fill_string_value);
218 data_value = zero_fill_value(0, &XFileDataDef::zero_fill_template_value);
222 if (data_value !=
nullptr) {
223 object->add_element(data_value);
272 size_t &index,
size_t &sub_index)
const {
273 nassertr(index < parse_data_list._list.size(),
nullptr);
278 if ((parse_data._parse_flags & XFileParseData::PF_int) != 0) {
279 nassertr(sub_index < parse_data._int_list.size(),
nullptr);
280 int value = parse_data._int_list[sub_index];
284 if (sub_index >= parse_data._int_list.size()) {
290 parse_data.yyerror(
"Expected integer data for " + get_name());
303 size_t &index,
size_t &sub_index)
const {
304 nassertr(index < parse_data_list._list.size(),
nullptr);
309 if ((parse_data._parse_flags & XFileParseData::PF_double) != 0) {
310 nassertr(sub_index < parse_data._double_list.size(),
nullptr);
311 double value = parse_data._double_list[sub_index];
315 if (sub_index >= parse_data._double_list.size()) {
320 }
else if ((parse_data._parse_flags & XFileParseData::PF_int) != 0) {
321 nassertr(sub_index < parse_data._int_list.size(),
nullptr);
322 int value = parse_data._int_list[sub_index];
326 if (sub_index >= parse_data._int_list.size()) {
332 parse_data.yyerror(
"Expected floating-point data for " + get_name());
345 size_t &index,
size_t &sub_index)
const {
346 nassertr(index < parse_data_list._list.size(),
nullptr);
351 if ((parse_data._parse_flags & XFileParseData::PF_string) != 0) {
357 parse_data.yyerror(
"Expected string data for " + get_name());
369 size_t &index,
size_t &sub_index)
const {
373 PrevData nested_prev_data(prev_data);
374 if (!_template->repack_data(data_value, parse_data_list,
375 nested_prev_data, index, sub_index)) {
390 size_t &index,
size_t &sub_index,
391 XFileDataDef::UnpackMethod unpack_method)
const {
394 if (array_index == (
int)_array_def.size()) {
395 if (index >= parse_data_list._list.size()) {
396 xyyerror(
"Not enough data elements in structure at " + get_name());
399 data_value = (this->*unpack_method)(parse_data_list, prev_data,
404 int array_size = _array_def[array_index].get_size(prev_data);
406 for (
int i = 0; i < array_size; i++) {
407 if (index >= parse_data_list._list.size()) {
408 xyyerror(std::string(
"Expected ") + format_string(array_size)
409 +
" array elements, found " + format_string(i));
414 unpack_value(parse_data_list, array_index + 1,
415 prev_data, index, sub_index,
417 if (array_element ==
nullptr) {
420 data_value->add_element(array_element);
431 zero_fill_integer_value()
const {
439 zero_fill_double_value()
const {
447 zero_fill_string_value()
const {
455 zero_fill_template_value()
const {
458 if (!_template->fill_zero_data(data_value)) {
471 zero_fill_value(
int array_index,
472 XFileDataDef::ZeroFillMethod zero_fill_method)
const {
475 if (array_index == (
int)_array_def.size()) {
476 data_value = (this->*zero_fill_method)();
481 if (_array_def[array_index].is_fixed_size()) {
482 array_size = _array_def[array_index].get_fixed_size();
485 for (
int i = 0; i < array_size; i++) {
487 zero_fill_value(array_index + 1, zero_fill_method);
488 if (array_element ==
nullptr) {
491 data_value->add_element(array_element);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 ...
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.
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...
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...
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
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.
An double-valued data element.
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.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 ...
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 ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.