Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
XFileNode Class Reference

A single node of an X file. More...

#include "xFileNode.h"

Inheritance diagram for XFileNode:
TypedObject Namable ReferenceCount MemoryBase MemoryBase MemoryBase XFile XFileDataDef XFileDataNode XFileTemplate XFileDataNodeReference XFileDataNodeTemplate

Public Types

typedef pmap< const XFileDataDef *, XFileDataObject * > PrevData
 

Public Member Functions

 XFileNode (XFile *x_file, const string &name)
 
void add_child (XFileNode *node)
 Adds the indicated node as a child of this node. More...
 
XFileDataNodeadd_Frame (const string &name)
 Creates a new Frame instance, as a child of this node. More...
 
XFileDataNodeadd_FrameTransformMatrix (const LMatrix4d &mat)
 Creates a new FrameTransformMatrix instance, as a child of this node. More...
 
XFileDataNodeadd_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. More...
 
XFileDataNodeadd_Mesh (const string &name)
 Creates a new Mesh instance, as a child of this node. More...
 
XFileDataNodeadd_MeshMaterialList (const string &name)
 Creates a new MeshMaterialList instance, as a child of this node. More...
 
XFileDataNodeadd_MeshNormals (const string &name)
 Creates a new MeshNormals instance, as a child of this node. More...
 
XFileDataNodeadd_MeshTextureCoords (const string &name)
 Creates a new MeshTextureCoords instance, as a child of this node. More...
 
XFileDataNodeadd_MeshVertexColors (const string &name)
 Creates a new MeshVertexColors instance, as a child of this node. More...
 
XFileDataNodeadd_TextureFilename (const string &name, const Filename &filename)
 Creates a new TextureFilename instance, as a child of this node. More...
 
virtual void clear ()
 Removes all children from the node, and otherwise resets it to its initial state. More...
 
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 template object to zero. More...
 
XFileNodefind_child (const string &name) const
 Returns the child with the indicated name, if any, or NULL if none. More...
 
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. More...
 
int find_child_index (const XFileNode *child) const
 Returns the index number of the indicated child, or -1 if none. More...
 
XFileNodefind_descendent (const string &name) const
 Returns the first child or descendent found with the indicated name after a depth-first search, if any, or NULL if none. More...
 
virtual TypeHandle force_init_type ()
 
XFileNodeget_child (int n) const
 Returns the nth child of this node. More...
 
virtual const WindowsGuidget_guid () const
 If has_guid() returned true, returns the particular GUID associated with this node. More...
 
int get_num_children () const
 Returns the list of children of this node. More...
 
int get_num_objects () const
 Returns the list of child objects of this node. More...
 
XFileDataNodeget_object (int n) const
 Returns the nth child object of this node. More...
 
virtual TypeHandle get_type () const
 
XFileget_x_file () const
 
virtual bool has_guid () const
 Returns true if this node has a GUID associated. More...
 
virtual bool is_object () const
 Returns true if this node represents a data object that is the instance of some template, or false otherwise. More...
 
virtual bool is_reference () const
 Returns true if this node represents an indirect reference to an object defined previously in the file. More...
 
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, or false otherwise. More...
 
virtual bool is_template_def () const
 Returns true if this node represents the definition of some template. More...
 
virtual bool matches (const XFileNode *other) const
 Returns true if the node, particularly a template node, is structurally equivalent to the other node (which must be of the same type). More...
 
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. More...
 
virtual void write_text (ostream &out, int indent_level) const
 Writes a suitable representation of this node to an .x file in text mode. More...
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
int get_best_parent_from_Set (const std::set< int > &) const
 
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly. More...
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type. More...
 
void operator= (const TypedObject &copy)
 
- Public Member Functions inherited from Namable
 Namable (const string &initial_name="")
 
 Namable (const Namable &copy)
 
void clear_name ()
 Resets the Namable's name to empty. More...
 
const string & get_name () const
 
bool has_name () const
 Returns true if the Namable has a nonempty name set, false if the name is empty. More...
 
Namableoperator= (const Namable &other)
 
void output (ostream &out) const
 Outputs the Namable. More...
 
void set_name (const string &name)
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 Returns the current reference count. More...
 
