Panda3D

xFileDataDef.h

00001 // Filename: xFileDataDef.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 XFILEDATADEF_H
00016 #define XFILEDATADEF_H
00017 
00018 #include "pandatoolbase.h"
00019 #include "namable.h"
00020 #include "xFileNode.h"
00021 #include "xFileArrayDef.h"
00022 #include "xFileTemplate.h"
00023 #include "xFileDataObject.h"
00024 #include "pvector.h"
00025 #include "pointerTo.h"
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : XFileDataDef
00029 // Description : A definition of a single data element appearing
00030 //               within a template record.  This class represents the
00031 //               *definition* of the data element (e.g. DWORD
00032 //               nVertices); see XFileDataObject for its *value*
00033 //               (e.g. 12).
00034 ////////////////////////////////////////////////////////////////////
00035 class XFileDataDef : public XFileNode {
00036 public:
00037   enum Type {
00038     T_word,
00039     T_dword,
00040     T_float,
00041     T_double,
00042     T_char,
00043     T_uchar,
00044     T_sword,
00045     T_sdword,
00046     T_string,
00047     T_cstring,
00048     T_unicode,
00049     T_template,
00050   };
00051 
00052   INLINE XFileDataDef(XFile *x_file, const string &name, 
00053                       Type type, XFileTemplate *xtemplate = NULL);
00054   virtual ~XFileDataDef();
00055 
00056   virtual void clear();
00057   void add_array_def(const XFileArrayDef &array_def);
00058 
00059   INLINE Type get_data_type() const;
00060   INLINE XFileTemplate *get_template() const;
00061 
00062   INLINE int get_num_array_defs() const;
00063   INLINE const XFileArrayDef &get_array_def(int i) const; 
00064 
00065   virtual void write_text(ostream &out, int indent_level) const;
00066 
00067   virtual bool repack_data(XFileDataObject *object, 
00068                            const XFileParseDataList &parse_data_list,
00069                            PrevData &prev_data,
00070                            size_t &index, size_t &sub_index) const;
00071 
00072   virtual bool fill_zero_data(XFileDataObject *object) const;
00073 
00074   virtual bool matches(const XFileNode *other) const;
00075 
00076 private:
00077   typedef PT(XFileDataObject) 
00078     (XFileDataDef::*UnpackMethod)(const XFileParseDataList &parse_data_list, 
00079                                   const PrevData &prev_data,
00080                                   size_t &index, size_t &sub_index) const;
00081   typedef PT(XFileDataObject) 
00082     (XFileDataDef::*ZeroFillMethod)() const;
00083 
00084   PT(XFileDataObject) 
00085     unpack_integer_value(const XFileParseDataList &parse_data_list,
00086                          const PrevData &prev_data,
00087                          size_t &index, size_t &sub_index) const;
00088   PT(XFileDataObject) 
00089     unpack_double_value(const XFileParseDataList &parse_data_list,
00090                         const PrevData &prev_data,
00091                         size_t &index, size_t &sub_index) const;
00092   PT(XFileDataObject) 
00093     unpack_string_value(const XFileParseDataList &parse_data_list,
00094                         const PrevData &prev_data,
00095                         size_t &index, size_t &sub_index) const;
00096   PT(XFileDataObject) 
00097     unpack_template_value(const XFileParseDataList &parse_data_list,
00098                           const PrevData &prev_data,
00099                           size_t &index, size_t &sub_index) const;
00100 
00101   PT(XFileDataObject) 
00102     unpack_value(const XFileParseDataList &parse_data_list, int array_index,
00103                  const PrevData &prev_data,
00104                  size_t &index, size_t &sub_index,
00105                  UnpackMethod unpack_method) const;
00106 
00107   PT(XFileDataObject) zero_fill_integer_value() const;
00108   PT(XFileDataObject) zero_fill_double_value() const;
00109   PT(XFileDataObject) zero_fill_string_value() const;
00110   PT(XFileDataObject) zero_fill_template_value() const;
00111   PT(XFileDataObject) 
00112     zero_fill_value(int array_index, ZeroFillMethod zero_fill_method) const;
00113     
00114 private:
00115   Type _type;
00116   PT(XFileTemplate) _template;
00117   
00118   typedef pvector<XFileArrayDef> ArrayDef;
00119   ArrayDef _array_def;
00120   
00121 public:
00122   static TypeHandle get_class_type() {
00123     return _type_handle;
00124   }
00125   static void init_type() {
00126     XFileNode::init_type();
00127     register_type(_type_handle, "XFileDataDef",
00128                   XFileNode::get_class_type());
00129   }
00130   virtual TypeHandle get_type() const {
00131     return get_class_type();
00132   }
00133   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00134 
00135 private:
00136   static TypeHandle _type_handle;
00137 };
00138 
00139 #include "xFileDataDef.I"
00140 
00141 #endif
00142   
00143 
00144 
 All Classes Functions Variables Enumerations