Panda3D

xFileDataObject.h

00001 // Filename: xFileDataObject.h
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 #ifndef XFILEDATAOBJECT_H
00016 #define XFILEDATAOBJECT_H
00017 
00018 #include "pandatoolbase.h"
00019 #include "referenceCount.h"
00020 #include "pointerTo.h"
00021 #include "dcast.h"
00022 #include "luse.h"
00023 
00024 class XFile;
00025 class XFileDataDef;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : XFileDataObject
00029 // Description : The abstract base class for a number of different
00030 //               types of data elements that may be stored in the X
00031 //               file.
00032 ////////////////////////////////////////////////////////////////////
00033 class XFileDataObject : virtual public ReferenceCount {
00034 public:
00035   INLINE XFileDataObject(const XFileDataDef *data_def = NULL);
00036   virtual ~XFileDataObject();
00037 
00038   INLINE const XFileDataDef *get_data_def() const;
00039 
00040   virtual bool is_complex_object() const;
00041   virtual string get_type_name() const;
00042 
00043   INLINE void operator = (int int_value);
00044   INLINE void operator = (double double_value);
00045   INLINE void operator = (const string &string_value);
00046   INLINE void operator = (const LVecBase2d &vec);
00047   INLINE void operator = (const LVecBase3d &vec);
00048   INLINE void operator = (const LVecBase4d &vec);
00049   INLINE void operator = (const LMatrix4d &mat);
00050 
00051   INLINE void set(int int_value);
00052   INLINE void set(double double_value);
00053   INLINE void set(const string &string_value);
00054   INLINE void set(const LVecBase2d &vec);
00055   INLINE void set(const LVecBase3d &vec);
00056   INLINE void set(const LVecBase4d &vec);
00057   INLINE void set(const LMatrix4d &mat);
00058 
00059   INLINE int i() const;
00060   INLINE double d() const;
00061   INLINE string s() const;
00062   INLINE LVecBase2d vec2() const;
00063   INLINE LVecBase3d vec3() const;
00064   INLINE LVecBase4d vec4() const;
00065   INLINE LMatrix4d mat4() const;
00066 
00067   INLINE int size() const;
00068   INLINE const XFileDataObject &operator [] (int n) const;
00069   INLINE const XFileDataObject &operator [] (const string &name) const;
00070 
00071   INLINE XFileDataObject &operator [] (int n);
00072   INLINE XFileDataObject &operator [] (const string &name);
00073 
00074   // The following methods can be used to add elements of a specific
00075   // type to a complex object, e.g. an array or a template object.
00076 
00077   XFileDataObject &add_int(int int_value);
00078   XFileDataObject &add_double(double double_value);
00079   XFileDataObject &add_string(const string &string_value);
00080 
00081   // The following methods can be used to add elements of a specific
00082   // type, based on one of the standard templates.
00083 
00084   XFileDataObject &add_Vector(XFile *x_file, const LVecBase3d &vector);
00085   XFileDataObject &add_MeshFace(XFile *x_file);
00086   XFileDataObject &add_IndexedColor(XFile *x_file, int index, 
00087                                     const LColor &color);
00088   XFileDataObject &add_Coords2d(XFile *x_file, const LVecBase2d &coords);
00089 
00090 public:
00091   virtual bool add_element(XFileDataObject *element);
00092 
00093   virtual void output_data(ostream &out) const;
00094   virtual void write_data(ostream &out, int indent_level,
00095                           const char *separator) const;
00096 
00097 protected:
00098   virtual void set_int_value(int int_value);
00099   virtual void set_double_value(double double_value);
00100   virtual void set_string_value(const string &string_value);
00101   void store_double_array(int num_elements, const double *values);
00102 
00103   virtual int get_int_value() const;
00104   virtual double get_double_value() const;
00105   virtual string get_string_value() const;
00106   void get_double_array(int num_elements, double *values) const;
00107 
00108   virtual int get_num_elements() const;
00109   virtual XFileDataObject *get_element(int n);
00110   virtual XFileDataObject *get_element(const string &name);
00111 
00112   const XFileDataDef *_data_def;
00113 
00114 public:
00115   static TypeHandle get_class_type() {
00116     return _type_handle;
00117   }
00118   static void init_type() {
00119     ReferenceCount::init_type();
00120     register_type(_type_handle, "XFileDataObject",
00121                   ReferenceCount::get_class_type());
00122   }
00123   virtual TypeHandle get_type() const {
00124     return get_class_type();
00125   }
00126   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00127 
00128 private:
00129   static TypeHandle _type_handle;
00130 };
00131 
00132 INLINE ostream &operator << (ostream &out, const XFileDataObject &data_object);
00133 
00134 #include "xFileDataObject.I"
00135 
00136 #endif
00137   
00138 
00139 
 All Classes Functions Variables Enumerations