Panda3D
 All Classes Functions Variables Enumerations
xFileDataObject.I
00001 // Filename: xFileDataObject.I
00002 // Created by:  drose (03Oct04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: XFileDataObject::Constructor
00018 //       Access: Public
00019 //  Description:
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE XFileDataObject::
00022 XFileDataObject(const XFileDataDef *data_def) :
00023   _data_def(data_def)
00024 {
00025 }
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: XFileDataObject::get_data_def
00029 //       Access: Public
00030 //  Description: Returns the data object that this object is
00031 //               represented by, if any, or NULL if there is none.
00032 ////////////////////////////////////////////////////////////////////
00033 INLINE const XFileDataDef *XFileDataObject::
00034 get_data_def() const {
00035   return _data_def;
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //     Function: XFileDataObject::operator = (int)
00040 //       Access: Public
00041 //  Description: Stores the indicated integer value into the object,
00042 //               if it makes sense to do so.  It is an error to call
00043 //               this on an object that cannot accept an integer value.
00044 ////////////////////////////////////////////////////////////////////
00045 INLINE void XFileDataObject::
00046 operator = (int int_value) {
00047   set(int_value);
00048 }
00049 
00050 ////////////////////////////////////////////////////////////////////
00051 //     Function: XFileDataObject::operator = (double)
00052 //       Access: Public
00053 //  Description: Stores the indicated floating-point value into the
00054 //               object, if it makes sense to do so.  It is an error
00055 //               to call this on an object that cannot accept a
00056 //               floating-point value.
00057 ////////////////////////////////////////////////////////////////////
00058 INLINE void XFileDataObject::
00059 operator = (double double_value) {
00060   set(double_value);
00061 }
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //     Function: XFileDataObject::operator = (string)
00065 //       Access: Public
00066 //  Description: Stores the indicated string value into the
00067 //               object, if it makes sense to do so.  It is an error
00068 //               to call this on an object that cannot accept a
00069 //               string value.
00070 ////////////////////////////////////////////////////////////////////
00071 INLINE void XFileDataObject::
00072 operator = (const string &string_value) {
00073   set(string_value);
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: XFileDataObject::operator = (vec2)
00078 //       Access: Public
00079 //  Description: Stores the indicated Vec2 value into the object,
00080 //               if it makes sense to do so.  It is an error to call
00081 //               this on an object that does not store two
00082 //               floating-point values.
00083 ////////////////////////////////////////////////////////////////////
00084 INLINE void XFileDataObject::
00085 operator = (const LVecBase2d &vec) {
00086   set(vec);
00087 }
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: XFileDataObject::operator = (vec3)
00091 //       Access: Public
00092 //  Description: Stores the indicated Vec3 value into the object,
00093 //               if it makes sense to do so.  It is an error to call
00094 //               this on an object that does not store three
00095 //               floating-point values.
00096 ////////////////////////////////////////////////////////////////////
00097 INLINE void XFileDataObject::
00098 operator = (const LVecBase3d &vec) {
00099   set(vec);
00100 }
00101 
00102 ////////////////////////////////////////////////////////////////////
00103 //     Function: XFileDataObject::operator = (vec4)
00104 //       Access: Public
00105 //  Description: Stores the indicated Vec4 value into the object,
00106 //               if it makes sense to do so.  It is an error to call
00107 //               this on an object that does not store four
00108 //               floating-point values.
00109 ////////////////////////////////////////////////////////////////////
00110 INLINE void XFileDataObject::
00111 operator = (const LVecBase4d &vec) {
00112   set(vec);
00113 }
00114 
00115 ////////////////////////////////////////////////////////////////////
00116 //     Function: XFileDataObject::operator = (mat)
00117 //       Access: Public
00118 //  Description: Stores the indicated Matrix value into the object,
00119 //               if it makes sense to do so.  It is an error to call
00120 //               this on an object that does not store sixteen
00121 //               floating-point values.
00122 ////////////////////////////////////////////////////////////////////
00123 INLINE void XFileDataObject::
00124 operator = (const LMatrix4d &mat) {
00125   set(mat);
00126 }
00127 
00128 ////////////////////////////////////////////////////////////////////
00129 //     Function: XFileDataObject::set(int)
00130 //       Access: Public
00131 //  Description: Stores the indicated integer value into the object,
00132 //               if it makes sense to do so.  It is an error to call
00133 //               this on an object that cannot accept an integer value.
00134 ////////////////////////////////////////////////////////////////////
00135 INLINE void XFileDataObject::
00136 set(int int_value) {
00137   set_int_value(int_value);
00138 }
00139 
00140 ////////////////////////////////////////////////////////////////////
00141 //     Function: XFileDataObject::set(double)
00142 //       Access: Public
00143 //  Description: Stores the indicated floating-point value into the
00144 //               object, if it makes sense to do so.  It is an error
00145 //               to call this on an object that cannot accept a
00146 //               floating-point value.
00147 ////////////////////////////////////////////////////////////////////
00148 INLINE void XFileDataObject::
00149 set(double double_value) {
00150   set_double_value(double_value);
00151 }
00152 
00153 ////////////////////////////////////////////////////////////////////
00154 //     Function: XFileDataObject::set(string)
00155 //       Access: Public
00156 //  Description: Stores the indicated string value into the
00157 //               object, if it makes sense to do so.  It is an error
00158 //               to call this on an object that cannot accept a
00159 //               string value.
00160 ////////////////////////////////////////////////////////////////////
00161 INLINE void XFileDataObject::
00162 set(const string &string_value) {
00163   set_string_value(string_value);
00164 }
00165 
00166 ////////////////////////////////////////////////////////////////////
00167 //     Function: XFileDataObject::set(vec2)
00168 //       Access: Public
00169 //  Description: Stores the indicated Vec2 value into the object,
00170 //               if it makes sense to do so.  It is an error to call
00171 //               this on an object that does not store two
00172 //               floating-point values.
00173 ////////////////////////////////////////////////////////////////////
00174 INLINE void XFileDataObject::
00175 set(const LVecBase2d &vec) {
00176   store_double_array(2, vec.get_data());
00177 }
00178 
00179 ////////////////////////////////////////////////////////////////////
00180 //     Function: XFileDataObject::set(vec3)
00181 //       Access: Public
00182 //  Description: Stores the indicated Vec3 value into the object,
00183 //               if it makes sense to do so.  It is an error to call
00184 //               this on an object that does not store three
00185 //               floating-point values.
00186 ////////////////////////////////////////////////////////////////////
00187 INLINE void XFileDataObject::
00188 set(const LVecBase3d &vec) {
00189   store_double_array(3, vec.get_data());
00190 }
00191 
00192 ////////////////////////////////////////////////////////////////////
00193 //     Function: XFileDataObject::set(vec4)
00194 //       Access: Public
00195 //  Description: Stores the indicated Vec4 value into the object,
00196 //               if it makes sense to do so.  It is an error to call
00197 //               this on an object that does not store four
00198 //               floating-point values.
00199 ////////////////////////////////////////////////////////////////////
00200 INLINE void XFileDataObject::
00201 set(const LVecBase4d &vec) {
00202   store_double_array(4, vec.get_data());
00203 }
00204 
00205 ////////////////////////////////////////////////////////////////////
00206 //     Function: XFileDataObject::set(mat)
00207 //       Access: Public
00208 //  Description: Stores the indicated Matrix value into the object,
00209 //               if it makes sense to do so.  It is an error to call
00210 //               this on an object that does not store sixteen
00211 //               floating-point values.
00212 ////////////////////////////////////////////////////////////////////
00213 INLINE void XFileDataObject::
00214 set(const LMatrix4d &mat) {
00215   store_double_array(16, mat.get_data());
00216 }
00217 
00218 ////////////////////////////////////////////////////////////////////
00219 //     Function: XFileDataObject::i
00220 //       Access: Public
00221 //  Description: Unambiguously returns the object's representation as
00222 //               an integer, or 0 if the object has no integer
00223 //               representation.  See also get_data_def() to determine
00224 //               what kind of representation this object has.
00225 ////////////////////////////////////////////////////////////////////
00226 INLINE int XFileDataObject::
00227 i() const {
00228   return get_int_value();
00229 }
00230 
00231 ////////////////////////////////////////////////////////////////////
00232 //     Function: XFileDataObject::d
00233 //       Access: Public
00234 //  Description: Unambiguously returns the object's representation as
00235 //               a double, or 0.0 if the object has no double
00236 //               representation.  See also get_data_def() to determine
00237 //               what kind of representation this object has.
00238 ////////////////////////////////////////////////////////////////////
00239 INLINE double XFileDataObject::
00240 d() const {
00241   return get_double_value();
00242 }
00243 
00244 ////////////////////////////////////////////////////////////////////
00245 //     Function: XFileDataObject::s
00246 //       Access: Public
00247 //  Description: Unambiguously returns the object's representation as
00248 //               a string, or empty string if the object has no string
00249 //               representation.  See also get_data_def() to determine
00250 //               what kind of representation this object has.
00251 ////////////////////////////////////////////////////////////////////
00252 INLINE string XFileDataObject::
00253 s() const {
00254   return get_string_value();
00255 }
00256 
00257 ////////////////////////////////////////////////////////////////////
00258 //     Function: XFileDataObject::vec2
00259 //       Access: Public
00260 //  Description: Returns the object's representation as an LVecBase2d.
00261 //               It is an error if the object does not have two nested
00262 //               objects that store a double value.
00263 ////////////////////////////////////////////////////////////////////
00264 INLINE LVecBase2d XFileDataObject::
00265 vec2() const {
00266   LVecBase2d vec;
00267   get_double_array(2, &vec[0]);
00268   return vec;
00269 }
00270 
00271 ////////////////////////////////////////////////////////////////////
00272 //     Function: XFileDataObject::vec3
00273 //       Access: Public
00274 //  Description: Returns the object's representation as an LVecBase3d.
00275 //               It is an error if the object does not have three nested
00276 //               objects that store a double value.
00277 ////////////////////////////////////////////////////////////////////
00278 INLINE LVecBase3d XFileDataObject::
00279 vec3() const {
00280   LVecBase3d vec;
00281   get_double_array(3, &vec[0]);
00282   return vec;
00283 }
00284 
00285 ////////////////////////////////////////////////////////////////////
00286 //     Function: XFileDataObject::vec4
00287 //       Access: Public
00288 //  Description: Returns the object's representation as an LVecBase4d.
00289 //               It is an error if the object does not have four nested
00290 //               objects that store a double value.
00291 ////////////////////////////////////////////////////////////////////
00292 INLINE LVecBase4d XFileDataObject::
00293 vec4() const {
00294   LVecBase4d vec;
00295   get_double_array(4, &vec[0]);
00296   return vec;
00297 }
00298 
00299 ////////////////////////////////////////////////////////////////////
00300 //     Function: XFileDataObject::mat4
00301 //       Access: Public
00302 //  Description: Returns the object's representation as an LMatrix4d.
00303 //               It is an error if the object does not have sixteen
00304 //               nested objects that store a double value.
00305 ////////////////////////////////////////////////////////////////////
00306 INLINE LMatrix4d XFileDataObject::
00307 mat4() const {
00308   LMatrix4d mat;
00309   get_double_array(16, &mat(0, 0));
00310   return mat;
00311 }
00312 
00313 ////////////////////////////////////////////////////////////////////
00314 //     Function: XFileDataObject::size
00315 //       Access: Public
00316 //  Description: Returns the number of nested data objects within this
00317 //               object.
00318 ////////////////////////////////////////////////////////////////////
00319 INLINE int XFileDataObject::
00320 size() const {
00321   return get_num_elements();
00322 }
00323 
00324 ////////////////////////////////////////////////////////////////////
00325 //     Function: XFileDataObject::operator [] (int)
00326 //       Access: Public
00327 //  Description: Returns the nth nested object within this object.
00328 //               Call get_num_children() to determine the number of
00329 //               nested objects.
00330 ////////////////////////////////////////////////////////////////////
00331 INLINE const XFileDataObject &XFileDataObject::
00332 operator [] (int n) const {
00333   const XFileDataObject *element = ((XFileDataObject *)this)->get_element(n);
00334   nassertr(element != (XFileDataObject *)NULL, *this);
00335   return *element;
00336 }
00337 
00338 ////////////////////////////////////////////////////////////////////
00339 //     Function: XFileDataObject::operator [] (string)
00340 //       Access: Public
00341 //  Description: Returns the named nested object within this object.
00342 //               It is an error if the named object does not exist.
00343 //               Call find_child() instead if there is any doubt.
00344 ////////////////////////////////////////////////////////////////////
00345 INLINE const XFileDataObject &XFileDataObject::
00346 operator [] (const string &name) const {
00347   const XFileDataObject *element = ((XFileDataObject *)this)->get_element(name);
00348   nassertr(element != (XFileDataObject *)NULL, *this);
00349   return *element;
00350 }
00351 
00352 ////////////////////////////////////////////////////////////////////
00353 //     Function: XFileDataObject::operator [] (int)
00354 //       Access: Public
00355 //  Description: Returns the nth nested object within this object.
00356 //               Call get_num_children() to determine the number of
00357 //               nested objects.
00358 ////////////////////////////////////////////////////////////////////
00359 INLINE XFileDataObject &XFileDataObject::
00360 operator [] (int n) {
00361   XFileDataObject *element = get_element(n);
00362   nassertr(element != (XFileDataObject *)NULL, *this);
00363   return *element;
00364 }
00365 
00366 ////////////////////////////////////////////////////////////////////
00367 //     Function: XFileDataObject::operator [] (string)
00368 //       Access: Public
00369 //  Description: Returns the named nested object within this object.
00370 //               It is an error if the named object does not exist.
00371 //               Call find_child() instead if there is any doubt.
00372 ////////////////////////////////////////////////////////////////////
00373 INLINE XFileDataObject &XFileDataObject::
00374 operator [] (const string &name) {
00375   XFileDataObject *element = get_element(name);
00376   nassertr(element != (XFileDataObject *)NULL, *this);
00377   return *element;
00378 }
00379 
00380 INLINE ostream &
00381 operator << (ostream &out, const XFileDataObject &data_object) {
00382   data_object.output_data(out);
00383   return out;
00384 }
 All Classes Functions Variables Enumerations