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 protected:
42  INLINE XFileNode(XFile *x_file);
43 
44 public:
45  XFileNode(XFile *x_file, const std::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 std::string &name) const;
53  int find_child_index(const std::string &name) const;
54  int find_child_index(const XFileNode *child) const;
55  XFileNode *find_descendent(const std::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 std::string &template_name) const;
67 
68  void add_child(XFileNode *node);
69  virtual void clear();
70 
71  virtual void write_text(std::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 standard
85  // template objects. These definitions match those defined in
86  // standardTemplates.x in this directory (and compiled into the executable).
87  XFileDataNode *add_Mesh(const std::string &name);
88  XFileDataNode *add_MeshNormals(const std::string &name);
89  XFileDataNode *add_MeshVertexColors(const std::string &name);
90  XFileDataNode *add_MeshTextureCoords(const std::string &name);
91  XFileDataNode *add_MeshMaterialList(const std::string &name);
92  XFileDataNode *add_Material(const std::string &name, const LColor &face_color,
93  double power, const LRGBColor &specular_color,
94  const LRGBColor &emissive_color);
95  XFileDataNode *add_TextureFilename(const std::string &name,
96  const Filename &filename);
97  XFileDataNode *add_Frame(const std::string &name);
98  XFileDataNode *add_FrameTransformMatrix(const LMatrix4d &mat);
99 
100 public:
101  static std::string make_nice_name(const std::string &str);
102 
103 protected:
104  XFile *_x_file;
105 
106  typedef pvector< PT(XFileNode) > Children;
107  Children _children;
108 
110  Objects _objects;
111 
113  ChildrenByName _children_by_name;
114 
115 public:
116  static TypeHandle get_class_type() {
117  return _type_handle;
118  }
119  static void init_type() {
121  ReferenceCount::init_type();
122  register_type(_type_handle, "XFileNode",
123  TypedObject::get_class_type(),
124  ReferenceCount::get_class_type());
125  }
126  virtual TypeHandle get_type() const {
127  return get_class_type();
128  }
129  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
130 
131 private:
132  static TypeHandle _type_handle;
133 
134  friend class XFileDataNodeReference;
135 };
136 
137 #include "xFileNode.I"
138 
139 #endif
TypedObject::init_type
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Definition: typedObject.cxx:44
XFileNode::add_child
void add_child(XFileNode *node)
Adds the indicated node as a child of this node.
Definition: xFileNode.cxx:191
XFileNode::find_child
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
XFileNode::add_MeshNormals
XFileDataNode * add_MeshNormals(const std::string &name)
Creates a new MeshNormals instance, as a child of this node.
Definition: xFileNode.cxx:315
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
XFileDataObject
The abstract base class for a number of different types of data elements that may be stored in the X ...
Definition: xFileDataObject.h:30
XFileNode::add_TextureFilename
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
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileNode::get_object
XFileDataNode * get_object(int n) const
Returns the nth child object of this node.
Definition: xFileNode.I:67
ReferenceCount
A base class for all things that want to be reference-counted.
Definition: referenceCount.h:38
XFileNode::add_MeshTextureCoords
XFileDataNode * add_MeshTextureCoords(const std::string &name)
Creates a new MeshTextureCoords instance, as a child of this node.
Definition: xFileNode.cxx:345
pmap
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
register_type
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
XFileNode::add_MeshMaterialList
XFileDataNode * add_MeshMaterialList(const std::string &name)
Creates a new MeshMaterialList instance, as a child of this node.
Definition: xFileNode.cxx:360
XFileNode::get_guid
virtual const WindowsGuid & get_guid() const
If has_guid() returned true, returns the particular GUID associated with this node.
Definition: xFileNode.cxx:129
XFileNode::get_num_children
int get_num_children() const
Returns the list of children of this node.
Definition: xFileNode.I:37
XFile
This represents the complete contents of an X file (file.x) in memory.
Definition: xFile.h:32
XFileNode::find_child_index
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
XFileNode::has_guid
virtual bool has_guid() const
Returns true if this node has a GUID associated.
Definition: xFileNode.cxx:120
XFileNode::get_child
XFileNode * get_child(int n) const
Returns the nth child of this node.
Definition: xFileNode.I:46
XFileNode
A single node of an X file.
Definition: xFileNode.h:40
XFileNode::is_reference
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
pnotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileNode::add_MeshVertexColors
XFileDataNode * add_MeshVertexColors(const std::string &name)
Creates a new MeshVertexColors instance, as a child of this node.
Definition: xFileNode.cxx:330
XFileNode::clear
virtual void clear()
Removes all children from the node, and otherwise resets it to its initial state.
Definition: xFileNode.cxx:209
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
XFileParseDataList
A container for a pvector of the above objects.
Definition: xFileParseData.h:62
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileNode::matches
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
namable.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileNode::get_num_objects
int get_num_objects() const
Returns the list of child objects of this node.
Definition: xFileNode.I:57
XFileNode::fill_zero_data
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
typedObject.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileDataDef
A definition of a single data element appearing within a template record.
Definition: xFileDataDef.h:31
luse.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileDataNodeTemplate
This is a node which contains all of the data elements defined by a template.
Definition: xFileDataNodeTemplate.h:30
XFileNode::is_object
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
XFileNode::make_nice_name
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
XFileNode::add_FrameTransformMatrix
XFileDataNode * add_FrameTransformMatrix(const LMatrix4d &mat)
Creates a new FrameTransformMatrix instance, as a child of this node.
Definition: xFileNode.cxx:436
XFileNode::add_Mesh
XFileDataNode * add_Mesh(const std::string &name)
Creates a new Mesh instance, as a child of this node.
Definition: xFileNode.cxx:300
XFileNode::repack_data
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
XFileNode::is_standard_object
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
xFileNode.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileNode::find_descendent
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
referenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileDataNodeReference
This is a nested reference to an instance of a template object, declared via the syntax:
Definition: xFileDataNodeReference.h:29
Namable
A base class for all things which can have a name.
Definition: namable.h:26
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileNode::is_template_def
virtual bool is_template_def() const
Returns true if this node represents the definition of some template.
Definition: xFileNode.cxx:143
XFileDataNode
This is an abstract base class for an XFileNode which is also an XFileDataObject.
Definition: xFileDataNode.h:33
XFileNode::add_Material
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
XFileNode::add_Frame
XFileDataNode * add_Frame(const std::string &name)
Creates a new Frame instance, as a child of this node.
Definition: xFileNode.cxx:421
XFileNode::write_text
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
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
WindowsGuid
This is an implementation of the Windows GUID object, used everywhere as a world-unique identifier fo...
Definition: windowsGuid.h:26
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
TypedObject
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:88