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

d_Ref_Any.h

Go to the documentation of this file.
00001 
00002 #ifndef d_Ref_Any_h
00003 #define d_Ref_Any_h 1
00004 
00005 //------------------------------------------------------------------------------
00006 #include "oPlatform.h"
00007 #include "cTypes.h"
00008 #include "cODMGLiteral.h"
00009 #include "oObjectId.h"
00010 
00011 //------------------------------------------------------------------------------
00012 class _ODLL d_Object;
00013 
00014 template< class T >
00015 class _ODLL d_Ref; 
00016 
00017 /**
00018  * Expresses relationships to objects.
00019  *
00020  * This class represents a generic reference to a persistent object. Use d_Ref
00021  * class for reference of knew type.
00022  * 
00023  * It can be used as attribute of a class for 1 to 1 relationship between
00024  * objects of the same or different class.
00025  * 
00026  * If it's used as template-argument of a class container in a class attribute
00027  * can express 1 to N relationships.
00028  *
00029  * LOCATION:
00030  * d_Ref_Any.h
00031  *
00032  * USAGE:
00033  * d_Ref_Any    <property-name>;
00034  * 
00035  * Where:
00036  * <PROPERTY-NAME>:     NAME OF PROPERTY
00037  *
00038  * EXAMPLES:
00039  * class Invoice : public d_Object
00040  * {
00041  *    * Relationship 1-1 to customer or supplier
00042  *   d_Ref_Any                  customer_or_supplier;
00043  * 
00044  *    * Relationship 1-N to product
00045  *   d_Set< d_Ref_Any > products;
00046  * };
00047  * 
00048  *  * Reference to Invoice object
00049  * d_Ref_Any<Invoice>   myInvoice;              
00050  *
00051  * SEE ALSO:
00052  * d_Ref, d_Object
00053  *
00054  * ODMG:
00055  * Compliant 
00056  */
00057 class _ODLL d_Ref_Any 
00058 {
00059   public:
00060     /**
00061      * Default constructor.
00062      *
00063      * Creates a null reference.
00064      *
00065      * ODMG    :  Compliant
00066      */
00067     d_Ref_Any ();
00068 
00069     /**
00070      * Creates a reference to <iObject> object.
00071      *
00072      * ODMG    :  Compliant 
00073      */
00074     d_Ref_Any (d_Object* iObject);
00075 
00076     /**
00077      * Copy constructor.
00078      *
00079      * Copy the reference of <iSource>.
00080      *
00081      * ODMG    :  Compliant 
00082      */
00083     d_Ref_Any (const d_Ref_Any& iSource);
00084 
00085     /**
00086      * Destructor.
00087      *
00088      * ODMG    :  Compliant 
00089      */
00090     ~d_Ref_Any();
00091 
00092 
00093     /**
00094      * Get a copy of the object <iSource>.
00095      *
00096      * ODMG    :  Compliant 
00097      */
00098     d_Ref_Any& operator =( const d_Ref_Any& iSource );
00099 
00100     /**
00101      * Get a reference for the object <iSource>.
00102      *
00103      * ODMG    :  Compliant 
00104      */
00105     d_Ref_Any& operator =( d_Object* iSource );
00106 
00107     /**
00108      * Check if two ref are equals (check the oid)
00109      *
00110      * ODMG    :  Extension
00111      */
00112     d_Boolean operator ==( const d_Ref_Any& iSource ) const;
00113 
00114 
00115     /**
00116      * Deletes permanently the object referred from memory and storage.
00117      *
00118      * ODMG    :  Compliant 
00119      */
00120     void delete_object ();
00121 
00122     // Internal.
00123     void free_object ();
00124 
00125     /**
00126      * Returns true is the reference has a null value otherwise false.
00127      * 
00128      * SEE ALSO:  is_null()
00129      * ODMG    :  Compliant 
00130      */
00131     d_Boolean operator ! () const;
00132 
00133     /**
00134      * Returns true is the reference has a null value otherwise false.
00135      * 
00136      * SEE ALSO:  operator !()
00137      * ODMG    :  Compliant 
00138      */
00139     d_Boolean is_null () const;
00140 
00141     /**
00142      * Clears the reference setting to null.
00143      *
00144      * ODMG    :  Compliant 
00145      */
00146     void clear ();
00147 
00148 
00149     // Internal.
00150     d_Ref_Any (const oObjectId& iSource);
00151 
00152     // Internal.
00153     bool check_for_oid();
00154 
00155     /**
00156      * Returns true is the reference is valid otherwise false.
00157      *
00158      * ODMG    :  Extension
00159      */
00160     bool is_valid () const;
00161 
00162     // Internal
00163     void setValid( bool iValid );
00164 
00165     /**
00166      * Returns true if the object referenced is already loaded in memory
00167      * otherwise false.
00168      * 
00169      * SEE ALSO:  d_Ref::operator -> (), d_Ref::ptr ()
00170      * ODMG    :  Extension
00171      */
00172     bool is_loaded () const;
00173 
00174     // Internal.
00175     void refresh();
00176 
00177     // Internal.
00178     const char* dump ();
00179 
00180     // Internal.
00181     void setOid (oUInt1 iDatabase, oUInt2 iClass, oUInt4 iRecord);
00182 
00183     // Internal.
00184     oObjectId& getOid ();
00185 
00186     // Internal.
00187     d_Object* getObject () const;
00188 
00189     // Internal.
00190     void clear_object();
00191 
00192     // Internal.
00193     void unload ();
00194   protected:
00195 
00196     // Internal.
00197     d_Object* ptr_check (bool& oLoad);
00198 
00199     // Internal.
00200     void ptr_load ();
00201 
00202     //--------------------------------------------------------------------------
00203     // ATTRIBUTES:
00204     //--------------------------------------------------------------------------
00205     // Internal
00206     bool valid;
00207     
00208     // Internal.
00209     oObjectId oid;
00210 
00211     // Internal.
00212     d_Object* object;
00213 };
00214 
00215 //------------------------------------------------------------------------------
00216 inline d_Boolean d_Ref_Any::operator ! () const
00217 {
00218   return !valid;
00219 }
00220 //------------------------------------------------------------------------------
00221 inline d_Boolean d_Ref_Any::operator == (const d_Ref_Any& iSource) const
00222 {
00223   if( !valid && !iSource.is_valid() )
00224     return true;
00225 
00226   if( valid && iSource.is_valid() )
00227     if( oid == iSource.oid )
00228       return true;
00229     else
00230       return false;
00231 
00232   return false;
00233 }
00234 //------------------------------------------------------------------------------
00235 inline d_Boolean d_Ref_Any::is_null () const
00236 {
00237   return !valid;
00238 }
00239 //------------------------------------------------------------------------------
00240 inline bool d_Ref_Any::is_valid () const
00241 {
00242   return valid;
00243 }
00244 //------------------------------------------------------------------------------
00245 inline void d_Ref_Any::setValid( bool iValid )
00246 {
00247   valid = iValid;
00248 }
00249 //------------------------------------------------------------------------------
00250 inline bool d_Ref_Any::is_loaded () const
00251 {
00252   return object ? true : false;
00253 }
00254 //------------------------------------------------------------------------------
00255 inline oObjectId& d_Ref_Any::getOid ()
00256 {
00257   return oid;
00258 }
00259 //------------------------------------------------------------------------------
00260 inline d_Object* d_Ref_Any::getObject () const
00261 {
00262   return object;
00263 }
00264 //------------------------------------------------------------------------------
00265 inline void d_Ref_Any::clear_object()
00266 {
00267   object = 0;
00268 }
00269 //------------------------------------------------------------------------------
00270 //------------------------------------------------------------------------------
00271 
00272 #endif

Generated on Fri Nov 29 17:12:13 2002 for Orient ODBMS Just Edition v. 2.0e by doxygen1.3-rc1