Main Page   Class Hierarchy   Compound List   File List   Compound 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 
00052 class FASTDB_DLL_ENTRY dbNullReference {};
00053 
00057 extern FASTDB_DLL_ENTRY dbNullReference null;
00058 
00059 #if (defined(_MSC_VER) && _MSC_VER+0 <= 1100)
00060 //
00061 // Visual C++ prior to 5.0 version (with applied Service Pack 3)
00062 // didn't support lazy template instantiation. As far as VC has bug
00063 // with treating local function prototypes, we have to use friend function.
00064 //
00065 template<class T>
00066 extern dbTableDescriptor* dbGetTableDescriptor(T*);
00067 #endif
00068 
00069 
00073 template<class T>
00074 class dbReference : public dbAnyReference { 
00075   public:
00079     dbFieldDescriptor* dbDescribeComponents(dbFieldDescriptor* fd) { 
00080         fd->type = fd->appType = dbField::tpReference;
00081 #if defined(_MSC_VER) && _MSC_VER+0 <= 1100 
00082         fd->refTable = dbGetTableDescriptor((T*)0);
00083 #else
00084 #if defined(__GNUC__) && __GNUC_MINOR__ <= 95
00085         extern dbTableDescriptor* dbGetTableDescriptor(T*);
00086         fd->refTable = dbGetTableDescriptor((T*)0);
00087 #else
00088         fd->refTable = &T::dbDescriptor;
00089 #endif
00090 #endif
00091         fd->dbsSize = fd->alignment = sizeof(oid_t);
00092         return NULL;
00093     }
00094 
00100     dbReference& operator = (dbReference const& ref) { 
00101         oid = ref.oid;
00102         return *this;
00103     }
00104 
00109     dbReference& operator = (dbNullReference const&) { 
00110         oid = 0;
00111         return *this;
00112     }
00113 
00117     bool operator == (dbReference const& ref) const { 
00118         return oid == ref.oid; 
00119     }
00120 
00124     bool operator != (dbReference const& ref) const { 
00125         return oid != ref.oid; 
00126     }
00127 
00131     bool operator == (dbNullReference const&) const { 
00132         return oid == 0;
00133     }
00134 
00138     bool operator != (dbNullReference const&) const { 
00139         return oid != 0;
00140     }
00141 
00145     dbReference(dbNullReference const&) : dbAnyReference(0) {}
00146 
00150     dbReference(dbReference const& ref) : dbAnyReference(ref.oid) {}
00151     
00158     dbReference(oid_t oid=0) : dbAnyReference(oid) {}
00159 };
00160 
00161 #endif
00162 
00163 
00164 
00165 
00166 

Generated on Fri Nov 15 21:06:29 2002 for FastDB by doxygen1.2.15