Panda3D
xFileNode.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file xFileNode.h
10  * @author drose
11  * @date 2004-10-03
12  */
13 
14 #ifndef XFILENODE_H
15 #define XFILENODE_H
16 
17 #include "pandatoolbase.h"
18 #include "typedObject.h"
19 #include "referenceCount.h"
20 #include "pointerTo.h"
21 #include "namable.h"
22 #include "pnotify.h"
23 #include "pvector.h"
24 #include "pmap.h"
25 #include "luse.h"
26 
27 class XFile;
28 class WindowsGuid;
29 class XFileParseDataList;
30 class XFileDataDef;
31 class XFileDataObject;
32 class XFileDataNode;
34 class Filename;
35 
36 /**
37  * A single node of an X file. This may be either a template or a data node.
38  */
39 class XFileNode : public TypedObject, public Namable,
40  virtual public ReferenceCount {
41 public:
42  XFileNode(XFile *x_file, const std::string &name);
43  virtual ~XFileNode();
44 
45  INLINE XFile *get_x_file() const;
46 
47  INLINE int get_num_children() const;
48  INLINE XFileNode *get_child(int n) const;
49  XFileNode *find_child(const std::string &name) const;
50  int find_child_index(const std::string &name) const;
51  int find_child_index(const XFileNode *child) const;
52  XFileNode *find_descendent(const std::string &name) const;
53 
54  INLINE int get_num_objects() const;
55  INLINE XFileDataNode *get_object(int n) const;
56 
57  virtual bool has_guid() const;
58  virtual const WindowsGuid &get_guid() const;
59 
60  virtual bool is_template_def() const;
61  virtual bool is_reference() const;
62  virtual bool is_object() const;
63  virtual bool is_standard_object(const std::string &template_name) const;
64 
65  void add_child(XFileNode *node);
66  virtual void clear();
67 
68  virtual void write_text(std::ostream &out, int indent_level) const;
69 
71 
72  virtual bool repack_data(XFileDataObject *object,
73  const XFileParseDataList &parse_data_list,
74  PrevData &prev_data,
75  size_t &index, size_t &sub_index) const;
76 
77  virtual bool fill_zero_data(XFileDataObject *object) const;
78 
79  virtual bool matches(const XFileNode *other) const;
80 
81  // The following methods can be used to create instances of the standard
82  // template objects. These definitions match those defined in
83  // standardTemplates.x in this directory (and compiled into the executable).
84  XFileDataNode *add_Mesh(const std::string &name);
85  XFileDataNode *add_MeshNormals(const std::string &name);
86  XFileDataNode *add_MeshVertexColors(const std::string &name);
87  XFileDataNode *add_MeshTextureCoords(const std::string &name);
88  XFileDataNode *add_MeshMaterialList(const std::string &name);
89  XFileDataNode *add_Material(const std::string &name, const LColor &face_color,
90  double power, const LRGBColor &specular_color,
91  const LRGBColor &emissive_color);
92  XFileDataNode *add_TextureFilename(const std::string &name,
93  const Filename &filename);
94  XFileDataNode *add_Frame(const std::string &name);
95  XFileDataNode *add_FrameTransformMatrix(const LMatrix4d &mat);
96 
97 public:
98  static std::string make_nice_name(const std::string &str);
99 
100 protected:
101  XFile *_x_file;
102 
103  typedef pvector< PT(XFileNode) > Children;
104  Children _children;
105 
107  Objects _objects;
108 
110  ChildrenByName _children_by_name;
111 
112 public:
113  static TypeHandle get_class_type() {
114  return _type_handle;
115  }
116  static void init_type() {
118  ReferenceCount::init_type();
119  register_type(_type_handle, "XFileNode",
120  TypedObject::get_class_type(),
121  ReferenceCount::get_class_type());
122  }
123  virtual TypeHandle get_type() const {
124  return get_class_type();
125  }
126  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
127 
128 private:
129  static TypeHandle _type_handle;
130 
131  friend class XFileDataNodeReference;
132 };
133 
134 #include "xFileNode.I"
135 
136 #endif
XFileDataNode * add_MeshTextureCoords(const std::string &name)
Creates a new MeshTextureCoords instance, as a child of this node.
Definition: xFileNode.cxx:345
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Definition: typedObject.cxx:44
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
XFileDataNode * add_MeshNormals(const std::string &name)
Creates a new MeshNormals instance, as a child of this node.
Definition: xFileNode.cxx:315
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileDataNode * add_Frame(const std::string &name)
Creates a new Frame instance, as a child of this node.
Definition: xFileNode.cxx:421
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:278
int get_num_children() const
Returns the list of children of this node.
Definition: xFileNode.I:27
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileDataNode * add_Material(const std::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:375
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.
Definition: xFileNode.cxx:219
This is an implementation of the Windows GUID object, used everywhere as a world-unique identifier fo...
Definition: windowsGuid.h:26
virtual bool is_object() const
Returns true if this node represents a data object that is the instance of some template,...
Definition: xFileNode.cxx:170
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void add_child(XFileNode *node)
Adds the indicated node as a child of this node.
Definition: xFileNode.cxx:191
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:88
This is a nested reference to an instance of a template object, declared via the syntax:
XFileDataNode * add_TextureFilename(const std::string &name, const Filename &filename)
Creates a new TextureFilename instance, as a child of this node.
Definition: xFileNode.cxx:404
XFileDataNode * add_Mesh(const std::string &name)
Creates a new Mesh instance, as a child of this node.
Definition: xFileNode.cxx:300
virtual bool is_template_def() const
Returns true if this node represents the definition of some template.
Definition: xFileNode.cxx:143
A definition of a single data element appearing within a template record.
Definition: xFileDataDef.h:31
virtual bool has_guid() const
Returns true if this node has a GUID associated.
Definition: xFileNode.cxx:120
int find_child_index(const std::string &name) const
Returns the index number of the child with the indicated name, if any, or -1 if none.
Definition: xFileNode.cxx:70
This is a node which contains all of the data elements defined by a template.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
int get_num_objects() const
Returns the list of child objects of this node.
Definition: xFileNode.I:47
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A single node of an X file.
Definition: xFileNode.h:39
A base class for all things which can have a name.
Definition: namable.h:26
virtual const WindowsGuid & get_guid() const
If has_guid() returned true, returns the particular GUID associated with this node.
Definition: xFileNode.cxx:129
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
virtual bool is_standard_object(const std::string &template_name) const
Returns true if this node represents an instance of the standard template with the indicated name,...
Definition: xFileNode.cxx:183
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static std::string make_nice_name(const std::string &str)
Transforms the indicated egg name to a name that is acceptable for a node in the X File format.
Definition: xFileNode.cxx:474
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:157
XFileDataNode * add_FrameTransformMatrix(const LMatrix4d &mat)
Creates a new FrameTransformMatrix instance, as a child of this node.
Definition: xFileNode.cxx:436
A container for a pvector of the above objects.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:236
A base class for all things that want to be reference-counted.
XFileNode * find_descendent(const std::string &name) const
Returns the first child or descendent found with the indicated name after a depth-first search,...
Definition: xFileNode.cxx:99
XFileDataNode * add_MeshVertexColors(const std::string &name)
Creates a new MeshVertexColors instance, as a child of this node.
Definition: xFileNode.cxx:330
XFileNode * find_child(const std::string &name) const
Returns the child with the indicated name, if any, or NULL if none.
Definition: xFileNode.cxx:55
virtual void clear()
Removes all children from the node, and otherwise resets it to its initial state.
Definition: xFileNode.cxx:209
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract base class for an XFileNode which is also an XFileDataObject.
Definition: xFileDataNode.h:33
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:261
This represents the complete contents of an X file (file.x) in memory.
Definition: xFile.h:32
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileDataNode * get_object(int n) const
Returns the nth child object of this node.
Definition: xFileNode.I:57
XFileDataNode * add_MeshMaterialList(const std::string &name)
Creates a new MeshMaterialList instance, as a child of this node.
Definition: xFileNode.cxx:360
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
The abstract base class for a number of different types of data elements that may be stored in the X ...
XFileNode * get_child(int n) const
Returns the nth child of this node.
Definition: xFileNode.I:36