Panda3D
xFileDataNodeReference.cxx
1 // Filename: xFileDataNodeReference.cxx
2 // Created by: drose (08Oct04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "xFileDataNodeReference.h"
16 #include "indent.h"
17 
18 TypeHandle XFileDataNodeReference::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: XFileDataNodeReference::Constructor
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 XFileDataNodeReference::
26 XFileDataNodeReference(XFileDataNodeTemplate *object) :
27  XFileDataNode(object->get_x_file(), object->get_name(),
28  object->get_template()),
29  _object(object)
30 {
31  // We steal a copy of the referenced object's children. This is
32  // just a one-time copy, so if you go and change the list of
33  // children of the referenced object, it won't be reflected here in
34  // the reference. Since presumably the reference is only used when
35  // parsing static files, that shouldn't be a problem; but you do
36  // need to be aware of it.
37  _children = object->_children;
38  _objects = object->_objects;
39  _children_by_name = object->_children_by_name;
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: XFileDataNodeReference::is_reference
44 // Access: Public, Virtual
45 // Description: Returns true if this node represents an indirect
46 // reference to an object defined previously in the
47 // file. References are generally transparent, so in
48 // most cases you never need to call this, unless you
49 // actually need to differentiate between references and
50 // instances; you can simply use the reference node as
51 // if it were itself the object it references.
52 //
53 // If this returns true, the node must be of type
54 // XFileDataNodeReference.
55 ////////////////////////////////////////////////////////////////////
57 is_reference() const {
58  return true;
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: XFileDataNodeReference::is_complex_object
63 // Access: Public, Virtual
64 // Description: Returns true if this kind of data object is a complex
65 // object that can hold nested data elements, false
66 // otherwise.
67 ////////////////////////////////////////////////////////////////////
70  return true;
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: XFileDataNodeReference::write_text
75 // Access: Public, Virtual
76 // Description: Writes a suitable representation of this node to an
77 // .x file in text mode.
78 ////////////////////////////////////////////////////////////////////
80 write_text(ostream &out, int indent_level) const {
81  indent(out, indent_level)
82  << "{ " << _object->get_name() << " }\n";
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: XFileDataNodeReference::get_num_elements
87 // Access: Protected, Virtual
88 // Description: Returns the number of nested data elements within the
89 // object. This may be, e.g. the size of the array, if
90 // it is an array.
91 ////////////////////////////////////////////////////////////////////
92 int XFileDataNodeReference::
93 get_num_elements() const {
94  return _object->size();
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: XFileDataNodeReference::get_element
99 // Access: Protected, Virtual
100 // Description: Returns the nth nested data element within the
101 // object.
102 ////////////////////////////////////////////////////////////////////
103 XFileDataObject *XFileDataNodeReference::
104 get_element(int n) {
105  return &((*_object)[n]);
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function: XFileDataNodeReference::get_element
110 // Access: Protected, Virtual
111 // Description: Returns the nested data element within the
112 // object that has the indicated name.
113 ////////////////////////////////////////////////////////////////////
114 XFileDataObject *XFileDataNodeReference::
115 get_element(const string &name) {
116  return &((*_object)[name]);
117 }
This is a node which contains all of the data elements defined by a template.
virtual bool is_reference() const
Returns true if this node represents an indirect reference to an object defined previously in the fil...
This is an abstract base class for an XFileNode which is also an XFileDataObject. ...
Definition: xFileDataNode.h:36
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual bool is_complex_object() const
Returns true if this kind of data object is a complex object that can hold nested data elements...
virtual void write_text(ostream &out, int indent_level) const
Writes a suitable representation of this node to an .x file in text mode.
The abstract base class for a number of different types of data elements that may be stored in the X ...