Panda3D
|
00001 // Filename: xFileDataNodeReference.cxx 00002 // Created by: drose (08Oct04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "xFileDataNodeReference.h" 00016 #include "indent.h" 00017 00018 TypeHandle XFileDataNodeReference::_type_handle; 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: XFileDataNodeReference::Constructor 00022 // Access: Public 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 XFileDataNodeReference:: 00026 XFileDataNodeReference(XFileDataNodeTemplate *object) : 00027 XFileDataNode(object->get_x_file(), object->get_name(), 00028 object->get_template()), 00029 _object(object) 00030 { 00031 // We steal a copy of the referenced object's children. This is 00032 // just a one-time copy, so if you go and change the list of 00033 // children of the referenced object, it won't be reflected here in 00034 // the reference. Since presumably the reference is only used when 00035 // parsing static files, that shouldn't be a problem; but you do 00036 // need to be aware of it. 00037 _children = object->_children; 00038 _objects = object->_objects; 00039 _children_by_name = object->_children_by_name; 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: XFileDataNodeReference::is_reference 00044 // Access: Public, Virtual 00045 // Description: Returns true if this node represents an indirect 00046 // reference to an object defined previously in the 00047 // file. References are generally transparent, so in 00048 // most cases you never need to call this, unless you 00049 // actually need to differentiate between references and 00050 // instances; you can simply use the reference node as 00051 // if it were itself the object it references. 00052 // 00053 // If this returns true, the node must be of type 00054 // XFileDataNodeReference. 00055 //////////////////////////////////////////////////////////////////// 00056 bool XFileDataNodeReference:: 00057 is_reference() const { 00058 return true; 00059 } 00060 00061 //////////////////////////////////////////////////////////////////// 00062 // Function: XFileDataNodeReference::is_complex_object 00063 // Access: Public, Virtual 00064 // Description: Returns true if this kind of data object is a complex 00065 // object that can hold nested data elements, false 00066 // otherwise. 00067 //////////////////////////////////////////////////////////////////// 00068 bool XFileDataNodeReference:: 00069 is_complex_object() const { 00070 return true; 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: XFileDataNodeReference::write_text 00075 // Access: Public, Virtual 00076 // Description: Writes a suitable representation of this node to an 00077 // .x file in text mode. 00078 //////////////////////////////////////////////////////////////////// 00079 void XFileDataNodeReference:: 00080 write_text(ostream &out, int indent_level) const { 00081 indent(out, indent_level) 00082 << "{ " << _object->get_name() << " }\n"; 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: XFileDataNodeReference::get_num_elements 00087 // Access: Protected, Virtual 00088 // Description: Returns the number of nested data elements within the 00089 // object. This may be, e.g. the size of the array, if 00090 // it is an array. 00091 //////////////////////////////////////////////////////////////////// 00092 int XFileDataNodeReference:: 00093 get_num_elements() const { 00094 return _object->size(); 00095 } 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function: XFileDataNodeReference::get_element 00099 // Access: Protected, Virtual 00100 // Description: Returns the nth nested data element within the 00101 // object. 00102 //////////////////////////////////////////////////////////////////// 00103 XFileDataObject *XFileDataNodeReference:: 00104 get_element(int n) { 00105 return &((*_object)[n]); 00106 } 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function: XFileDataNodeReference::get_element 00110 // Access: Protected, Virtual 00111 // Description: Returns the nested data element within the 00112 // object that has the indicated name. 00113 //////////////////////////////////////////////////////////////////// 00114 XFileDataObject *XFileDataNodeReference:: 00115 get_element(const string &name) { 00116 return &((*_object)[name]); 00117 }