00001 //-< REFERENCE.H >---------------------------------------------------*--------* 00002 // GigaBASE Version 1.0 (c) 1999 GARRET * ? * 00003 // (Post Relational Database Management System) * /\| * 00004 // * / \ * 00005 // Created: 20-Nov-98 K.A. Knizhnik * / [] \ * 00006 // Last update: 10-Dec-98 K.A. Knizhnik * GARRET * 00007 //-------------------------------------------------------------------*--------* 00008 // Database table field reference type 00009 //-------------------------------------------------------------------*--------* 00010 00011 #ifndef __REFERENCE_H__ 00012 #define __REFERENCE_H__ 00013 00014 BEGIN_GIGABASE_NAMESPACE 00015 00019 class GIGABASE_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 00045 dbAnyReference& operator = (dbAnyReference const& ref) { 00046 oid = ref.oid; 00047 return *this; 00048 } 00049 00053 bool isNull() const { return oid == 0; } 00054 00055 dbFieldDescriptor* dbDescribeComponents(dbFieldDescriptor* fd) { 00056 fd->type = fd->appType = dbField::tpReference; 00057 fd->refTable = NULL; 00058 fd->dbsSize = fd->alignment = sizeof(oid_t); 00059 return NULL; 00060 } 00061 }; 00062 00066 class GIGABASE_DLL_ENTRY dbNullReference {}; 00067 00071 extern GIGABASE_DLL_ENTRY dbNullReference null; 00072 00073 #if (defined(_MSC_VER) && (_MSC_VER+0 < 1200 || _MSC_VER >= 1310)) || defined(__MWERKS__) 00074 // 00075 // Visual C++ prior to 5.0 version (with applied Service Pack 3) 00076 // didn't support lazy template instantiation. As far as VC has bug 00077 // with treating local function prototypes, we have to use friend function. 00078 // 00079 template<class T> 00080 extern dbTableDescriptor* dbGetTableDescriptor(T*); 00081 #endif 00082 00083 00087 template<class T> 00088 class dbReference : public dbAnyReference { 00089 public: 00090 dbFieldDescriptor* dbDescribeComponents(dbFieldDescriptor* fd) { 00091 fd->type = fd->appType = dbField::tpReference; 00092 #if defined(_MSC_VER) && (_MSC_VER+0 < 1200 || _MSC_VER >= 1310) || defined(__MWERKS__) 00093 fd->refTable = dbGetTableDescriptor((T*)0); 00094 #else 00095 #if GNUC_BEFORE(2,96) || defined(__VACPP_MULTI__) || defined(__IBMCPP__) || defined(HPUX_ITANIUM64) 00096 extern dbTableDescriptor* dbGetTableDescriptor(T*); 00097 fd->refTable = dbGetTableDescriptor((T*)0); 00098 #else 00099 fd->refTable = &T::dbDescriptor; 00100 #endif 00101 #endif 00102 fd->dbsSize = fd->alignment = sizeof(oid_t); 00103 return NULL; 00104 } 00105 00106 00112 dbReference<T>& operator = (dbReference<T> const& ref) { 00113 oid = ref.oid; 00114 return *this; 00115 } 00116 00121 dbReference<T>& operator = (dbNullReference const&) { 00122 oid = 0; 00123 return *this; 00124 } 00125 00131 dbReference<T>& unsafeAssign(dbAnyReference const& ref) { 00132 oid = ref.getOid(); 00133 return *this; 00134 } 00135 00139 bool operator == (dbReference<T> const& ref) const { 00140 return oid == ref.oid; 00141 } 00142 00146 bool operator != (dbReference<T> const& ref) const { 00147 return oid != ref.oid; 00148 } 00149 00153 bool operator == (dbNullReference const&) const { 00154 return oid == 0; 00155 } 00156 00160 bool operator != (dbNullReference const&) const { 00161 return oid != 0; 00162 } 00163 00167 dbReference(dbNullReference const&) : dbAnyReference(0) {} 00168 00172 dbReference(dbReference<T> const& ref) : dbAnyReference(ref.oid) {} 00173 00180 dbReference(oid_t oid=0) : dbAnyReference(oid) {} 00181 }; 00182 00183 END_GIGABASE_NAMESPACE 00184 00185 #endif 00186 00187 00188 00189 00190