Main Page | Class Hierarchy | Class List | File List | Class Members

reference.h

00001 //-< REFERENCE.H >---------------------------------------------------*--------*
00002 // FastDB                    Version 1.0         (c) 1999  GARRET    *     ?  *
00003 // (Main Memory Database Management System)                          *   /\|  *
00004 //                                                                   *  /  \  *
00005 //                          Created:     20-Nov-98    K.A. Knizhnik  * / [] \ *
00006 //                          Last update: 15-Feb-99    K.A. Knizhnik  * GARRET *
00007 //-------------------------------------------------------------------*--------*
00008 // Database table field reference type
00009 //-------------------------------------------------------------------*--------*
00010 
00011 #ifndef __REFERENCE_H__
00012 #define __REFERENCE_H__
00013 
00017 class FASTDB_DLL_ENTRY dbAnyReference {  
00018     friend class dbAnyCursor;
00019     friend class dbDatabase;
00020     friend class dbFieldDescriptor;
00021   protected:
00022     oid_t       oid;
00023 
00024   public: 
00025     dbAnyReference(oid_t oid = 0) { 
00026         this->oid = oid;
00027     }
00032     oid_t getOid() const { 
00033         return oid;
00034     }
00035 
00039     friend bool isNull(dbAnyReference const& ref) { 
00040         return ref.oid == 0; 
00041     }
00042     
00046     bool isNull() const { return oid == 0; }
00047 
00048     dbFieldDescriptor* dbDescribeComponents(dbFieldDescriptor* fd) {
00049         fd->type = fd->appType = dbField::tpReference;
00050         fd->refTable = NULL;
00051         fd->dbsSize = fd->alignment = sizeof(oid_t);
00052         return NULL;
00053     }
00054 };
00055 
00059 class FASTDB_DLL_ENTRY dbNullReference {};
00060 
00064 extern FASTDB_DLL_ENTRY dbNullReference null;
00065 
00066 #if (defined(_MSC_VER) && _MSC_VER+0 <= 1100)
00067 //
00068 // Visual C++ prior to 5.0 version (with applied Service Pack 3)
00069 // didn't support lazy template instantiation. As far as VC has bug
00070 // with treating local function prototypes, we have to use friend function.
00071 //
00072 template<class T>
00073 extern dbTableDescriptor* dbGetTableDescriptor(T*);
00074 #endif
00075 
00076 
00080 template<class T>
00081 class dbReference : public dbAnyReference { 
00082   public:
00086     dbFieldDescriptor* dbDescribeComponents(dbFieldDescriptor* fd) { 
00087         fd->type = fd->appType = dbField::tpReference;
00088 #if defined(_MSC_VER) && _MSC_VER+0 <= 1100 
00089         fd->refTable = dbGetTableDescriptor((T*)0);
00090 #else
00091 #if defined(__GNUC__) && __GNUC_MINOR__ <= 95
00092         extern dbTableDescriptor* dbGetTableDescriptor(T*);
00093         fd->refTable = dbGetTableDescriptor((T*)0);
00094 #else
00095         fd->refTable = &T::dbDescriptor;
00096 #endif
00097 #endif
00098         fd->dbsSize = fd->alignment = sizeof(oid_t);
00099         return NULL;
00100     }
00101 
00107     dbReference& operator = (dbReference const& ref) { 
00108         oid = ref.oid;
00109         return *this;
00110     }
00111 
00116     dbReference& operator = (dbNullReference const&) { 
00117         oid = 0;
00118         return *this;
00119     }
00120 
00126     dbReference<T>& unsafeAssign(dbAnyReference const& ref) {
00127         oid = ref.getOid();
00128         return *this;
00129     }
00130  
00134     bool operator == (dbReference const& ref) const { 
00135         return oid == ref.oid; 
00136     }
00137 
00141     bool operator != (dbReference const& ref) const { 
00142         return oid != ref.oid; 
00143     }
00144 
00148     bool operator == (dbNullReference const&) const { 
00149         return oid == 0;
00150     }
00151 
00155     bool operator != (dbNullReference const&) const { 
00156         return oid != 0;
00157     }
00158 
00162     dbReference(dbNullReference const&) : dbAnyReference(0) {}
00163 
00167     dbReference(dbReference const& ref) : dbAnyReference(ref.oid) {}
00168     
00175     dbReference(oid_t oid=0) : dbAnyReference(oid) {}
00176 };
00177 
00178 #endif
00179 
00180 
00181 
00182 
00183 

Generated on Thu Feb 12 13:04:48 2004 for FastDB by doxygen 1.3.5