00001 //------------------------------------------------------------------------------ 00002 #ifndef d_Ref_h 00003 #define d_Ref_h 1 00004 //------------------------------------------------------------------------------ 00005 00006 #include "d_Ref_Any.h" 00007 //------------------------------------------------------------------------------ 00008 00009 /** 00010 * Expresses relationships to objects. 00011 * 00012 * You had to use this class for referencing persistent objects rather than C++ 00013 * pointers. It's implemented as a template class. The user must specify the 00014 * persistent class (derived from d_Object class) of the relationship as 00015 * template-argoument. Being a template class there is no need to cast the 00016 * result to own class. 00017 * 00018 * It can be used as attribute of a class for 1 to 1 relationship between 00019 * objects of the same or different class. 00020 * 00021 * If it's used as template-argoument of a class container in a class attribute 00022 * can express 1 to N relationships. 00023 * 00024 * LOCATION: 00025 * d_Ref.h 00026 * 00027 * Usage: 00028 * d_Ref< <linked-class> > <property-name>; 00029 * 00030 * WHERE: 00031 * 00032 * <linked-class>: Name of class to link. Can be only a persistent class 00033 * (inherited from d_Object) 00034 * 00035 * <property-name>: name of property 00036 * 00037 * EXAMPLES: 00038 * class Invoice : public d_Object 00039 * { 00040 * * Relationship 1-1 to customer object 00041 * d_Ref<Customer> customer; 00042 * 00043 * * Relationship 1-N to product objects 00044 * d_Set< d_Ref<Product> > products; 00045 * }; 00046 * 00047 * * Reference to Invoice object 00048 * d_Ref<Invoice> myInvoice; 00049 * 00050 * SEE ALSO: 00051 * d_Ref_Any, d_Object 00052 * 00053 * ODMG: 00054 * Compliant 00055 */ 00056 00057 template <class T> 00058 class _ODLL d_Ref : public d_Ref_Any 00059 { 00060 public: 00061 /** 00062 * Default constructor. 00063 * 00064 * Creates a null reference. 00065 * 00066 * ODMG : Compliant 00067 */ 00068 d_Ref(); 00069 00070 /** 00071 * Creates a reference to <iObject> object. 00072 * 00073 * ODMG : Compliant 00074 */ 00075 d_Ref( const T* iObject ); 00076 00077 /** 00078 * Copy constructor. 00079 * 00080 * Copy the reference of <iRef>. 00081 * 00082 * ODMG : Compliant 00083 */ 00084 d_Ref( const d_Ref<T>& iRef ); 00085 00086 /** 00087 * Creates a reference by the d_Ref_Any object <iRef>. 00088 * 00089 * ODMG : Compliant 00090 */ 00091 d_Ref( const d_Ref_Any& iRef ); 00092 00093 /** 00094 * Set the reference to <iSource> object. 00095 * 00096 * ODMG : Compliant 00097 */ 00098 d_Ref<T>& operator =( const T* iSource ); 00099 00100 /** 00101 * Returns the persistent object in memory. 00102 * 00103 * If the object is not present in memory Orient ODBMS loads the object 00104 * from database to memory trasparently. 00105 * 00106 * If the reference is null then an exception d_Error_RefNull or 00107 * d_Error_RefInvalid is raised. 00108 * 00109 * This operator permits to handle d_Ref<> as common C++ pointer. 00110 * 00111 * SEE ALSO: operator *(), ptr() 00112 * ODMG : Compliant 00113 */ 00114 T* operator -> (); 00115 00116 /** 00117 * Returns the persistent object in memory. 00118 * 00119 * If the object is not present in memory Orient ODBMS loads the object 00120 * from storage to memory trasparently. 00121 * 00122 * If the reference is null then an exception d_Error_RefNull or 00123 * d_Error_RefInvalid is raised. 00124 * 00125 * SEE ALSO: operator ->(), ptr() 00126 * ODMG : Compliant 00127 */ 00128 T & operator * (); 00129 00130 /** 00131 * Returns the persistent object in memory. 00132 * 00133 * If the object is not present in memory Orient ODBMS loads the object 00134 * from storage to memory trasparently. 00135 * 00136 * If the reference is null then an exception d_Error_RefInvalid is 00137 * raised. 00138 * 00139 * SEE ALSO: operator ->(), operator *() 00140 * ODMG : Compliant 00141 */ 00142 T * ptr (); 00143 00144 /** 00145 * Force loading of object in memory. 00146 * 00147 * If the object is not present in memory Orient ODBMS loads the object 00148 * from storage to memory. 00149 * 00150 * If the reference is null then an exception d_Error_RefInvalid is 00151 * raised. 00152 * 00153 * SEE ALSO: operator ->(), operator *(), ptr() 00154 * ODMG : Extension 00155 */ 00156 void load (); 00157 }; 00158 //------------------------------------------------------------------------------ 00159 00160 #include "d_Ref.cti" 00161 //------------------------------------------------------------------------------ 00162 //------------------------------------------------------------------------------ 00163 00164 #endif 00165
1.3-rc1