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

This represents the complete contents of an X file (file.x) in memory. More...

#include "xFile.h"

Inheritance diagram for XFile:
XFileNode TypedObject Namable ReferenceCount MemoryBase MemoryBase MemoryBase

Public Types

enum  FloatSize { FS_32, FS_64 }
 
enum  FormatType { FT_text, FT_binary, FT_compressed }
 
- Public Types inherited from XFileNode
typedef pmap< const XFileDataDef *, XFileDataObject * > PrevData
 

Public Member Functions

 XFile (bool keep_names=false)
 
virtual void clear ()
 Removes all of the classes defined within the XFile and prepares it for reading a new file. More...
 
XFileDataNodeTemplatefind_data_object (const std::string &name) const
 Returns the data object associated with the indicated name, if any, or NULL if none. More...
 
XFileDataNodeTemplatefind_data_object (const WindowsGuid &guid) const
 Returns the data object associated with the indicated GUID, if any, or NULL if none. More...
 
XFileTemplatefind_template (const std::string &name) const
 Returns the template associated with the indicated name, if any, or NULL if none. More...
 
XFileTemplatefind_template (const WindowsGuid &guid) const
 Returns the template associated with the indicated GUID, if any, or NULL if none. More...
 
virtual TypeHandle force_init_type ()
 
virtual TypeHandle get_type () const
 
bool read (Filename filename)
 Opens and reads the indicated .x file by name. More...
 
bool read (std::istream &in, const std::string &filename=std::string())
 Parses the already-opened input stream for distributed class descriptions. More...
 
bool write (Filename filename) const
 Opens the indicated filename for output and writes a parseable description of all the known distributed classes to the file. More...
 
bool write (std::ostream &out) const
 Writes a parseable description of all the known nodes and templates to the stream. More...
 
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. More...
 
- Public Member Functions inherited from XFileNode
 XFileNode (XFile *x_file, const std::string &name)
 
void add_child (XFileNode *node)
 Adds the indicated node as a child of this node. More...
 
XFileDataNodeadd_Frame (const std::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 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. More...
 
XFileDataNodeadd_Mesh (const std::string &name)
 Creates a new Mesh instance, as a child of this node. More...
 
XFileDataNodeadd_MeshMaterialList (const std::string &name)
 Creates a new MeshMaterialList instance, as a child of this node. More...
 
XFileDataNodeadd_MeshNormals (const std::string &name)
 Creates a new MeshNormals instance, as a child of this node. More...
 
XFileDataNodeadd_MeshTextureCoords (const std::string &name)
 Creates a new MeshTextureCoords instance, as a child of this node. More...
 
XFileDataNodeadd_MeshVertexColors (const std::string &name)
 Creates a new MeshVertexColors instance, as a child of this node. More...
 
XFileDataNodeadd_TextureFilename (const std::string &name, const Filename &filename)
 Creates a new TextureFilename instance, as a child of this node. 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 std::string &name) const
 Returns the child with the indicated name, if any, or NULL if none. More...
 
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. 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 std::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...
 
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...
 
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 std::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...
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)=default
 
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...
 
TypedObjectoperator= (const TypedObject &copy)=default
 
- Public Member Functions inherited from Namable
 Namable (const std::string &initial_name="")
 
void clear_name ()
 Resets the Namable's name to empty. More...
 
const std::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...
 
void output (std::ostream &out) const
 Outputs the Namable. More...
 
void set_name (const std::string &name)
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 
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 ref_if_nonzero () const
 Atomically increases the reference count of this object if it is not zero. 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...
 
WeakReferenceListweak_ref ()
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref ()
 Removes the indicated PointerToVoid as a weak reference to this object. More...
 

Static Public Member Functions

static XFileTemplatefind_standard_template (const std::string &name)
 Returns the standard template associated with the indicated name, if any, or NULL if none. More...
 
