22 TypeHandle XFileDataNodeTemplate::_type_handle;
27 XFileDataNodeTemplate::
28 XFileDataNodeTemplate(
XFile *x_file,
const string &name,
39 _template->fill_zero_data(
this);
58 pdata._double_list = double_list;
59 pdata._parse_flags = XFileParseData::PF_double;
61 _parse_data_list._list.push_back(pdata);
71 pdata._int_list = int_list;
72 pdata._parse_flags = XFileParseData::PF_int;
74 _parse_data_list._list.push_back(pdata);
85 pdata._parse_flags = XFileParseData::PF_string;
87 _parse_data_list._list.push_back(pdata);
103 size_t sub_index = 0;
105 if (!_template->repack_data(
this, _parse_data_list,
106 prev_data, index, sub_index)) {
110 if (index != _parse_data_list._list.size()) {
111 xyywarning(
"Too many data elements in structure.");
124 _nested_elements.push_back(element);
134 << _template->get_name();
136 out <<
" " << get_name();
140 NestedElements::const_iterator ni;
141 for (ni = _nested_elements.begin(); ni != _nested_elements.end(); ++ni) {
142 (*ni)->write_data(out, indent_level + 2,
";");
154 write_data(std::ostream &out,
int indent_level,
const char *separator)
const {
155 if (!_nested_elements.empty()) {
156 bool indented =
false;
157 for (
size_t i = 0;
i < _nested_elements.size() - 1;
i++) {
165 object->write_data(out, indent_level,
";");
170 indent(out, indent_level);
173 out << *
object <<
"; ";
184 string combined_separator = string(
";") + string(separator);
185 object->write_data(out, indent_level, combined_separator.c_str());
189 indent(out, indent_level);
191 out << *
object <<
";" << separator <<
"\n";
200 int XFileDataNodeTemplate::
201 get_num_elements()
const {
202 return _nested_elements.size();
210 nassertr(n >= 0 && n < (
int)_nested_elements.size(),
nullptr);
211 return _nested_elements[n];
219 get_element(
const string &name) {
220 int child_index = _template->find_child_index(name);
221 if (child_index >= 0) {
222 return get_element(child_index);
225 <<
"\"" << name <<
"\" not a member of " << _template->get_name()
virtual bool add_element(XFileDataObject *element)
Adds the indicated element as a nested data element, if this data object type supports it.
This is our own Panda specialization on the default STL map.
void add_parse_double(PTA_double double_list)
Adds the indicated list of doubles as a data element encountered in the parser.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int i() const
Unambiguously returns the object's representation as an integer, or 0 if the object has no integer re...
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 class is used to fill up the data into an XFileDataNodeTemplate object as the data values are pa...
void zero_fill()
Fills the data node with zero-valued elements appropriate to the template.
void add_parse_int(PTA_int int_list)
Adds the indicated list of ints as a data element encountered in the parser.
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 void write_data(std::ostream &out, int indent_level, const char *separator) const
Writes a suitable representation of this node to an .x file in text mode.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
virtual bool is_complex_object() const
Returns true if this kind of data object is a complex object that can hold nested data elements,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool finalize_parse_data()
Processes all of the data elements added by add_parse_*(), checks them for syntactic and semantic cor...
This is an abstract base class for an XFileNode which is also an XFileDataObject.
This represents the complete contents of an X file (file.x) in memory.
A template definition in the X file.
bool has_name() const
Returns true if the Namable has a nonempty name set, false if the name is empty.
virtual bool is_complex_object() const
Returns true if this kind of data object is a complex object that can hold nested data elements,...
TypeHandle is the identifier used to differentiate C++ class types.
void add_parse_string(const std::string &str)
Adds the indicated string as a data element encountered in the parser.
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.