WeakReferenceListget_weak_list () const
 Returns the WeakReferenceList associated with this ReferenceCount object. More...
 
bool has_weak_list () const
 Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More...
 
void local_object ()
 This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More...
 
void ref () const
 Explicitly increments the reference count. More...
 
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
bool test_ref_count_nonzero () const
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More...
 
virtual bool unref () const
 Explicitly decrements the reference count. More...
 
void weak_ref (WeakPointerToVoid *ptv)
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref (WeakPointerToVoid *ptv)
 Removes the indicated PointerToVoid as a weak reference to this object. More...
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static void init_type ()
 
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. More...
 
- Static Public Member Functions inherited from TypedObject
static TypeHandle get_class_type ()
 
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96. More...
 
- Static Public Member Functions inherited from Namable
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from ReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 

Friends

class XFileDataNodeReference
 

Detailed Description

A single node of an X file.

This may be either a template or a data node.

Definition at line 42 of file xFileNode.h.

Member Function Documentation

◆ add_child()

void XFileNode::add_child ( XFileNode node)

Adds the indicated node as a child of this node.

Definition at line 230 of file xFileNode.cxx.

References clear(), get_guid(), has_guid(), Namable::has_name(), and TypedObject::is_of_type().

Referenced by is_standard_object().

◆ add_Frame()

XFileDataNode * XFileNode::add_Frame ( const string &  name)

Creates a new Frame instance, as a child of this node.

Definition at line 499 of file xFileNode.cxx.

References add_FrameTransformMatrix(), XFile::find_standard_template(), and XFileDataNodeTemplate::zero_fill().

Referenced by add_TextureFilename(), and XFileMaker::add_tree().

◆ add_FrameTransformMatrix()

XFileDataNode * XFileNode::add_FrameTransformMatrix ( const LMatrix4d mat)

Creates a new FrameTransformMatrix instance, as a child of this node.

Definition at line 517 of file xFileNode.cxx.

References XFile::find_standard_template(), make_nice_name(), and XFileDataNodeTemplate::zero_fill().

Referenced by add_Frame(), and XFileMaker::add_tree().

◆ add_Material()

XFileDataNode * XFileNode::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 at line 447 of file xFileNode.cxx.

References add_TextureFilename(), XFile::find_standard_template(), and XFileDataNodeTemplate::zero_fill().

Referenced by add_MeshMaterialList(), and XFileMaterial::make_x_material().

◆ add_Mesh()

XFileDataNode * XFileNode::add_Mesh ( const string &  name)

Creates a new Mesh instance, as a child of this node.

Definition at line 357 of file xFileNode.cxx.

References add_MeshNormals(), XFile::find_standard_template(), and XFileDataNodeTemplate::zero_fill().

Referenced by XFileMesh::make_x_mesh(), and matches().

◆ add_MeshMaterialList()

XFileDataNode * XFileNode::add_MeshMaterialList ( const string &  name)

Creates a new MeshMaterialList instance, as a child of this node.

Definition at line 429 of file xFileNode.cxx.

References add_Material(), XFile::find_standard_template(), and XFileDataNodeTemplate::zero_fill().

Referenced by add_MeshTextureCoords(), and XFileMesh::make_x_material_list().

◆ add_MeshNormals()

XFileDataNode * XFileNode::add_MeshNormals ( const string &  name)

Creates a new MeshNormals instance, as a child of this node.

Definition at line 375 of file xFileNode.cxx.

References add_MeshVertexColors(), XFile::find_standard_template(), and XFileDataNodeTemplate::zero_fill().

Referenced by add_Mesh(), and XFileMesh::make_x_normals().

◆ add_MeshTextureCoords()

XFileDataNode * XFileNode::add_MeshTextureCoords ( const string &  name)

Creates a new MeshTextureCoords instance, as a child of this node.

Definition at line 411 of file xFileNode.cxx.

References add_MeshMaterialList(), XFile::find_standard_template(), and XFileDataNodeTemplate::zero_fill().

Referenced by add_MeshVertexColors(), and XFileMesh::make_x_uvs().

◆ add_MeshVertexColors()

XFileDataNode * XFileNode::add_MeshVertexColors ( const string &  name)

