Panda3D
 All Classes Functions Variables Enumerations
xFileDataObject.h
1 // Filename: xFileDataObject.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 XFILEDATAOBJECT_H
16 #define XFILEDATAOBJECT_H
17 
18 #include "pandatoolbase.h"
19 #include "referenceCount.h"
20 #include "pointerTo.h"
21 #include "dcast.h"
22 #include "luse.h"
23 
24 class XFile;
25 class XFileDataDef;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : XFileDataObject
29 // Description : The abstract base class for a number of different
30 // types of data elements that may be stored in the X
31 // file.
32 ////////////////////////////////////////////////////////////////////
33 class XFileDataObject : virtual public ReferenceCount {
34 public:
35  INLINE XFileDataObject(const XFileDataDef *data_def = NULL);
36  virtual ~XFileDataObject();
37 
38  INLINE const XFileDataDef *get_data_def() const;
39 
40  virtual bool is_complex_object() const;
41  virtual string get_type_name() const;
42 
43  INLINE void operator = (int int_value);
44  INLINE void operator = (double double_value);
45  INLINE void operator = (const string &string_value);
46  INLINE void operator = (const LVecBase2d &vec);
47  INLINE void operator = (const LVecBase3d &vec);
48  INLINE void operator = (const LVecBase4d &vec);
49  INLINE void operator = (const LMatrix4d &mat);
50 
51  INLINE void set(int int_value);
52  INLINE void set(double double_value);
53  INLINE void set(const string &string_value);
54  INLINE void set(const LVecBase2d &vec);
55  INLINE void set(const LVecBase3d &vec);
56  INLINE void set(const LVecBase4d &vec);
57  INLINE void set(const LMatrix4d &mat);
58 
59  INLINE int i() const;
60  INLINE double d() const;
61  INLINE string s() const;
62  INLINE LVecBase2d vec2() const;
63  INLINE LVecBase3d vec3() const;
64  INLINE LVecBase4d vec4() const;
65  INLINE LMatrix4d mat4() const;
66 
67  INLINE int size() const;
68  INLINE const XFileDataObject &operator [] (int n) const;
69  INLINE const XFileDataObject &operator [] (const string &name) const;
70 
71  INLINE XFileDataObject &operator [] (int n);
72  INLINE XFileDataObject &operator [] (const string &name);
73 
74  // The following methods can be used to add elements of a specific
75  // type to a complex object, e.g. an array or a template object.
76 
77  XFileDataObject &add_int(int int_value);
78  XFileDataObject &add_double(double double_value);
79  XFileDataObject &add_string(const string &string_value);
80 
81  // The following methods can be used to add elements of a specific
82  // type, based on one of the standard templates.
83 
84  XFileDataObject &add_Vector(XFile *x_file, const LVecBase3d &vector);
85  XFileDataObject &add_MeshFace(XFile *x_file);
86  XFileDataObject &add_IndexedColor(XFile *x_file, int index,
87  const LColor &color);
88  XFileDataObject &add_Coords2d(XFile *x_file, const LVecBase2d &coords);
89 
90 public:
91  virtual bool add_element(XFileDataObject *element);
92 
93  virtual void output_data(ostream &out) const;
94  virtual void write_data(ostream &out, int indent_level,
95  const char *separator) const;
96 
97 protected:
98  virtual void set_int_value(int int_value);
99  virtual void set_double_value(double double_value);
100  virtual void set_string_value(const string &string_value);
101  void store_double_array(int num_elements, const double *values);
102 
103  virtual int get_int_value() const;
104  virtual double get_double_value() const;
105  virtual string get_string_value() const;
106  void get_double_array(int num_elements, double *values) const;
107 
108  virtual int get_num_elements() const;
109  virtual XFileDataObject *get_element(int n);
110  virtual XFileDataObject *get_element(const string &name);
111 
112  const XFileDataDef *_data_def;
113 
114 public:
115  static TypeHandle get_class_type() {
116  return _type_handle;
117  }
118  static void init_type() {
119  ReferenceCount::init_type();
120  register_type(_type_handle, "XFileDataObject",
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 
132 INLINE ostream &operator << (ostream &out, const XFileDataObject &data_object);
133 
134 #include "xFileDataObject.I"
135 
136 #endif
137 
138 
139 
LVecBase4d vec4() const
Returns the object&#39;s representation as an LVecBase4d.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
virtual void write_data(ostream &out, int indent_level, const char *separator) const
Writes a suitable representation of this node to an .x file in text mode.
virtual bool add_element(XFileDataObject *element)
Adds the indicated element as a nested data element, if this data object type supports it...
XFileDataObject & add_int(int int_value)
Appends a new integer value to the data object, if it makes sense to do so.
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:1241
LVecBase3d vec3() const
Returns the object&#39;s representation as an LVecBase3d.
virtual string get_type_name() const
Returns a string that represents the type of object this data object represents.
virtual void output_data(ostream &out) const
Writes a suitable representation of this node to an .x file in text mode.
string s() const
Unambiguously returns the object&#39;s representation as a string, or empty string if the object has no s...
LMatrix4d mat4() const
Returns the object&#39;s representation as an LMatrix4d.
XFileDataObject & add_MeshFace(XFile *x_file)
Appends a new MeshFace instance.
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:1661
int size() const
Returns the number of nested data objects within this object.
A definition of a single data element appearing within a template record.
Definition: xFileDataDef.h:35
const XFileDataDef * get_data_def() const
Returns the data object that this object is represented by, if any, or NULL if there is none...
XFileDataObject & add_Vector(XFile *x_file, const LVecBase3d &vector)
Appends a new Vector instance.
XFileDataObject & add_Coords2d(XFile *x_file, const LVecBase2d &coords)
Appends a new Coords2d instance.
const XFileDataObject & operator[](int n) const
Returns the nth nested object within this object.
XFileDataObject & add_IndexedColor(XFile *x_file, int index, const LColor &color)
Appends a new IndexedColor instance.
LVecBase2d vec2() const
Returns the object&#39;s representation as an LVecBase2d.
void set(int int_value)
Stores the indicated integer value into the object, if it makes sense to do so.
XFileDataObject & add_double(double double_value)
Appends a new floating-point value to the data object, if it makes sense to do so.
XFileDataObject & add_string(const string &string_value)
Appends a new string value to the data object, if it makes sense to do so.
virtual bool is_complex_object() const
Returns true if this kind of data object is a complex object that can hold nested data elements...
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:1455
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.
void operator=(int int_value)
Stores the indicated integer value into the object, if it makes sense to do so.
This represents the complete contents of an X file (file.x) in memory.
Definition: xFile.h:35
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
The abstract base class for a number of different types of data elements that may be stored in the X ...
int i() const
Unambiguously returns the object&#39;s representation as an integer, or 0 if the object has no integer re...
double d() const
Unambiguously returns the object&#39;s representation as a double, or 0.0 if the object has no double rep...