00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __T_REF_H__
00016 #define __T_REF_H__
00017
00018 template<class T> class Ref;
00019
00020
00021 #include <cRefBase.h>
00022
00023
00024 #include <cObjectBuffer.h>
00025
00026 template<class T> class Ref : public RefBase
00027 {
00028 #ifdef POLITE_TEST_FRIEND
00029 friend POLITE_TEST_FRIEND;
00030 #endif // POLITE_TEST_FRIEND
00031
00032 public:
00033 T *operator ->()
00034
00035
00036
00037 {
00038 if (*this == DBNULL)
00039 throw ObjLibException_NotFound();
00040 return IsPersistent() ? (T *)ObjectCache.GetReferencedObject(*this) : (T *)_Object();
00041 };
00042
00043 T &operator *()
00044
00045
00046
00047 {
00048 if (*this == DBNULL)
00049 throw ObjLibException_NotFound();
00050 return IsPersistent() ? *(T *)ObjectCache.GetReferencedObject(*this) : *(T *)_Object();
00051 };
00052
00053 Ref(): RefBase() {};
00054
00055 Ref(const RefBase &Dbp): RefBase(Dbp) {};
00056
00057 Ref(const Object * const DbObj): RefBase(DbObj) {};
00058
00059 Ref(
00060 class Connection *aConnection,
00061 class ProtoBase *aPrototype,
00062 char *aSelectKeyValues,
00063 unsigned short aStrategies
00064 )
00065 : RefBase(aConnection, aPrototype, aSelectKeyValues, aStrategies) {};
00066
00067 Ref(
00068 class Connection *aConnection,
00069 const long anOid
00070 )
00071 : RefBase(aConnection, anOid, Class[T::ClassName()]) {};
00072
00073 Ref(
00074 class Connection *aConnection,
00075 const QueRefProto &aQuery
00076 )
00077 : RefBase()
00078 {
00079
00080 Result<T> *r = (Result<T> *)(Class[T::ClassName()]->ExecuteQuery(aQuery,aConnection,1,new Result<T>));
00081 *this = ++(*r);
00082 if (((*r)!=DBNULL) && (++(*r)!=DBNULL))
00083
00084 *this = DBNULL;
00085 delete r;
00086 };
00087
00088 Ref(
00089 class Connection *aConnection,
00090 const char *aQuery
00091 )
00092 : RefBase()
00093 {
00094
00095 Result<T> *r = (Result<T> *)(Class[T::ClassName()]->ExecuteQuery(Query(aQuery),aConnection,1,new Result<T>));
00096 *this = ++(*r);
00097 if (((*r)!=DBNULL) && (++(*r)!=DBNULL))
00098
00099 *this = DBNULL;
00100 delete r;
00101 };
00102
00103 Ref<T> &operator = (const RefBase &Dbp)
00104 {
00105 return (Ref<T> &)this->RefBase::operator = (Dbp);
00106 };
00107
00108 Ref<T> &operator = (const T *Ptr)
00109 {
00110 return (Ref<T> &)this->RefBase::operator = (Ptr->Address());
00111 };
00112 };
00113
00114 #endif //__T_REF_H__