storage_xml.h
Go to the documentation of this file.00001 #ifndef VVELIB_STORAGE_STORAGE_XML_H
00002 #define VVELIB_STORAGE_STORAGE_XML_H
00003
00009 #include <config.h>
00010 #include <storage/storage.h>
00011 #include <QDomDocument>
00012 #include <list>
00013 #include <storage/types.h>
00014
00015 class Model;
00016
00022 namespace storage
00023 {
00028 class VVEStorage_XMLWriter : public VVEStorage
00029 {
00030 public:
00032 typedef ptrdiff_t reference_t;
00033
00034 VVEStorage_XMLWriter();
00035 virtual ~VVEStorage_XMLWriter();
00036
00037 virtual bool setOption(int option, int value);
00038
00042 virtual bool serialize(const QString& filename, Model* model);
00043
00044 virtual bool startCompound(const QString& name);
00045 virtual bool endCompound();
00046
00047 virtual int startReference(const QString& name, const QString& ref_type, reference_t ref);
00048 virtual bool endReference();
00049
00050 virtual bool reader() { return false; }
00051 virtual bool writer() { return true; }
00052
00053 #define DEF_FIELD(T) virtual bool field(const QString& name, T& value);
00054 FOR_ALL_TYPES(DEF_FIELD)
00055 #undef DEF_FIELD
00056
00057 virtual bool checkNextField(const QString& ) { return false; }
00058
00059 virtual QString filename() const { return _filename; }
00060
00061 protected:
00062 QDomElement createElement(const QString& name, const QString& type = QString());
00063
00064 QDomDocument doc;
00065 QDomElement root;
00066 std::list<QDomElement> compound_stack;
00067
00068 #ifdef USE_HASH
00069 typedef std::unordered_map<reference_t, uint> ref_map_t;
00070 typedef std::unordered_map<QString, ref_map_t> ref_map_typed_t;
00071 #else
00072 typedef std::map<reference_t, uint> ref_map_t;
00073 typedef std::map<QString, ref_map_t> ref_map_typed_t;
00074 #endif
00075
00076 ref_map_typed_t typed_references_map;
00077
00078 bool write_type;
00079
00080 QString _filename;
00081 };
00082
00087 class VVEStorage_XMLReader : public VVEStorage
00088 {
00089 public:
00091 typedef ptrdiff_t reference_t;
00092
00093 VVEStorage_XMLReader();
00094 virtual ~VVEStorage_XMLReader();
00095
00096 virtual bool setOption(int option, int value);
00097
00101 virtual bool serialize(const QString& filename, Model* model);
00102
00103 virtual bool startCompound(const QString& name);
00104 virtual bool endCompound();
00105
00106 virtual int startReference(const QString& name, const QString& ref_type, reference_t ref);
00107 virtual bool endReference();
00108
00109 virtual bool reader() { return true; }
00110 virtual bool writer() { return false; }
00111
00112 #define DEF_FIELD(T) virtual bool field(const QString& name, T& value);
00113 FOR_ALL_TYPES(DEF_FIELD)
00114 #undef DEF_FIELD
00115
00116 virtual bool checkNextField(const QString& name);
00117
00118 virtual void setLastError(int error, const QString& err);
00119
00120 virtual QString filename() const { return _filename; }
00121
00122 protected:
00123 template <typename T>
00124 bool get_field(const QString& name, T& result);
00125
00126 template <typename From, typename To>
00127 bool extract_value_with_error(QDomElement element, To& result);
00128
00129 bool validType(QDomElement element, TYPES type);
00130 QDomElement extractElement(const QString& name);
00131 void setError_novalue(const QString& name);
00132 void setError_invalid_value(const QString& name, const QString& type, const QString& value);
00133 void setError_invalid_conversion(const QString& name, const QString& value, const QString& type_from, const QString& type_to);
00134
00135 QDomDocument doc;
00136 QDomElement root;
00137 std::list<QDomElement> compound_stack;
00138
00139 int type_checking;
00140
00141 QString _filename;
00142 };
00143 }
00144
00145 #endif // VVELIB_STORAGE_STORAGE_XML_H
00146