Panda3D
xFileDataObject.I
1 // Filename: xFileDataObject.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: XFileDataObject::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE XFileDataObject::
22 XFileDataObject(const XFileDataDef *data_def) :
23  _data_def(data_def)
24 {
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: XFileDataObject::get_data_def
29 // Access: Public
30 // Description: Returns the data object that this object is
31 // represented by, if any, or NULL if there is none.
32 ////////////////////////////////////////////////////////////////////
33 INLINE const XFileDataDef *XFileDataObject::
34 get_data_def() const {
35  return _data_def;
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: XFileDataObject::operator = (int)
40 // Access: Public
41 // Description: Stores the indicated integer value into the object,
42 // if it makes sense to do so. It is an error to call
43 // this on an object that cannot accept an integer value.
44 ////////////////////////////////////////////////////////////////////
45 INLINE void XFileDataObject::
46 operator = (int int_value) {
47  set(int_value);
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: XFileDataObject::operator = (double)
52 // Access: Public
53 // Description: Stores the indicated floating-point value into the
54 // object, if it makes sense to do so. It is an error
55 // to call this on an object that cannot accept a
56 // floating-point value.
57 ////////////////////////////////////////////////////////////////////
58 INLINE void XFileDataObject::
59 operator = (double double_value) {
60  set(double_value);
61 }
62 
63 ////////////////////////////////////////////////////////////////////
64 // Function: XFileDataObject::operator = (string)
65 // Access: Public
66 // Description: Stores the indicated string value into the
67 // object, if it makes sense to do so. It is an error
68 // to call this on an object that cannot accept a
69 // string value.
70 ////////////////////////////////////////////////////////////////////
71 INLINE void XFileDataObject::
72 operator = (const string &string_value) {
73  set(string_value);
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: XFileDataObject::operator = (vec2)
78 // Access: Public
79 // Description: Stores the indicated Vec2 value into the object,
80 // if it makes sense to do so. It is an error to call
81 // this on an object that does not store two
82 // floating-point values.
83 ////////////////////////////////////////////////////////////////////
84 INLINE void XFileDataObject::
85 operator = (const LVecBase2d &vec) {
86  set(vec);
87 }
88 
89 ////////////////////////////////////////////////////////////////////
90 // Function: XFileDataObject::operator = (vec3)
91 // Access: Public
92 // Description: Stores the indicated Vec3 value into the object,
93 // if it makes sense to do so. It is an error to call
94 // this on an object that does not store three
95 // floating-point values.
96 ////////////////////////////////////////////////////////////////////
97 INLINE void XFileDataObject::
98 operator = (const LVecBase3d &vec) {
99  set(vec);
100 }
101 
102 ////////////////////////////////////////////////////////////////////
103 // Function: XFileDataObject::operator = (vec4)
104 // Access: Public
105 // Description: Stores the indicated Vec4 value into the object,
106 // if it makes sense to do so. It is an error to call
107 // this on an object that does not store four
108 // floating-point values.
109 ////////////////////////////////////////////////////////////////////
110 INLINE void XFileDataObject::
111 operator = (const LVecBase4d &vec) {
112  set(vec);
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: XFileDataObject::operator = (mat)
117 // Access: Public
118 // Description: Stores the indicated Matrix value into the object,
119 // if it makes sense to do so. It is an error to call
120 // this on an object that does not store sixteen
121 // floating-point values.
122 ////////////////////////////////////////////////////////////////////
123 INLINE void XFileDataObject::
124 operator = (const LMatrix4d &mat) {
125  set(mat);
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: XFileDataObject::set(int)
130 // Access: Public
131 // Description: Stores the indicated integer value into the object,
132 // if it makes sense to do so. It is an error to call
133 // this on an object that cannot accept an integer value.
134 ////////////////////////////////////////////////////////////////////
135 INLINE void XFileDataObject::
136 set(int int_value) {
137  set_int_value(int_value);
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: XFileDataObject::set(double)
142 // Access: Public
143 // Description: Stores the indicated floating-point value into the
144 // object, if it makes sense to do so. It is an error
145 // to call this on an object that cannot accept a
146 // floating-point value.
147 ////////////////////////////////////////////////////////////////////
148 INLINE void XFileDataObject::
149 set(double double_value) {
150  set_double_value(double_value);
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: XFileDataObject::set(string)
155 // Access: Public
156 // Description: Stores the indicated string value into the
157 // object, if it makes sense to do so. It is an error
158 // to call this on an object that cannot accept a
159 // string value.
160 ////////////////////////////////////////////////////////////////////
161 INLINE void XFileDataObject::
162 set(const string &string_value) {
163  set_string_value(string_value);
164 }
165 
166 ////////////////////////////////////////////////////////////////////
167 // Function: XFileDataObject::set(vec2)
168 // Access: Public
169 // Description: Stores the indicated Vec2 value into the object,
170 // if it makes sense to do so. It is an error to call
171 // this on an object that does not store two
172 // floating-point values.
173 ////////////////////////////////////////////////////////////////////
174 INLINE void XFileDataObject::
175 set(const LVecBase2d &vec) {
176  store_double_array(2, vec.get_data());
177 }
178 
179 ////////////////////////////////////////////////////////////////////
180 // Function: XFileDataObject::set(vec3)
181 // Access: Public
182 // Description: Stores the indicated Vec3 value into the object,
183 // if it makes sense to do so. It is an error to call
184 // this on an object that does not store three
185 // floating-point values.
186 ////////////////////////////////////////////////////////////////////
187 INLINE void XFileDataObject::
188 set(const LVecBase3d &vec) {
189  store_double_array(3, vec.get_data());
190 }
191 
192 ////////////////////////////////////////////////////////////////////
193 // Function: XFileDataObject::set(vec4)
194 // Access: Public
195 // Description: Stores the indicated Vec4 value into the object,
196 // if it makes sense to do so. It is an error to call
197 // this on an object that does not store four
198 // floating-point values.
199 ////////////////////////////////////////////////////////////////////
200 INLINE void XFileDataObject::
201 set(const LVecBase4d &vec) {
202  store_double_array(4, vec.get_data());
203 }
204 
205 ////////////////////////////////////////////////////////////////////
206 // Function: XFileDataObject::set(mat)
207 // Access: Public
208 // Description: Stores the indicated Matrix value into the object,
209 // if it makes sense to do so. It is an error to call
210 // this on an object that does not store sixteen
211 // floating-point values.
212 ////////////////////////////////////////////////////////////////////
213 INLINE void XFileDataObject::
214 set(const LMatrix4d &mat) {
215  store_double_array(16, mat.get_data());
216 }
217 
218 ////////////////////////////////////////////////////////////////////
219 // Function: XFileDataObject::i
220 // Access: Public
221 // Description: Unambiguously returns the object's representation as
222 // an integer, or 0 if the object has no integer
223 // representation. See also get_data_def() to determine
224 // what kind of representation this object has.
225 ////////////////////////////////////////////////////////////////////
226 INLINE int XFileDataObject::
227 i() const {
228  return get_int_value();
229 }
230 
231 ////////////////////////////////////////////////////////////////////
232 // Function: XFileDataObject::d
233 // Access: Public
234 // Description: Unambiguously returns the object's representation as
235 // a double, or 0.0 if the object has no double
236 // representation. See also get_data_def() to determine
237 // what kind of representation this object has.
238 ////////////////////////////////////////////////////////////////////
239 INLINE double XFileDataObject::
240 d() const {
241  return get_double_value();
242 }
243 
244 ////////////////////////////////////////////////////////////////////
245 // Function: XFileDataObject::s
246 // Access: Public
247 // Description: Unambiguously returns the object's representation as
248 // a string, or empty string if the object has no string
249 // representation. See also get_data_def() to determine
250 // what kind of representation this object has.
251 ////////////////////////////////////////////////////////////////////
252 INLINE string XFileDataObject::
253 s() const {
254  return get_string_value();
255 }
256 
257 ////////////////////////////////////////////////////////////////////
258 // Function: XFileDataObject::vec2
259 // Access: Public
260 // Description: Returns the object's representation as an LVecBase2d.
261 // It is an error if the object does not have two nested
262 // objects that store a double value.
263 ////////////////////////////////////////////////////////////////////
265 vec2() const {
266  LVecBase2d vec;
267  get_double_array(2, &vec[0]);
268  return vec;
269 }
270 
271 ////////////////////////////////////////////////////////////////////
272 // Function: XFileDataObject::vec3
273 // Access: Public
274 // Description: Returns the object's representation as an LVecBase3d.
275 // It is an error if the object does not have three nested
276 // objects that store a double value.
277 ////////////////////////////////////////////////////////////////////
279 vec3() const {
280  LVecBase3d vec;
281  get_double_array(3, &vec[0]);
282  return vec;
283 }
284 
285 ////////////////////////////////////////////////////////////////////
286 // Function: XFileDataObject::vec4
287 // Access: Public
288 // Description: Returns the object's representation as an LVecBase4d.
289 // It is an error if the object does not have four nested
290 // objects that store a double value.
291 ////////////////////////////////////////////////////////////////////
293 vec4() const {
294  LVecBase4d vec;
295  get_double_array(4, &vec[0]);
296  return vec;
297 }
298 
299 ////////////////////////////////////////////////////////////////////
300 // Function: XFileDataObject::mat4
301 // Access: Public
302 // Description: Returns the object's representation as an LMatrix4d.
303 // It is an error if the object does not have sixteen
304 // nested objects that store a double value.
305 ////////////////////////////////////////////////////////////////////
307 mat4() const {
308  LMatrix4d mat;
309  get_double_array(16, &mat(0, 0));
310  return mat;
311 }
312 
313 ////////////////////////////////////////////////////////////////////
314 // Function: XFileDataObject::size
315 // Access: Public
316 // Description: Returns the number of nested data objects within this
317 // object.
318 ////////////////////////////////////////////////////////////////////
319 INLINE int XFileDataObject::
320 size() const {
321  return get_num_elements();
322 }
323 
324 ////////////////////////////////////////////////////////////////////
325 // Function: XFileDataObject::operator [] (int)
326 // Access: Public
327 // Description: Returns the nth nested object within this object.
328 // Call get_num_children() to determine the number of
329 // nested objects.
330 ////////////////////////////////////////////////////////////////////
332 operator [] (int n) const {
333  const XFileDataObject *element = ((XFileDataObject *)this)->get_element(n);
334  nassertr(element != (XFileDataObject *)NULL, *this);
335  return *element;
336 }
337 
338 ////////////////////////////////////////////////////////////////////
339 // Function: XFileDataObject::operator [] (string)
340 // Access: Public
341 // Description: Returns the named nested object within this object.
342 // It is an error if the named object does not exist.
343 // Call find_child() instead if there is any doubt.
344 ////////////////////////////////////////////////////////////////////
346 operator [] (const string &name) const {
347  const XFileDataObject *element = ((XFileDataObject *)this)->get_element(name);
348  nassertr(element != (XFileDataObject *)NULL, *this);
349  return *element;
350 }
351 
352 ////////////////////////////////////////////////////////////////////
353 // Function: XFileDataObject::operator [] (int)
354 // Access: Public
355 // Description: Returns the nth nested object within this object.
356 // Call get_num_children() to determine the number of
357 // nested objects.
358 ////////////////////////////////////////////////////////////////////
360 operator [] (int n) {
361  XFileDataObject *element = get_element(n);
362  nassertr(element != (XFileDataObject *)NULL, *this);
363  return *element;
364 }
365 
366 ////////////////////////////////////////////////////////////////////
367 // Function: XFileDataObject::operator [] (string)
368 // Access: Public
369 // Description: Returns the named nested object within this object.
370 // It is an error if the named object does not exist.
371 // Call find_child() instead if there is any doubt.
372 ////////////////////////////////////////////////////////////////////
374 operator [] (const string &name) {
375  XFileDataObject *element = get_element(name);
376  nassertr(element != (XFileDataObject *)NULL, *this);
377  return *element;
378 }
379 
380 INLINE ostream &
381 operator << (ostream &out, const XFileDataObject &data_object) {
382  data_object.output_data(out);
383  return out;
384 }
virtual void output_data(ostream &out) const
Writes a suitable representation of this node to an .x file in text mode.
const double * get_data() const
Returns the address of the first of the nine data elements in the matrix.
Definition: lmatrix.h:5733
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
string s() const
Unambiguously returns the object&#39;s representation as a string, or empty string if the object has no s...
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:1257
int i() const
Unambiguously returns the object&#39;s representation as an integer, or 0 if the object has no integer re...
const double * get_data() const
Returns the address of the first of the two data elements in the vector.
Definition: lvecBase2.h:1693
const XFileDataDef * get_data_def() const
Returns the data object that this object is represented by, if any, or NULL if there is none...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:1677
A definition of a single data element appearing within a template record.
Definition: xFileDataDef.h:35
const double * get_data() const
Returns the address of the first of the four data elements in the vector.
Definition: lvecBase4.h:2312
LVecBase4d vec4() const
Returns the object&#39;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.
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:1471
int size() const
Returns the number of nested data objects within this object.
LVecBase2d vec2() const
Returns the object&#39;s representation as an LVecBase2d.
LMatrix4d mat4() const
Returns the object&#39;s representation as an LMatrix4d.
const double * get_data() const
Returns the address of the first of the three data elements in the vector.
Definition: lvecBase3.h:2003
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&#39;s representation as a double, or 0.0 if the object has no double rep...
LVecBase3d vec3() const
Returns the object&#39;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 ...