static XFileTemplatefind_standard_template (const WindowsGuid &guid)
 Returns the template associated with the indicated GUID, if any, or NULL if none. More...
 
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from XFileNode
static TypeHandle get_class_type ()
 
static void init_type ()
 
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. 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 XFileNode
 

Additional Inherited Members

- Public Attributes inherited from TypedObject
 get_type
 
- Public Attributes inherited from Namable
 get_name
 
 set_name
 
- Public Attributes inherited from ReferenceCount
 get_ref_count
 Returns the current reference count. More...
 

Detailed Description

This represents the complete contents of an X file (file.x) in memory.

It may be read or written from or to a disk file.

Definition at line 32 of file xFile.h.

Member Function Documentation

◆ clear()

void XFile::clear ( )
virtual

Removes all of the classes defined within the XFile and prepares it for reading a new file.

Reimplemented from XFileNode.

Definition at line 58 of file xFile.cxx.

References XFileNode::clear().

◆ find_data_object() [1/2]

XFileDataNodeTemplate * XFile::find_data_object ( const std::string &  name) const

Returns the data object associated with the indicated name, if any, or NULL if none.

Definition at line 257 of file xFile.cxx.

References XFileNode::find_descendent(), and TypedObject::is_of_type().

◆ find_data_object() [2/2]

XFileDataNodeTemplate * XFile::find_data_object ( const WindowsGuid guid) const

Returns the data object associated with the indicated GUID, if any, or NULL if none.

Definition at line 272 of file xFile.cxx.

◆ find_standard_template() [1/2]

XFileTemplate * XFile::find_standard_template ( const std::string &  name)
static

◆ find_standard_template() [2/2]

XFileTemplate * XFile::find_standard_template ( const WindowsGuid guid)
static

Returns the template associated with the indicated GUID, if any, or NULL if none.

Definition at line 247 of file xFile.cxx.

References find_template().

◆ find_template() [1/2]

XFileTemplate * XFile::find_template ( const std::string &  name) const

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

Definition at line 178 of file xFile.cxx.

References XFileNode::find_child(), find_template(), and TypedObject::is_of_type().

Referenced by find_standard_template(), and find_template().

◆ find_template() [2/2]

XFileTemplate * XFile::find_template ( const WindowsGuid guid) const

Returns the template associated with the indicated GUID, if any, or NULL if none.

Definition at line 207 of file xFile.cxx.

References find_template().

◆ read() [1/2]

bool XFile::read ( Filename  filename)

Opens and reads the indicated .x file by name.

The nodes and templates defined in the file will be appended to the set of nodes already recorded, if any.

Returns true if the file is successfully read, false if there was an error (in which case the file might have been partially read).

Definition at line 73 of file xFile.cxx.

References Filename::set_text().

◆ read() [2/2]

bool XFile::read ( std::istream &  in,
const std::string &  filename = std::string() 
)

Parses the already-opened input stream for distributed class descriptions.

The filename parameter is optional and is only used when reporting errors.

The distributed classes defined in the file will be appended to the set of distributed classes already recorded, if any.

Returns true if the file is successfully read, false if there was an error (in which case the file might have been partially read).

Definition at line 98 of file xFile.cxx.

◆ write() [1/2]

bool XFile::write ( Filename  filename) const

Opens the indicated filename for output and writes a parseable description of all the known distributed classes to the file.

Returns true if the description is successfully written, false otherwise.

Definition at line 130 of file xFile.cxx.

References Filename::get_extension(), Filename::open_write(), and Filename::set_binary().

◆ write() [2/2]

bool XFile::write ( std::ostream &  out) const

Writes a parseable description of all the known nodes and templates to the stream.

Returns true if the description is successfully written, false otherwise.

Definition at line 163 of file xFile.cxx.

References write_text().

◆ write_text()

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

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

Reimplemented from XFileNode.

Definition at line 287 of file xFile.cxx.

Referenced by write().


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