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 00014 BEGIN_FASTDB_NAMESPACE 00015 00019 class FASTDB_DLL_ENTRY dbAnyReference { 00020 friend class dbAnyCursor; 00021 friend class dbDatabase; 00022 friend class dbFieldDescriptor; 00023 protected: 00024 oid_t oid; 00025 00026 public: 00027 dbAnyReference(oid_t oid = 0) { 00028 this->oid = oid; 00029 } 00034 oid_t getOid() const { 00035 return oid; 00036 } 00037 00041 friend bool isNull(dbAnyReference const& ref) { 00042 return ref.oid == 0; 00043 } 00044 00048 bool isNull() const { return oid == 0; } 00049 00050 dbFieldDescriptor* dbDescribeComponents(dbFieldDescriptor* fd) { 00051 fd->type = fd->appType = dbField::tpReference; 00052 fd->refTable = NULL; 00053 fd->dbsSize = fd->alignment = sizeof(oid_t); 00054 return NULL; 00055 } 00056 }; 00057 00061 class FASTDB_DLL_ENTRY dbNullReference {}; 00062 00066 extern FASTDB_DLL_ENTRY dbNullReference null; 00067 00068 #if (defined(_MSC_VER) && (_MSC_VER+0 < 1200 || _MSC_VER >= 1310)) || defined(__MWERKS__) 00069 // 00070 // Visual C++ prior to 5.0 version (with applied Service Pack 3) 00071 // didn't support lazy template instantiation. As far as VC has bug 00072 // with treating local function prototypes, we have to use friend function. 00073 // 00074 template<class T> 00075 extern dbTableDescriptor* dbGetTableDescriptor(T*); 00076 #endif 00077 00078 00082 template<class T> 00083 class dbReference : public dbAnyReference { 00084 public: 00088 dbFieldDescriptor* dbDescribeComponents(dbFieldDescriptor* fd) { 00089 fd->type = fd->appType = dbField::tpReference; 00090 #if defined(_MSC_VER) && (_MSC_VER+0 < 1200 || _MSC_VER >= 1310) || defined(__MWERKS__) 00091 fd->refTable = dbGetTableDescriptor((T*)0); 00092 #else 00093 #if GNUC_BEFORE(2,96) || defined(__VACPP_MULTI__) || defined(__IBMCPP__) 00094 extern dbTableDescriptor* dbGetTableDescriptor(T*); 00095 fd->refTable = dbGetTableDescriptor((T*)0); 00096 #else 00097 fd->refTable = &T::dbDescriptor; 00098 #endif 00099 #endif 00100 fd->dbsSize = fd->alignment = sizeof(oid_t); 00101 return NULL; 00102 } 00103 00109 dbReference& operator = (dbReference const& ref) { 00110 oid = ref.oid; 00111 return *this; 00112 } 00113 00118 dbReference& operator = (dbNullReference const&) { 00119 oid = 0; 00120 return *this; 00121 } 00122 00128 dbReference<T>& unsafeAssign(dbAnyReference const& ref) { 00129 oid = ref.getOid(); 00130 return *this; 00131 } 00132 00136 bool operator == (dbReference const& ref) const { 00137 return oid == ref.oid; 00138 } 00139 00143 bool operator != (dbReference const& ref) const { 00144 return oid != ref.oid; 00145 } 00146 00150 bool operator == (dbNullReference const&) const { 00151 return oid == 0; 00152 } 00153 00157 bool operator != (dbNullReference const&) const { 00158 return oid != 0; 00159 } 00160 00164 dbReference(dbNullReference const&) : dbAnyReference(0) {} 00165 00169 dbReference(dbReference const& ref) : dbAnyReference(ref.oid) {} 00170 00177 dbReference(oid_t oid=0) : dbAnyReference(oid) {} 00178 }; 00179 00180 END_FASTDB_NAMESPACE 00181 00182 #endif 00183 00184 00185 00186 00187