Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

tRef.h

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /* POLiTe - Persistent Object Library Test                                    */
00004 /*                                        Ph.D. Thesis by Mgr. Michal Kopecky */
00005 /*                                                                            */
00006 /* Charles University Prague                                                  */
00007 /*                                                                            */
00008 /******************************************************************************/
00009 /*                                                                            */
00010 /* File name: ...                                                             */
00011 /* Module: ......                                                             */
00012 /*                                                                            */
00013 /******************************************************************************/
00014 
00015 #ifndef __T_REF_H__
00016 #define __T_REF_H__
00017 
00018 template<class T> class Ref;
00019 
00020 // Parent Header(s)
00021 #include <cRefBase.h>
00022 
00023 // Other POLiTe Header(s)
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         //Returns the pointer to the pointed object
00035         //which will be read from the database, if the object
00036         //is not present in memory yet.
00037         {
00038                 if (*this == DBNULL)
00039                         throw ObjLibException_NotFound();
00040                 return IsPersistent() ? (T *)ObjectCache.GetReferencedObject(*this) : (T *)_Object();
00041         };
00042 
00043         T &operator *()
00044         //Returns the pointed object
00045         //which will be read from the database, if the object
00046         //is not present in memory yet.
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                 // use temporary query result to find firts object matching the query
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                         // there is more than one object that match the condition
00084                         *this = DBNULL;
00085                 delete r;
00086         };
00087 
00088         Ref(
00089                 class Connection *aConnection,
00090                 const char *aQuery
00091                 )
00092                 : RefBase()
00093         {
00094                 // use temporary query result to find firts object matching the query
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                         // there is more than one object that match the condition
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__

Generated on Sun Jul 14 20:51:15 2002 for POLiTe by doxygen1.2.16