database.h

Go to the documentation of this file.
00001 /* Database.
00002  *
00003  * PegSoft databases library (c) 2005 PegSoft
00004  * Contact us at pegsoft@pegsoft.net
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program (see the file COPYING); if not, write to the
00018  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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         /* Types */
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         /* Constants */
00103         
00105         static modules::PSIID const IID = 0x42d05105;
00106         
00107         /* Static functions */
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         /* Functions */
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,
00439             dpDelayed = 0x0020,
00440             
00442             dpImport = dpCreate | dpUpdate | dpDelete
00443         };
00444         
00446         uint16_t perms() const { return m_perms; }
00448 
00483         uint16_t perms_add(uint16_t perms);
00485 
00494         uint16_t perms_remove(uint16_t perms);
00495         
00497         static modules::PSIID const sIDGen = 0x469def8f;
00499         static modules::PSIID const sDelayed = 0x46ed1d6e;
00500         
00502 
00519         virtual modules::Interface *supports(modules::PSIID feature) { return 0; }
00520         
00522 
00546         virtual Field *field_create(char const *name, uint16_t minver,
00547                 uint16_t type, size_t size, uint16_t attrs, char const *def,
00548                 uint16_t tag = 0);
00549         
00551 
00562         virtual bool field_add(Field *field);
00563         
00565 
00582         Field *field_find(char const *name, int restrict = 0);
00583         
00585 
00594         virtual bool readable() const { return true; }
00595         
00597 
00608         virtual bool writable() const;
00609         
00611         enum
00612         {
00614             dsRegistered = 0x0001,
00616             dsStarted = 0x0002,
00618             dsInitial = 0x0004
00619         };
00620         
00622         uint16_t status() const { return m_status; }
00623     protected:
00625         modules::Core *m_core;
00627         Collection *m_coll;
00628     
00630         std::string m_name;
00631         
00633         uint16_t m_impver;
00635         uint16_t m_expver;
00637         uint16_t m_minver;
00639         uint16_t m_maxver;
00640         
00642         uint16_t m_perms;
00643         
00645         fields_type m_fields;
00647         fields_type m_expfields;
00649         fields_type m_impfields;
00650         
00652         uint16_t m_status;
00653         
00655 
00661         virtual void generate_expfields();
00662         
00664 
00676         virtual void generate_impfields();
00677         
00679 
00687         virtual bool reg();
00688         
00690 
00698         virtual bool start_real() = 0;
00699     private:
00700         static container_type g_list;
00701     
00702         Database(Database const &);
00703         Database &operator=(Database const &);
00704 };
00705 
00706 /*************************************************************************/
00707 
00709 
00716 class DBRemove : public modules::ErrorInterface
00717 {
00718     public:
00720         static modules::PSIID const iid = 0x43f0f5f3;
00721         
00723 
00728         virtual bool remove(std::string const &database) = 0;
00729         
00731 
00734         virtual bool clear() = 0;
00735     private:
00736 };
00737 
00738 /*************************************************************************/
00739 
00740 } /* namespace databases */
00741 
00742 /*************************************************************************/
00743 
00744 #endif /* DATABASES_DATABASE_H */

Generated on Fri Apr 18 22:03:27 2008 for Epona API by  doxygen 1.5.3