15 #include "xFileDataNodeTemplate.h"
17 #include "xFileParseData.h"
18 #include "xLexerDefs.h"
19 #include "config_xfile.h"
21 TypeHandle XFileDataNodeTemplate::_type_handle;
28 XFileDataNodeTemplate::
29 XFileDataNodeTemplate(
XFile *x_file,
const string &name,
43 _template->fill_zero_data(
this);
68 pdata._double_list = double_list;
69 pdata._parse_flags = XFileParseData::PF_double;
71 _parse_data_list._list.push_back(pdata);
84 pdata._int_list = int_list;
85 pdata._parse_flags = XFileParseData::PF_int;
87 _parse_data_list._list.push_back(pdata);
101 pdata._parse_flags = XFileParseData::PF_string;
103 _parse_data_list._list.push_back(pdata);
122 size_t sub_index = 0;
124 if (!_template->repack_data(
this, _parse_data_list,
125 prev_data, index, sub_index)) {
129 if (index != _parse_data_list._list.size()) {
130 xyywarning(
"Too many data elements in structure.");
146 _nested_elements.push_back(element);
158 indent(out, indent_level)
159 << _template->get_name();
161 out <<
" " << get_name();
165 NestedElements::const_iterator ni;
166 for (ni = _nested_elements.begin(); ni != _nested_elements.end(); ++ni) {
167 (*ni)->write_data(out, indent_level + 2,
";");
171 indent(out, indent_level)
182 write_data(ostream &out,
int indent_level,
const char *separator)
const {
183 if (!_nested_elements.empty()) {
184 bool indented =
false;
185 for (
size_t i = 0;
i < _nested_elements.size() - 1;
i++) {
194 object->write_data(out, indent_level,
";");
199 indent(out, indent_level);
202 out << *
object <<
"; ";
213 string combined_separator = string(
";") + string(separator);
214 object->write_data(out, indent_level, combined_separator.c_str());
218 indent(out, indent_level);
220 out << *
object <<
";" << separator <<
"\n";
232 int XFileDataNodeTemplate::
233 get_num_elements()
const {
234 return _nested_elements.size();
245 nassertr(n >= 0 && n < (
int)_nested_elements.size(), NULL);
246 return _nested_elements[n];
256 get_element(
const string &name) {
257 int child_index = _template->find_child_index(name);
258 if (child_index >= 0) {
259 return get_element(child_index);
262 <<
"\"" << 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.
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.
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...
void add_parse_string(const string &str)
Adds the indicated string as a data element encountered in the parser.
virtual bool is_complex_object() const
Returns true if this kind of data object is a complex object that can hold nested data elements...
bool finalize_parse_data()
Processes all of the data elements added by add_parse_*(), checks them for syntactic and semantic cor...
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 void write_text(ostream &out, int indent_level) const
Writes a suitable representation of this node to an .x file in text mode.
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.
virtual void write_data(ostream &out, int indent_level, const char *separator) const
Writes a suitable representation of this node to an .x file in text mode.
TypeHandle is the identifier used to differentiate C++ class types.
The abstract base class for a number of different types of data elements that may be stored in the X ...
int i() const
Unambiguously returns the object's representation as an integer, or 0 if the object has no integer re...