Panda3D
xFileNode.h
1 // Filename: xFileNode.h
2 // Created by: drose (03Oct04)
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 #ifndef XFILENODE_H
16 #define XFILENODE_H
17 
18 #include "pandatoolbase.h"
19 #include "typedObject.h"
20 #include "referenceCount.h"
21 #include "pointerTo.h"
22 #include "namable.h"
23 #include "pnotify.h"
24 #include "pvector.h"
25 #include "pmap.h"
26 #include "luse.h"
27 
28 class XFile;
29 class WindowsGuid;
30 class XFileParseDataList;
31 class XFileDataDef;
32 class XFileDataObject;
33 class XFileDataNode;
35 class Filename;
36 
37 ////////////////////////////////////////////////////////////////////
38 // Class : XFileNode
39 // Description : A single node of an X file. This may be either a
40 // template or a data node.
41 ////////////////////////////////////////////////////////////////////
42 class XFileNode : public TypedObject, public Namable,
43  virtual public ReferenceCount {
44 public:
45  XFileNode(XFile *x_file, const string &name);
46  virtual ~XFileNode();
47 
48  INLINE XFile *get_x_file() const;
49 
50  INLINE int get_num_children() const;
51  INLINE XFileNode *get_child(int n) const;
52  XFileNode *find_child(const string &name) const;
53  int find_child_index(const string &name) const;
54  int find_child_index(const XFileNode *child) const;
55  XFileNode *find_descendent(const string &name) const;
56 
57  INLINE int get_num_objects() const;
58  INLINE XFileDataNode *get_object(int n) const;
59 
60  virtual bool has_guid() const;
61  virtual const WindowsGuid &get_guid() const;
62 
63  virtual bool is_template_def() const;
64  virtual bool is_reference() const;
65  virtual bool is_object() const;
66  virtual bool is_standard_object(const string &template_name) const;
67 
68  void add_child(XFileNode *node);
69  virtual void clear();
70 
71  virtual void write_text(ostream &out, int indent_level) const;
72 
74 
75  virtual bool repack_data(XFileDataObject *object,
76  const XFileParseDataList &parse_data_list,
77  PrevData &prev_data,
78  size_t &index, size_t &sub_index) const;
79 
80  virtual bool fill_zero_data(XFileDataObject *object) const;
81 
82  virtual bool matches(const XFileNode *other) const;
83 
84  // The following methods can be used to create instances of the
85  // standard template objects. These definitions match those defined
86  // in standardTemplates.x in this directory (and compiled into the
87  // executable).
88  XFileDataNode *add_Mesh(const string &name);
89  XFileDataNode *add_MeshNormals(const string &name);
90  XFileDataNode *add_MeshVertexColors(const string &name);
91  XFileDataNode *add_MeshTextureCoords(const string &name);
92  XFileDataNode *add_MeshMaterialList(const string &name);
93  XFileDataNode *add_Material(const string &name, const LColor &face_color,
94  double power, const LRGBColor &specular_color,
95  const LRGBColor &emissive_color);
96  XFileDataNode *add_TextureFilename(const string &name,
97  const Filename &filename);
98  XFileDataNode *add_Frame(const string &name);
100 
101 public:
102  static string make_nice_name(const string &str);
103 
104 protected:
105  XFile *_x_file;
106 
108  Children _children;
109 
111  Objects _objects;
112 
114  ChildrenByName _children_by_name;
115 
116 public:
117  static TypeHandle get_class_type() {
118  return _type_handle;
119  }
120  static void init_type() {
122  ReferenceCount::init_type();
123  register_type(_type_handle, "XFileNode",
124  TypedObject::get_class_type(),
125  ReferenceCount::get_class_type());
126  }
127  virtual TypeHandle get_type() const {
128  return get_class_type();
129  }
130  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
131 
132 private:
133  static TypeHandle _type_handle;
134 
135  friend class XFileDataNodeReference;
136 };
137 
138 #include "xFileNode.I"
139 
140 #endif
141 
142 
143 
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Definition: typedObject.cxx:52
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
virtual bool matches(const XFileNode *other) const
Returns true if the node, particularly a template node, is structurally equivalent to the other node ...
Definition: xFileNode.cxx:333
XFileDataNode * add_Mesh(const string &name)
Creates a new Mesh instance, as a child of this node.
Definition: xFileNode.cxx:357
int get_num_children() const
Returns the list of children of this node.
Definition: xFileNode.I:33
This is an implementation of the Windows GUID object, used everywhere as a world-unique identifier fo...
Definition: windowsGuid.h:29
virtual bool is_object() const
Returns true if this node represents a data object that is the instance of some template, or false otherwise.
Definition: xFileNode.cxx:203
XFileDataNode * add_MeshNormals(const string &name)
Creates a new MeshNormals instance, as a child of this node.
Definition: xFileNode.cxx:375
void add_child(XFileNode *node)
Adds the indicated node as a child of this node.
Definition: xFileNode.cxx:230
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:98
This is a nested reference to an instance of a template object, declared via the syntax: ...
virtual bool is_template_def() const
Returns true if this node represents the definition of some template.
Definition: xFileNode.cxx:166
A definition of a single data element appearing within a template record.
Definition: xFileDataDef.h:35
virtual bool has_guid() const
Returns true if this node has a GUID associated.
Definition: xFileNode.cxx:136
virtual void write_text(ostream &out, int indent_level) const
Writes a suitable representation of this node to an .x file in text mode.
Definition: xFileNode.cxx:263
This is a node which contains all of the data elements defined by a template.
XFileDataNode * add_MeshTextureCoords(const string &name)
Creates a new MeshTextureCoords instance, as a child of this node.
Definition: xFileNode.cxx:411
int get_num_objects() const
Returns the list of child objects of this node.
Definition: xFileNode.I:58
int find_child_index(const string &name) const
Returns the index number of the child with the indicated name, if any, or -1 if none.
Definition: xFileNode.cxx:78
A single node of an X file.
Definition: xFileNode.h:42
A base class for all things which can have a name.
Definition: namable.h:29
XFileDataNode * add_MeshVertexColors(const string &name)
Creates a new MeshVertexColors instance, as a child of this node.
Definition: xFileNode.cxx:393
virtual const WindowsGuid & get_guid() const
If has_guid() returned true, returns the particular GUID associated with this node.
Definition: xFileNode.cxx:147
XFileDataNode * add_TextureFilename(const string &name, const Filename &filename)
Creates a new TextureFilename instance, as a child of this node.
Definition: xFileNode.cxx:479
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
XFileDataNode * add_Frame(const string &name)
Creates a new Frame instance, as a child of this node.
Definition: xFileNode.cxx:499
virtual bool is_reference() const
Returns true if this node represents an indirect reference to an object defined previously in the fil...
Definition: xFileNode.cxx:185
XFileDataNode * add_FrameTransformMatrix(const LMatrix4d &mat)
Creates a new FrameTransformMatrix instance, as a child of this node.
Definition: xFileNode.cxx:517
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...
Definition: xFileNode.cxx:284
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
A base class for all things that want to be reference-counted.
XFileNode * find_child(const string &name) const
Returns the child with the indicated name, if any, or NULL if none.
Definition: xFileNode.cxx:61
virtual void clear()
Removes all children from the node, and otherwise resets it to its initial state. ...
Definition: xFileNode.cxx:250
static string make_nice_name(const string &str)
Transforms the indicated egg name to a name that is acceptable for a node in the X File format...
Definition: xFileNode.cxx:557
This is an abstract base class for an XFileNode which is also an XFileDataObject. ...
Definition: xFileDataNode.h:36
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...
Definition: xFileNode.cxx:312
XFileDataNode * add_MeshMaterialList(const string &name)
Creates a new MeshMaterialList instance, as a child of this node.
Definition: xFileNode.cxx:429
This represents the complete contents of an X file (file.x) in memory.
Definition: xFile.h:35
XFileNode * find_descendent(const string &name) const
Returns the first child or descendent found with the indicated name after a depth-first search...
Definition: xFileNode.cxx:113
XFileDataNode * get_object(int n) const
Returns the nth child object of this node.
Definition: xFileNode.I:71
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
XFileDataNode * add_Material(const string &name, const LColor &face_color, double power, const LRGBColor &specular_color, const LRGBColor &emissive_color)
Creates a new Material instance, as a child of this node.
Definition: xFileNode.cxx:447
The abstract base class for a number of different types of data elements that may be stored in the X ...
virtual bool is_standard_object(const string &template_name) const
Returns true if this node represents an instance of the standard template with the indicated name...
Definition: xFileNode.cxx:220
XFileNode * get_child(int n) const
Returns the nth child of this node.
Definition: xFileNode.I:44