00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024 #ifndef DATABASES_DATABASE_H
00025 #define DATABASES_DATABASE_H
00026
00027
00028
00029 #include <list>
00030 #include <string>
00031 #include <vector>
00032
00033 #include <databases/record.h>
00034 #include <modules/interface.h>
00035
00036
00037
00038 namespace modules { class Core; }
00039
00040
00041
00042 namespace databases
00043 {
00044
00045
00046
00047 class Collection;
00048 class Field;
00049
00050
00051
00053
00087 class Database : public modules::Interface
00088 {
00089 public:
00090
00091
00093 typedef std::list<Database *> container_type;
00095 typedef container_type::const_iterator const_iterator;
00097 typedef container_type::const_reverse_iterator const_reverse_iterator;
00098
00100 typedef std::vector<Field *> fields_type;
00101
00102
00103
00105 static modules::PSIID const IID = 0x42d05105;
00106
00107
00108
00110
00115 static Database *find(std::string const &name);
00116
00118 static const_iterator begin() { return g_list.begin(); }
00120 static const_iterator end() { return g_list.end(); }
00121
00123 static const_reverse_iterator rbegin() { return g_list.rbegin(); }
00125 static const_reverse_iterator rend() { return g_list.rend(); }
00126
00127
00128
00130
00133 explicit Database(modules::Core &core) :
00134 m_core(&core), m_coll(0), m_name(), m_impver(0),
00135 m_expver(0), m_minver(0), m_maxver(0), m_perms(0),
00136 m_fields(), m_expfields(), m_impfields(), m_status(0) { }
00138 virtual ~Database();
00139
00141
00155 bool start();
00156
00158
00168 virtual bool insert(Record const *record);
00169
00171
00183 virtual bool update_s(Record const *record, Field const *field,
00184 char const *value);
00185
00187
00199 virtual bool update_i(Record const *record, Field const *field,
00200 int32_t value);
00201
00203
00215 virtual bool update_ui(Record const *record, Field const *field,
00216 uint32_t value);
00217
00219
00231 virtual bool update_ut(Record const *record, Field const *field,
00232 time_t value);
00233
00235
00247 virtual bool update_ri(Record const *record, Field const *field,
00248 Record::identifier_type value);
00249
00251
00273 virtual bool update_multi(Record const *record,
00274 unsigned int valcount, va_list args);
00275
00277
00289 virtual bool update_owned(Field const *field,
00290 Record::identifier_type id, Record::identifier_type new_id);
00291
00293
00303 virtual bool delete_(Record const *record);
00304
00306
00317 virtual bool delete_owned(Field const *field,
00318 Record::identifier_type id);
00319
00321
00330 virtual bool truncate();
00331
00333 Collection *coll() { return m_coll; }
00335
00342 Collection *coll(Collection *coll);
00343
00345 std::string const &name() const { return m_name; }
00347
00356 std::string const &name(std::string const &name);
00357
00359 enum
00360 {
00362 vtImport = 1,
00364 vtExport = 2,
00366 vtMinimum = 3,
00368 vtMaximum = 4
00369 };
00370
00372
00405 uint16_t version(int type) const;
00406
00408
00418 uint16_t version(int type, uint16_t ver);
00419
00421 enum
00422 {
00424 dpInitial = 0x0001,
00426 dpCreate = 0x0002,
00428 dpUpdate = 0x0004,
00430 dpDelete = 0x0008,
00432 dpExport = 0x0010,
00433
00435 dpImport = dpCreate | dpUpdate | dpDelete
00436 };
00437
00439 uint16_t perms() const { return m_perms; }
00441
00469 uint16_t perms_add(uint16_t perms);
00471
00480 uint16_t perms_remove(uint16_t perms);
00481
00483
00507 virtual Field *field_create(char const *name, uint16_t minver,
00508 uint16_t type, size_t size, uint16_t attrs, char const *def,
00509 uint16_t tag = 0);
00510
00512
00523 virtual bool field_add(Field *field);
00524
00526
00543 Field *field_find(char const *name, int restrict = 0);
00544
00546
00555 virtual bool readable() const { return true; }
00556
00558
00569 virtual bool writable() const;
00570
00572 enum
00573 {
00575 dsRegistered = 0x0001,
00577 dsStarted = 0x0002,
00579 dsInitial = 0x0004
00580 };
00581
00583 uint16_t status() const { return m_status; }
00584 protected:
00586 modules::Core *m_core;
00588 Collection *m_coll;
00589
00591 std::string m_name;
00592
00594 uint16_t m_impver;
00596 uint16_t m_expver;
00598 uint16_t m_minver;
00600 uint16_t m_maxver;
00601
00603 uint16_t m_perms;
00604
00606 fields_type m_fields;
00608 fields_type m_expfields;
00610 fields_type m_impfields;
00611
00613 uint16_t m_status;
00614
00616
00622 virtual void generate_expfields();
00623
00625
00637 virtual void generate_impfields();
00638
00640
00648 virtual bool reg();
00649
00651
00659 virtual bool start_real() = 0;
00660 private:
00661 static container_type g_list;
00662
00663 Database(Database const &);
00664 Database &operator=(Database const &);
00665 };
00666
00667
00668
00670
00677 class DBRemove : public modules::ErrorInterface
00678 {
00679 public:
00681 static modules::PSIID const iid = 0x43f0f5f3;
00682
00684
00689 virtual bool remove(std::string const &database) = 0;
00690
00692
00695 virtual bool clear() = 0;
00696 private:
00697 };
00698
00699
00700
00701 }
00702
00703
00704
00705 #endif