Creates a new MeshVertexColors instance, as a child of this node.

Definition at line 393 of file xFileNode.cxx.

References add_MeshTextureCoords(), XFile::find_standard_template(), and XFileDataNodeTemplate::zero_fill().

Referenced by add_MeshNormals(), and XFileMesh::make_x_colors().

◆ add_TextureFilename()

XFileDataNode * XFileNode::add_TextureFilename ( const string &  name,
const Filename filename 
)

Creates a new TextureFilename instance, as a child of this node.

Definition at line 479 of file xFileNode.cxx.

References add_Frame(), XFile::find_standard_template(), Filename::to_os_specific(), and XFileDataNodeTemplate::zero_fill().

Referenced by add_Material(), and XFileMaterial::make_x_material().

◆ clear()

void XFileNode::clear ( void  )
virtual

Removes all children from the node, and otherwise resets it to its initial state.

Reimplemented in XFileDataDef, XFile, and XFileTemplate.

Definition at line 250 of file xFileNode.cxx.

References write_text().

Referenced by add_child(), XFileTemplate::clear(), XFile::clear(), and XFileDataDef::clear().

◆ fill_zero_data()

bool XFileNode::fill_zero_data ( XFileDataObject object) const
virtual

This is similar to repack_data(), except it is used to fill the initial values for a newly-created template object to zero.

Reimplemented in XFileDataDef.

Definition at line 312 of file xFileNode.cxx.

References matches().

Referenced by XFileDataDef::fill_zero_data(), and repack_data().

◆ find_child()

XFileNode * XFileNode::find_child ( const string &  name) const

Returns the child with the indicated name, if any, or NULL if none.

Definition at line 61 of file xFileNode.cxx.

References find_child_index().

◆ find_child_index() [1/2]

int XFileNode::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 at line 78 of file xFileNode.cxx.

Referenced by find_child(), and XFileArrayDef::matches().

◆ find_child_index() [2/2]

int XFileNode::find_child_index ( const XFileNode child) const

Returns the index number of the indicated child, or -1 if none.

Definition at line 95 of file xFileNode.cxx.

References find_descendent(), and XFileDataObject::i().

◆ find_descendent()

XFileNode * XFileNode::find_descendent ( const string &  name) const

Returns the first child or descendent found with the indicated name after a depth-first search, if any, or NULL if none.

Definition at line 113 of file xFileNode.cxx.

References find_descendent(), and has_guid().

Referenced by find_child_index(), and find_descendent().

◆ get_child()

XFileNode * XFileNode::get_child ( int  n) const
inline

Returns the nth child of this node.

This list includes templates as well as data objects.

Definition at line 44 of file xFileNode.I.

References get_num_objects().

Referenced by XFileDataNode::get_data_child(), get_num_children(), matches(), and XFile::write_text().

◆ get_guid()

const WindowsGuid & XFileNode::get_guid ( ) const
virtual

If has_guid() returned true, returns the particular GUID associated with this node.

Reimplemented in XFileTemplate.

Definition at line 147 of file xFileNode.cxx.

References is_template_def().

Referenced by add_child(), and has_guid().

◆ get_num_children()

int XFileNode::get_num_children ( ) const
inline

Returns the list of children of this node.

This list includes templates as well as data objects.

Definition at line 33 of file xFileNode.I.

References get_child().

Referenced by matches().

◆ get_num_objects()

int XFileNode::get_num_objects ( ) const
inline

Returns the list of child objects of this node.

This list does not include template definitions; it is strictly the list of children that are also data objects (instances of templates).

Definition at line 58 of file xFileNode.I.

References get_object().

Referenced by XFileMaterial::fill_material(), XFileMesh::fill_material_list(), XFileMesh::fill_mesh(), XFileToEggConverter::find_joint(), and get_child().

◆ get_object()

XFileDataNode * XFileNode::get_object ( int  n) const
inline

Returns the nth child object of this node.

This list does not include template definitions; it is strictly the list of children that are also data objects (instances of templates).

Definition at line 71 of file xFileNode.I.

Referenced by XFileMaterial::fill_material(), XFileMesh::fill_material_list(), XFileMesh::fill_mesh(), XFileToEggConverter::find_joint(), and get_num_objects().

