storage_bin.h

00001 #ifndef VVELIB_STORAGE_STORAGE_BIN_H
00002 #define VVELIB_STORAGE_STORAGE_BIN_H
00003 
00009 #include <config.h>
00010 #include <storage/storage.h>
00011 #include <storage/types.h>
00012 #include <QFile>
00013 #include <stack>
00014 
00015 class Model;
00016 
00022 namespace storage
00023 {
00027   struct Frame
00028   {
00029     Frame(int u = 0, bool h = false)
00030       : unnamed_subframes(u)
00031       , has_fields(h)
00032     {}
00033 
00034     Frame(const Frame& copy)
00035       : unnamed_subframes(copy.unnamed_subframes)
00036       , has_fields(copy.has_fields)
00037     {}
00038 
00039     int unnamed_subframes;
00040     bool has_fields;
00041   };
00042 
00047   class VVEStorage_BINWriter : public VVEStorage
00048   {
00049   public:
00051     typedef ptrdiff_t reference_t;
00052 
00053     VVEStorage_BINWriter();
00054     virtual ~VVEStorage_BINWriter() {}
00055 
00059     virtual bool serialize(const QString& filename, Model* model);
00060 
00061     virtual bool startCompound(const QString& name);
00062     virtual bool endCompound();
00063 
00064     virtual int startReference(const QString& name, const QString& ref_type, reference_t ref);
00065     virtual bool endReference();
00066 
00067     virtual bool reader() { return false; }
00068     virtual bool writer() { return true; }
00069 
00070 #define DEF_FIELD(T) virtual bool field(const QString& name, T& value);
00071     FOR_ALL_TYPES(DEF_FIELD)
00072 #undef DEF_FIELD
00073 
00074     bool checkNextField(const QString& ) { return false; }
00075 
00079     virtual QString filename() const
00080     {
00081       if(file)
00082         return file->fileName();
00083       else
00084         return "";
00085     }
00086 
00087   protected:
00088     bool createElement(const QString& name, unsigned char type);
00089     bool checkFileStatus();
00090     bool resolveFrame(bool named_field = true);
00091 
00092     template <typename T>
00093     bool writeField(const QString& name, T& value);
00094 
00095     QFile *file;
00097     std::stack<Frame> frame_stack;
00098 #ifdef USE_HASH
00099     typedef std::unordered_map<reference_t,int> ref_t;
00100     std::unordered_map<QString, ref_t> references;
00101 #else
00102     typedef std::map<reference_t,int> ref_t;
00103     std::map<QString, ref_t> references;
00104 #endif
00105   };
00106 
00111   class VVEStorage_BINReader : public VVEStorage
00112   {
00113   public:
00115     typedef ptrdiff_t reference_t;
00116 
00117     VVEStorage_BINReader();
00118     virtual ~VVEStorage_BINReader() {}
00119 
00120     virtual bool setOption(int option, int value);
00121 
00125     virtual bool serialize(const QString& filename, Model* model);
00126 
00127     virtual bool startCompound(const QString& name);
00128     virtual bool endCompound();
00129     virtual bool ignore(const QString& name);
00130 
00131     virtual int startReference(const QString& name, const QString& ref_type, reference_t ref);
00132     virtual bool endReference();
00133 
00134     virtual bool reader() { return true; }
00135     virtual bool writer() { return false; }
00136 
00137 #define DEF_FIELD(T) virtual bool field(const QString& name, T& value);
00138     FOR_ALL_TYPES(DEF_FIELD)
00139 #undef DEF_FIELD
00140 
00141     bool checkNextField(const QString& name);
00142     virtual void setLastError(int error, const QString& err);
00143 
00147     virtual QString filename() const
00148     {
00149       if(file)
00150         return file->fileName();
00151       else
00152         return "";
00153     }
00154 
00155   protected:
00156     unsigned char nextElementType();
00157     const QString& nextElementName();
00158     bool checkFileStatus();
00159     bool skipNext();
00160     bool skipToEnd();
00161 
00162     template <typename Read, typename Store>
00163     bool readData(QFile* file, Store& value);
00164 
00165     template <typename T>
00166     bool readValue(const QString& name, T& value);
00167 
00168     bool resolveFrame(bool named_field = true);
00169 
00170     QFile *file;
00171     int type_check;
00173     std::stack<Frame> frame_stack;
00180     int top_level_compounds;
00181 
00182     void elementUsed();
00183 
00184     QString next_element_name;
00185     bool has_next_element_name;
00186 
00187     TYPES type_conversion[NB_STORAGE_TYPES];
00188     size_t type_size[NB_STORAGE_TYPES];
00189     NUMBER_CLASS type_class[NB_STORAGE_TYPES];
00190   };
00191 }
00192 
00193 #endif // VVELIB_STORAGE_STORAGE_BIN_H
00194 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:37:52 2013 for VVE by  doxygen 1.6.3