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
00173 virtual bool insert(Record *record);
00174
00176
00188 virtual bool update_s(Record const *record, Field const *field,
00189 char const *value);
00190
00192
00204 virtual bool update_i(Record const *record, Field const *field,
00205 int32_t value);
00206
00208
00220 virtual bool update_ui(Record const *record, Field const *field,
00221 uint32_t value);
00222
00224
00236 virtual bool update_ut(Record const *record, Field const *field,
00237 time_t value);
00238
00240
00252 virtual bool update_ri(Record const *record, Field const *field,
00253 Record::identifier_type value);
00254
00256
00278 virtual bool update_multi(Record const *record,
00279 unsigned int valcount, va_list args);
00280
00282
00294 virtual bool update_owned(Field const *field,
00295 Record::identifier_type id, Record::identifier_type new_id);
00296
00298
00308 virtual bool delete_(Record const *record);
00309
00311
00322 virtual bool delete_owned(Field const *field,
00323 Record::identifier_type id);
00324
00326
00335 virtual bool truncate();
00336
00338 Collection *coll() { return m_coll; }
00340
00347 Collection *coll(Collection *coll);
00348
00350 std::string const &name() const { return m_name; }
00352
00361 std::string const &name(std::string const &name);
00362
00364 enum
00365 {
00367 vtImport = 1,
00369 vtExport = 2,
00371 vtMinimum = 3,
00373 vtMaximum = 4
00374 };
00375
00377
00410 uint16_t version(int type) const;
00411
00413
00423 uint16_t version(int type, uint16_t ver);
00424
00426 enum
00427 {
00429 dpInitial = 0x0001,
00431 dpCreate = 0x0002,
00433 dpUpdate = 0x0004,
00435 dpDelete = 0x0008,
00437 dpExport = 0x0010,
00438
00440 dpImport = dpCreate | dpUpdate | dpDelete
00441 };
00442
00444 uint16_t perms() const { return m_perms; }
00446
00474 uint16_t perms_add(uint16_t perms);
00476
00485 uint16_t perms_remove(uint16_t perms);
00486
00488 static modules::PSIID const sIDGen = 0x469def8f;
00489
00491
00503 virtual modules::Interface *supports(modules::PSIID sid) { return 0; }
00504
00506
00530 virtual Field *field_create(char const *name, uint16_t minver,
00531 uint16_t type, size_t size, uint16_t attrs, char const *def,
00532 uint16_t tag = 0);
00533
00535
00546 virtual bool field_add(Field *field);
00547
00549
00566 Field *field_find(char const *name, int restrict = 0);
00567
00569
00578 virtual bool readable() const { return true; }
00579
00581
00592 virtual bool writable() const;
00593
00595 enum
00596 {
00598 dsRegistered = 0x0001,
00600 dsStarted = 0x0002,
00602 dsInitial = 0x0004
00603 };
00604
00606 uint16_t status() const { return m_status; }
00607 protected:
00609 modules::Core *m_core;
00611 Collection *m_coll;
00612
00614 std::string m_name;
00615
00617 uint16_t m_impver;
00619 uint16_t m_expver;
00621 uint16_t m_minver;
00623 uint16_t m_maxver;
00624
00626 uint16_t m_perms;
00627
00629 fields_type m_fields;
00631 fields_type m_expfields;
00633 fields_type m_impfields;
00634
00636 uint16_t m_status;
00637
00639
00645 virtual void generate_expfields();
00646
00648
00660 virtual void generate_impfields();
00661
00663
00671 virtual bool reg();
00672
00674
00682 virtual bool start_real() = 0;
00683 private:
00684 static container_type g_list;
00685
00686 Database(Database const &);
00687 Database &operator=(Database const &);
00688 };
00689
00690
00691
00693
00700 class DBRemove : public modules::ErrorInterface
00701 {
00702 public:
00704 static modules::PSIID const iid = 0x43f0f5f3;
00705
00707
00712 virtual bool remove(std::string const &database) = 0;
00713
00715
00718 virtual bool clear() = 0;
00719 private:
00720 };
00721
00722
00723
00724 }
00725
00726
00727
00728 #endif