Panda3D
xFileDataObject.I
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.I
10  * @author drose
11  * @date 2004-10-03
12  */
13 
14 /**
15  *
16  */
17 INLINE XFileDataObject::
18 XFileDataObject(const XFileDataDef *data_def) :
19  _data_def(data_def)
20 {
21 }
22 
23 /**
24  * Returns the data object that this object is represented by, if any, or NULL
25  * if there is none.
26  */
27 INLINE const XFileDataDef *XFileDataObject::
28 get_data_def() const {
29  return _data_def;
30 }
31 
32 /**
33  * Stores the indicated integer value into the object, if it makes sense to do
34  * so. It is an error to call this on an object that cannot accept an integer
35  * value.
36  */
37 INLINE void XFileDataObject::
38 operator = (int int_value) {
39  set(int_value);
40 }
41 
42 /**
43  * Stores the indicated floating-point value into the object, if it makes
44  * sense to do so. It is an error to call this on an object that cannot
45  * accept a floating-point value.
46  */
47 INLINE void XFileDataObject::
48 operator = (double double_value) {
49  set(double_value);
50 }
51 
52 /**
53  * Stores the indicated string value into the object, if it makes sense to do
54  * so. It is an error to call this on an object that cannot accept a string
55  * value.
56  */
57 INLINE void XFileDataObject::
58 operator = (const std::string &string_value) {
59  set(string_value);
60 }
61 
62 /**
63  * Stores the indicated Vec2 value into the object, if it makes sense to do
64  * so. It is an error to call this on an object that does not store two
65  * floating-point values.
66  */
67 INLINE void XFileDataObject::
68 operator = (const LVecBase2d &vec) {
69  set(vec);
70 }
71 
72 /**
73  * Stores the indicated Vec3 value into the object, if it makes sense to do
74  * so. It is an error to call this on an object that does not store three
75  * floating-point values.
76  */
77 INLINE void XFileDataObject::
78 operator = (const LVecBase3d &vec) {
79  set(vec);
80 }
81 
82 /**
83  * Stores the indicated Vec4 value into the object, if it makes sense to do
84  * so. It is an error to call this on an object that does not store four
85  * floating-point values.
86  */
87 INLINE void XFileDataObject::
88 operator = (const LVecBase4d &vec) {
89  set(vec);
90 }
91 
92 /**
93  * Stores the indicated Matrix value into the object, if it makes sense to do
94  * so. It is an error to call this on an object that does not store sixteen
95  * floating-point values.
96  */
97 INLINE void XFileDataObject::
98 operator = (const LMatrix4d &mat) {
99  set(mat);
100 }
101 
102 /**
103  * Stores the indicated integer value into the object, if it makes sense to do
104  * so. It is an error to call this on an object that cannot accept an integer
105  * value.
106  */
107 INLINE void XFileDataObject::
108 set(int int_value) {
109  set_int_value(int_value);
110 }
111 
112 /**
113  * Stores the indicated floating-point value into the object, if it makes
114  * sense to do so. It is an error to call this on an object that cannot
115  * accept a floating-point value.
116  */
117 INLINE void XFileDataObject::
118 set(double double_value) {
119  set_double_value(double_value);
120 }
121 
122 /**
123  * Stores the indicated string value into the object, if it makes sense to do
124  * so. It is an error to call this on an object that cannot accept a string
125  * value.
126  */
127 INLINE void XFileDataObject::
128 set(const std::string &string_value) {
129  set_string_value(string_value);
130 }
131 
132 /**
133  * Stores the indicated Vec2 value into the object, if it makes sense to do
134  * so. It is an error to call this on an object that does not store two
135  * floating-point values.
136  */
137 INLINE void XFileDataObject::
138 set(const LVecBase2d &vec) {
139  store_double_array(2, vec.get_data());
140 }
141 
142 /**
143  * Stores the indicated Vec3 value into the object, if it makes sense to do
144  * so. It is an error to call this on an object that does not store three
145  * floating-point values.
146  */
147 INLINE void XFileDataObject::
148 set(const LVecBase3d &vec) {
149  store_double_array(3, vec.get_data());
150 }
151 
152 /**
153  * Stores the indicated Vec4 value into the object, if it makes sense to do
154  * so. It is an error to call this on an object that does not store four
155  * floating-point values.
156  */
157 INLINE void XFileDataObject::
158 set(const LVecBase4d &vec) {
159  store_double_array(4, vec.get_data());
160 }
161 
162 /**
163  * Stores the indicated Matrix value into the object, if it makes sense to do
164  * so. It is an error to call this on an object that does not store sixteen
165  * floating-point values.
166  */
167 INLINE void XFileDataObject::
168 set(const LMatrix4d &mat) {
169  store_double_array(16, mat.get_data());
170 }
171 
172 /**
173  * Unambiguously returns the object's representation as an integer, or 0 if
174  * the object has no integer representation. See also get_data_def() to
175  * determine what kind of representation this object has.
176  */
177 INLINE int XFileDataObject::
178 i() const {
179  return get_int_value();
180 }
181 
182 /**
183  * Unambiguously returns the object's representation as a double, or 0.0 if
184  * the object has no double representation. See also get_data_def() to
185  * determine what kind of representation this object has.
186  */
187 INLINE double XFileDataObject::
188 d() const {
189  return get_double_value();
190 }
191 
192 /**
193  * Unambiguously returns the object's representation as a string, or empty
194  * string if the object has no string representation. See also get_data_def()
195  * to determine what kind of representation this object has.
196  */
197 INLINE std::string XFileDataObject::
198 s() const {
199  return get_string_value();
200 }
201 
202 /**
203  * Returns the object's representation as an LVecBase2d. It is an error if
204  * the object does not have two nested objects that store a double value.
205  */
206 INLINE LVecBase2d XFileDataObject::
207 vec2() const {
208  LVecBase2d vec;
209  get_double_array(2, &vec[0]);
210  return vec;
211 }
212 
213 /**
214  * Returns the object's representation as an LVecBase3d. It is an error if
215  * the object does not have three nested objects that store a double value.
216  */
217 INLINE LVecBase3d XFileDataObject::
218 vec3() const {
219  LVecBase3d vec;
220  get_double_array(3, &vec[0]);
221  return vec;
222 }
223 
224 /**
225  * Returns the object's representation as an LVecBase4d. It is an error if
226  * the object does not have four nested objects that store a double value.
227  */
228 INLINE LVecBase4d XFileDataObject::
229 vec4() const {
230  LVecBase4d vec;
231  get_double_array(4, &vec[0]);
232  return vec;
233 }
234 
235 /**
236  * Returns the object's representation as an LMatrix4d. It is an error if the
237  * object does not have sixteen nested objects that store a double value.
238  */
239 INLINE LMatrix4d XFileDataObject::
240 mat4() const {
241  LMatrix4d mat;
242  get_double_array(16, &mat(0, 0));
243  return mat;
244 }
245 
246 /**
247  * Returns the number of nested data objects within this object.
248  */
249 INLINE int XFileDataObject::
250 size() const {
251  return get_num_elements();
252 }
253 
254 /**
255  * Returns the nth nested object within this object. Call get_num_children()
256  * to determine the number of nested objects.
257  */
259 operator [] (int n) const {
260  const XFileDataObject *element = ((XFileDataObject *)this)->get_element(n);
261  nassertr(element != nullptr, *this);
262  return *element;
263 }
264 
265 /**
266  * Returns the named nested object within this object. It is an error if the
267  * named object does not exist. Call find_child() instead if there is any
268  * doubt.
269  */
271 operator [] (const std::string &name) const {
272  const XFileDataObject *element = ((XFileDataObject *)this)->get_element(name);
273  nassertr(element != nullptr, *this);
274  return *element;
275 }
276 
277 /**
278  * Returns the nth nested object within this object. Call get_num_children()
279  * to determine the number of nested objects.
280  */
282 operator [] (int n) {
283  XFileDataObject *element = get_element(n);
284  nassertr(element != nullptr, *this);
285  return *element;
286 }
287 
288 /**
289  * Returns the named nested object within this object. It is an error if the
290  * named object does not exist. Call find_child() instead if there is any
291  * doubt.
292  */
294 operator [] (const std::string &name) {
295  XFileDataObject *element = get_element(name);
296  nassertr(element != nullptr, *this);
297  return *element;
298 }
299 
300 INLINE std::ostream &
301 operator << (std::ostream &out, const XFileDataObject &data_object) {
302  data_object.output_data(out);
303  return out;
304 }
virtual void output_data(std::ostream &out) const
Writes a suitable representation of this node to an .x file in text mode.
std::string s() const
Unambiguously returns the object's representation as a string, or empty string if the object has no s...
int i() const
Unambiguously returns the object's representation as an integer, or 0 if the object has no integer re...
const XFileDataDef * get_data_def() const
Returns the data object that this object is represented by, if any, or NULL if there is none.
A definition of a single data element appearing within a template record.
Definition: xFileDataDef.h:31
LVecBase4d vec4() const
Returns the object's representation as an LVecBase4d.
void set(int int_value)
Stores the indicated integer value into the object, if it makes sense to do so.
int size() const
Returns the number of nested data objects within this object.
LVecBase2d vec2() const
Returns the object's representation as an LVecBase2d.
LMatrix4d mat4() const
Returns the object's representation as an LMatrix4d.
void operator=(int int_value)
Stores the indicated integer value into the object, if it makes sense to do so.
double d() const
Unambiguously returns the object's representation as a double, or 0.0 if the object has no double rep...
LVecBase3d vec3() const
Returns the object's representation as an LVecBase3d.
const XFileDataObject & operator [](int n) const
Returns the nth nested object within this object.
The abstract base class for a number of different types of data elements that may be stored in the X ...