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 uint32_t const max_id = 0xFFFFFFFF;
00058         
00060         static inline identifier_type strtori(char const *nptr, char **endptr,
00061                 int base) { return strtoul(nptr, endptr, base); }
00062 
00064 #       define RECORD_FORMAT "%u"
00065         
00067         Record() : m_id(0), m_db_status(0) { }
00069         explicit Record(identifier_type id) : m_id(id), m_db_status(0) { }
00071         Record(Record const &r) : m_id(0), m_db_status(r.m_db_status) { }
00073         Record &operator=(Record const &right);
00075         virtual ~Record() { }
00076         
00078         bool operator==(identifier_type id) { return (m_id == id); }
00079         
00081 
00098         virtual void begin_update();
00099         
00101 
00107         virtual char const *get_s(Field const *field) const { return NULL; }
00108         
00110 
00121         virtual char const *set_s(Field const *field, char const *value)
00122                 { return value; }
00123         
00125 
00131         virtual int32_t get_i(Field const *field) const { return 0; }
00132         
00134 
00145         virtual int32_t set_i(Field const *field, int32_t value)
00146                 { return value; }
00147         
00149 
00155         virtual uint32_t get_ui(Field const *field) const { return 0; }
00156         
00158 
00169         virtual uint32_t set_ui(Field const *field, uint32_t value)
00170                 { return value; }
00171         
00173 
00179         virtual time_t get_ut(Field const *field) const { return 0; }
00180         
00182 
00193         virtual time_t set_ut(Field const *field, time_t value)
00194                 { return value; }
00195         
00197 
00203         virtual identifier_type get_ri(Field const *field) const { return 0; }
00204         
00206 
00217         virtual identifier_type set_ri(Field const *field,
00218                 identifier_type value) { return value; }
00219         
00221 
00233         virtual bool end_update();
00234         
00236 
00248         virtual bool owned(Collection const *coll, Record const *record)
00249                 { return false; }
00250         
00252 
00257         virtual size_t memory_usage() const { return 0; }
00258         
00260         identifier_type id() const { return m_id; }
00262 
00267         identifier_type id(identifier_type id);
00268         
00270         enum
00271         {
00273             dbsUpdating = 0x0001,
00275             dbsUpdateError = 0x0002,
00277             dbsMember = 0x0004,
00279             dbsInsert = 0x0008
00280         };
00281         
00283         uint16_t db_status() const { return m_db_status; }
00285 
00289         uint16_t db_status_add(uint16_t flags)
00290                 { return (m_db_status |= flags); }
00292 
00296         uint16_t db_status_remove(uint16_t flags)
00297                 { return (m_db_status &= ~flags); }
00298     protected:
00300         identifier_type m_id;
00302         uint16_t m_db_status;
00303 };
00304 
00305 /*************************************************************************/
00306 
00308 
00315 class NameRecord : public Record
00316 {
00317     public:
00319         NameRecord() : Record() { }
00321         explicit NameRecord(identifier_type id) : Record(id) { }
00322         
00324 
00331         virtual bool operator==(char const *name) const
00332                 { return !strcasecmp(this->name(), name); }
00333         
00335 
00344         virtual bool matches(char const *pattern) const;
00345         
00347         virtual char const *name() const = 0;
00348     protected:
00349 };
00350 
00351 /*************************************************************************/
00352 
00353 } /* namespace databases */
00354 
00355 /*************************************************************************/
00356 
00357 #endif /* DATABASES_RECORD_H */

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