00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024 #ifndef DATABASES_XML_H
00025 #define DATABASES_XML_H
00026
00027
00028
00029 #include <string>
00030 #include <vector>
00031
00032 #include <tinyxml/tinyxml.h>
00033
00034 #include <databases/record.h>
00035 #include <modules/interface.h>
00036
00037
00038
00039 namespace databases
00040 {
00041
00042
00043
00044 class XMLIndex;
00045
00046
00047
00049
00058 class XMLExport : public modules::ErrorInterface
00059 {
00060 public:
00062 static modules::PSIID const IID = 0x42e2ed91;
00063
00065
00085 virtual bool export_data(std::string const &dir,
00086 XMLIndex &index, std::string const &database = "") = 0;
00087 private:
00088 };
00089
00090
00091
00093
00102 class XMLImport : public modules::ErrorInterface
00103 {
00104 public:
00106 static modules::PSIID const IID = 0x42e3f23f;
00107
00109
00124 virtual bool import_data(std::string const &dir,
00125 std::string const &database) = 0;
00126 private:
00127 };
00128
00129
00130
00132
00135 class XMLIndex
00136 {
00137 public:
00138
00139
00141 typedef std::vector<std::string> container_type;
00143 typedef container_type::const_iterator const_iterator;
00145 typedef container_type::const_reverse_iterator const_reverse_iterator;
00146
00147
00148
00150 XMLIndex() : m_files(), m_error() { }
00152 XMLIndex(XMLIndex const &xi) : m_files(xi.m_files), m_error(xi.m_error) { }
00154 XMLIndex &operator=(XMLIndex const &right);
00155
00157
00162 bool load(std::string const &filename);
00163
00165
00170 bool save(std::string const &filename);
00171
00173
00179 bool add(std::string const &filename);
00180
00182
00186 bool remove(std::string const &filename);
00187
00189
00192 void clear();
00193
00195
00199 bool exists(std::string const &filename) const;
00200
00202 const_iterator begin() const { return m_files.begin(); }
00204 const_iterator end() const { return m_files.end(); }
00205
00207 const_reverse_iterator rbegin() const { return m_files.rbegin(); }
00209 const_reverse_iterator rend() const { return m_files.rend(); }
00210
00212 bool empty() const { return m_files.empty(); }
00214 container_type::size_type size() const { return m_files.size(); }
00215
00217 std::string const &error() const { return m_error; }
00218 private:
00219 container_type m_files;
00220 std::string m_error;
00221 };
00222
00223
00224
00226
00234 class XMLReader
00235 {
00236 public:
00237
00238
00240
00243 class Callback
00244 {
00245 public:
00247 virtual ~Callback() { }
00248
00250
00255 virtual bool database(uint16_t version) = 0;
00256
00258
00268 virtual bool add_field(char const *name, uint16_t type,
00269 size_t size, uint16_t attrs, char const *defval) = 0;
00270
00272
00276 virtual bool count(uint32_t count) = 0;
00277
00279
00284 virtual bool begin_record() = 0;
00285
00287
00292 virtual bool add_value(char const *field,
00293 char const *value) = 0;
00294
00296 virtual bool add_ivalue(char const *field, int32_t value) = 0;
00298 virtual bool add_uivalue(char const *field,
00299 uint32_t value) = 0;
00301 virtual bool add_utvalue(char const *field, time_t value) = 0;
00303 virtual bool add_rivalue(char const *field,
00304 Record::identifier_type value) = 0;
00305
00307
00310 virtual bool end_record() = 0;
00311 };
00312
00313
00314
00316 XMLReader() : m_error() { }
00318 XMLReader(XMLReader const &xr) : m_error() { }
00320 XMLReader &operator=(XMLReader const &right);
00321
00323
00330 bool load(std::string const &filename, Callback &cb);
00331
00333 char const *error() const { return m_error.c_str(); }
00334 private:
00335 std::string m_error;
00336 };
00337
00338
00339
00341
00347 class XMLWriter
00348 {
00349 public:
00351 XMLWriter() : m_doc(), m_header("header"), m_data("data"),
00352 m_record(0) { }
00354 XMLWriter(XMLWriter const &xw) : m_doc(xw.m_doc),
00355 m_header(xw.m_header), m_data(xw.m_data),
00356 m_record(xw.m_record ? new TiXmlElement(*xw.m_record) : 0) { }
00358 XMLWriter &operator=(XMLWriter const &right);
00360 ~XMLWriter();
00361
00363
00368 bool database(uint16_t version);
00369
00371
00380 bool add_field(char const *name, uint16_t type, size_t size,
00381 uint16_t attrs, char const *defval);
00382
00384
00388 bool count(uint32_t count);
00389
00391
00396 bool begin_record();
00397
00399
00404 bool add_value(char const *field, char const *value);
00405
00407 bool add_ivalue(char const *field, int32_t value);
00409 bool add_uivalue(char const *field, uint32_t value);
00411 bool add_utvalue(char const *field, time_t value);
00413 bool add_rivalue(char const *field, Record::identifier_type value);
00414
00416
00421 bool end_record();
00422
00424
00427 void dump_record();
00428
00430
00435 bool save(std::string const &filename);
00436
00438 char const *error() const { return m_doc.ErrorDesc(); }
00439 private:
00440 TiXmlDocument m_doc;
00441 TiXmlElement m_header;
00442 TiXmlElement m_data;
00443 TiXmlElement *m_record;
00444 };
00445
00446
00447
00448 }
00449
00450
00451
00452 #endif