◆ has_guid()

bool XFileNode::has_guid ( ) const
virtual

Returns true if this node has a GUID associated.

Reimplemented in XFileTemplate.

Definition at line 136 of file xFileNode.cxx.

References get_guid().

Referenced by add_child(), and find_descendent().

◆ is_object()

bool XFileNode::is_object ( ) const
virtual

Returns true if this node represents a data object that is the instance of some template, or false otherwise.

This also returns true for references to objects (which are generally treated just like the objects themselves).

If this returns true, the node must be of type XFileDataNode (it is either an XFileDataNodeTemplate or an XFileDataNodeReference).

Reimplemented in XFileDataNode.

Definition at line 203 of file xFileNode.cxx.

References is_standard_object().

Referenced by is_reference().

◆ is_reference()

bool XFileNode::is_reference ( ) const
virtual

Returns true if this node represents an indirect reference to an object defined previously in the file.

References are generally transparent, so in most cases you never need to call this, unless you actually need to differentiate between references and instances; you can simply use the reference node as if it were itself the object it references.

If this returns true, the node must be of type XFileDataNodeReference.

Reimplemented in XFileDataNodeReference.

Definition at line 185 of file xFileNode.cxx.

References is_object().

Referenced by XFileToEggConverter::find_joint(), and is_template_def().

◆ is_standard_object()

bool XFileNode::is_standard_object ( const string &  template_name) const
virtual

Returns true if this node represents an instance of the standard template with the indicated name, or false otherwise.

This returns also returns true for references to standard objects.

If this returns true, the node must be of type XFileDataNode (it is either an XFileDataNodeTemplate or an XFileDataNodeReference).

Reimplemented in XFileDataNode.

Definition at line 220 of file xFileNode.cxx.

References add_child().

Referenced by is_object().

◆ is_template_def()

bool XFileNode::is_template_def ( ) const
virtual

Returns true if this node represents the definition of some template.

This is the template definition, not an actual data object that represents an instance of the template. If the file strictly uses standard templates, the presence of template definitions is optional.

If this returns true, the node must be of type XFileTemplate.

Reimplemented in XFileTemplate.

Definition at line 166 of file xFileNode.cxx.

References is_reference().

Referenced by get_guid().

◆ make_nice_name()

string XFileNode::make_nice_name ( const string &  str)
static

Transforms the indicated egg name to a name that is acceptable for a node in the X File format.

Definition at line 557 of file xFileNode.cxx.

Referenced by add_FrameTransformMatrix().

◆ matches()

bool XFileNode::matches ( const XFileNode other) const
virtual

Returns true if the node, particularly a template node, is structurally equivalent to the other node (which must be of the same type).

This checks data element types, but does not compare data element names.

Reimplemented in XFileDataDef, and XFileTemplate.

Definition at line 333 of file xFileNode.cxx.

References add_Mesh(), get_child(), get_num_children(), and XFileDataObject::i().

Referenced by fill_zero_data(), XFileTemplate::matches(), and XFileDataDef::matches().

◆ repack_data()

bool XFileNode::repack_data ( XFileDataObject object,
const XFileParseDataList parse_data_list,
XFileNode::PrevData prev_data,
size_t &  index,
size_t &  sub_index 
) const
virtual

This is called on the template that defines an object, once the data for the object has been parsed.

It is responsible for identifying which component of the template owns each data element, and packing the data elements appropriately back into the object.

It returns true on success, or false on an error (e.g. not enough data elements, mismatched data type).

Reimplemented in XFileDataDef.

Definition at line 284 of file xFileNode.cxx.

References fill_zero_data().

Referenced by XFileDataDef::repack_data(), and write_text().

◆ write_text()

void XFileNode::write_text ( ostream &  out,
int  indent_level 
) const
virtual

Writes a suitable representation of this node to an .x file in text mode.

Reimplemented in XFileDataDef, XFile, XFileDataNodeTemplate, XFileDataNodeReference, and XFileTemplate.

Definition at line 263 of file xFileNode.cxx.

References repack_data().

Referenced by clear(), XFileTemplate::write_text(), and XFileDataNodeTemplate::write_text().


The documentation for this class was generated from the following files: