Panda3D
Loading...
Searching...
No Matches
xFileDataObject.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 xFileDataObject.h
10 * @author drose
11 * @date 2004-10-03
12 */
13
14#ifndef XFILEDATAOBJECT_H
15#define XFILEDATAOBJECT_H
16
17#include "pandatoolbase.h"
18#include "referenceCount.h"
19#include "pointerTo.h"
20#include "dcast.h"
21#include "luse.h"
22
23class XFile;
24class XFileDataDef;
25
26/**
27 * The abstract base class for a number of different types of data elements
28 * that may be stored in the X file.
29 */
30class XFileDataObject : virtual public ReferenceCount {
31public:
32 INLINE XFileDataObject(const XFileDataDef *data_def = nullptr);
33 virtual ~XFileDataObject();
34
35 INLINE const XFileDataDef *get_data_def() const;
36
37 virtual bool is_complex_object() const;
38 virtual std::string get_type_name() const;
39
40 INLINE void operator = (int int_value);
41 INLINE void operator = (double double_value);
42 INLINE void operator = (const std::string &string_value);
43 INLINE void operator = (const LVecBase2d &vec);
44 INLINE void operator = (const LVecBase3d &vec);
45 INLINE void operator = (const LVecBase4d &vec);
46 INLINE void operator = (const LMatrix4d &mat);
47
48 INLINE void set(int int_value);
49 INLINE void set(double double_value);
50 INLINE void set(const std::string &string_value);
51 INLINE void set(const LVecBase2d &vec);
52 INLINE void set(const LVecBase3d &vec);
53 INLINE void set(const LVecBase4d &vec);
54 INLINE void set(const LMatrix4d &mat);
55
56 INLINE int i() const;
57 INLINE double d() const;
58 INLINE std::string s() const;
59 INLINE LVecBase2d vec2() const;
60 INLINE LVecBase3d vec3() const;
61 INLINE LVecBase4d vec4() const;
62 INLINE LMatrix4d mat4() const;
63
64 INLINE int size() const;
65 INLINE const XFileDataObject &operator [] (int n) const;
66 INLINE const XFileDataObject &operator [] (const std::string &name) const;
67
68 INLINE XFileDataObject &operator [] (int n);
69 INLINE XFileDataObject &operator [] (const std::string &name);
70
71 // The following methods can be used to add elements of a specific type to a
72 // complex object, e.g. an array or a template object.
73
74 XFileDataObject &add_int(int int_value);
75 XFileDataObject &add_double(double double_value);
76 XFileDataObject &add_string(const std::string &string_value);
77
78 // The following methods can be used to add elements of a specific type,
79 // based on one of the standard templates.
80
81 XFileDataObject &add_Vector(XFile *x_file, const LVecBase3d &vector);
83 XFileDataObject &add_IndexedColor(XFile *x_file, int index,
84 const LColor &color);
85 XFileDataObject &add_Coords2d(XFile *x_file, const LVecBase2d &coords);
86
87public:
88 virtual bool add_element(XFileDataObject *element);
89
90 virtual void output_data(std::ostream &out) const;
91 virtual void write_data(std::ostream &out, int indent_level,
92 const char *separator) const;
93
94protected:
95 virtual void set_int_value(int int_value);
96 virtual void set_double_value(double double_value);
97 virtual void set_string_value(const std::string &string_value);
98 void store_double_array(int num_elements, const double *values);
99
100 virtual int get_int_value() const;
101 virtual double get_double_value() const;
102 virtual std::string get_string_value() const;
103 void get_double_array(int num_elements, double *values) const;
104
105 virtual int get_num_elements() const;
106 virtual XFileDataObject *get_element(int n);
107 virtual XFileDataObject *get_element(const std::string &name);
108
109 const XFileDataDef *_data_def;
110
111public:
112 static TypeHandle get_class_type() {
113 return _type_handle;
114 }
115 static void init_type() {
116 ReferenceCount::init_type();
117 register_type(_type_handle, "XFileDataObject",
118 ReferenceCount::get_class_type());
119 }
120 virtual TypeHandle get_type() const {
121 return get_class_type();
122 }
123 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
124
125private:
126 static TypeHandle _type_handle;
127};
128
129INLINE std::ostream &operator << (std::ostream &out, const XFileDataObject &data_object);
130
131#include "xFileDataObject.I"
132
133#endif
A base class for all things that want to be reference-counted.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
A definition of a single data element appearing within a template record.
The abstract base class for a number of different types of data elements that may be stored in the X ...
const XFileDataDef * get_data_def() const
Returns the data object that this object is represented by, if any, or NULL if there is none.
void set(int int_value)
Stores the indicated integer value into the object, if it makes sense to do so.
virtual std::string get_type_name() const
Returns a string that represents the type of object this data object represents.
XFileDataObject & add_int(int int_value)
Appends a new integer value to the data object, if it makes sense to do so.
void operator=(int int_value)
Stores the indicated integer value into the object, if it makes sense to do so.
LMatrix4d mat4() const
Returns the object's representation as an LMatrix4d.
LVecBase4d vec4() const
Returns the object's representation as an LVecBase4d.
virtual bool is_complex_object() const
Returns true if this kind of data object is a complex object that can hold nested data elements,...
double d() const
Unambiguously returns the object's representation as a double, or 0.0 if the object has no double rep...
int i() const
Unambiguously returns the object's representation as an integer, or 0 if the object has no integer re...
std::string s() const
Unambiguously returns the object's representation as a string, or empty string if the object has no s...
virtual void write_data(std::ostream &out, int indent_level, const char *separator) const
Writes a suitable representation of this node to an .x file in text mode.
XFileDataObject & add_MeshFace(XFile *x_file)
Appends a new MeshFace instance.
int size() const
Returns the number of nested data objects within this object.
virtual void output_data(std::ostream &out) const
Writes a suitable representation of this node to an .x file in text mode.
XFileDataObject & add_Vector(XFile *x_file, const LVecBase3d &vector)
Appends a new Vector instance.
XFileDataObject & add_double(double double_value)
Appends a new floating-point value to the data object, if it makes sense to do so.
LVecBase3d vec3() const
Returns the object's representation as an LVecBase3d.
LVecBase2d vec2() const
Returns the object's representation as an LVecBase2d.
XFileDataObject & add_IndexedColor(XFile *x_file, int index, const LColor &color)
Appends a new IndexedColor instance.
XFileDataObject & add_string(const std::string &string_value)
Appends a new string value to the data object, if it makes sense to do so.
virtual bool add_element(XFileDataObject *element)
Adds the indicated element as a nested data element, if this data object type supports it.
const XFileDataObject & operator[](int n) const
Returns the nth nested object within this object.
XFileDataObject & add_Coords2d(XFile *x_file, const LVecBase2d &coords)
Appends a new Coords2d instance.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.