record.h

Go to the documentation of this file.
00001 /* Data records.
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_RECORD_H
00025 #define DATABASES_RECORD_H
00026 
00027 /*************************************************************************/
00028     
00029 namespace databases
00030 {
00031 
00032 /*************************************************************************/
00033 
00034 class Collection;
00035 class Field;
00036 
00037 /*************************************************************************/
00038 
00040 
00050 class Record
00051 {
00052     public:
00054         typedef uint32_t identifier_type;
00055         
00057         static inline identifier_type strtori(char const *nptr, char **endptr,
00058                 int base) { return strtoul(nptr, endptr, base); }
00059 
00061 #       define RECORD_FORMAT "%u"
00062         
00064         Record() : m_id(0), m_db_status(0) { }
00066         explicit Record(identifier_type id) : m_id(id), m_db_status(0) { }
00068         Record(Record const &r) : m_id(0), m_db_status(r.m_db_status) { }
00070         Record &operator=(Record const &right);
00072         virtual ~Record() { }
00073         
00075         bool operator==(identifier_type id) { return (m_id == id); }
00076         
00078 
00095         virtual void begin_update();
00096         
00098 
00104         virtual char const *get_s(Field const *field) const { return NULL; }
00105         
00107 
00118         virtual char const *set_s(Field const *field, char const *value)
00119                 { return value; }
00120         
00122 
00128         virtual int32_t get_i(Field const *field) const { return 0; }
00129         
00131 
00142         virtual int32_t set_i(Field const *field, int32_t value)
00143                 { return value; }
00144         
00146 
00152         virtual uint32_t get_ui(Field const *field) const { return 0; }
00153         
00155 
00166         virtual uint32_t set_ui(Field const *field, uint32_t value)
00167                 { return value; }
00168         
00170 
00176         virtual time_t get_ut(Field const *field) const { return 0; }
00177         
00179 
00190         virtual time_t set_ut(Field const *field, time_t value)
00191                 { return value; }
00192         
00194 
00200         virtual identifier_type get_ri(Field const *field) const { return 0; }
00201         
00203 
00214         virtual identifier_type set_ri(Field const *field,
00215                 identifier_type value) { return value; }
00216         
00218 
00230         virtual bool end_update();
00231         
00233 
00245         virtual bool owned(Collection const *coll, Record const *record)
00246                 { return false; }
00247         
00249 
00254         virtual size_t memory_usage() const { return 0; }
00255         
00257         identifier_type id() const { return m_id; }
00259 
00264         identifier_type id(identifier_type id);
00265         
00267         enum
00268         {
00270             dbsUpdating = 0x0001,
00272             dbsUpdateError = 0x0002,
00274             dbsMember = 0x0004,
00276             dbsInsert = 0x0008
00277         };
00278         
00280         uint16_t db_status() const { return m_db_status; }
00282 
00286         uint16_t db_status_add(uint16_t flags)
00287                 { return (m_db_status |= flags); }
00289 
00293         uint16_t db_status_remove(uint16_t flags)
00294                 { return (m_db_status &= ~flags); }
00295     protected:
00297         identifier_type m_id;
00299         uint16_t m_db_status;
00300 };
00301 
00302 /*************************************************************************/
00303 
00305 
00312 class NameRecord : public Record
00313 {
00314     public:
00316         NameRecord() : Record() { }
00318         explicit NameRecord(identifier_type id) : Record(id) { }
00319         
00321 
00328         virtual bool operator==(char const *name)
00329                 { return !strcasecmp(this->name(), name); }
00330         
00332 
00341         virtual bool matches(char const *pattern);
00342         
00344         virtual char const *name() const = 0;
00345     protected:
00346 };
00347 
00348 /*************************************************************************/
00349 
00350 } /* namespace databases */
00351 
00352 /*************************************************************************/
00353 
00354 #endif /* DATABASES_RECORD_H */

Generated on Sun May 20 21:32:14 2007 for Epona API by  doxygen 1.4.6