|
|
Java-like object reference class. Objects used with this reference class have to be descandents of class Referable.
sample usage:
#include "Ref.h" #include "Referable.h" class A : public virtual Referable; ... A * a = new A(); Ref ref1 = a; // 1 reference to a Ref ref2 = ref1; // 2 references to a ref1 = 0; // 1 reference to a ref2 = 0; // at this point object a is destroyed |
Based on Tima Saarinen's work, http://gamma.nic.fi/~timosa/comp/refcount.html
T* object | object |
[private]
inline
Ref ( void )
throw () | Ref |
Default constructor.
inline
Ref ( const Ref throw ( Exception ) | Ref |
Copy constructor.
Parameters:
other | the Ref to copy. |
Throws: Exception
inline
Ref ( T * obj )
throw ( Exception ) | Ref |
Constructor based on an object to reference.
Parameters:
obj | the object to reference. |
Throws: Exception
inline
~Ref ( void )
throw ( Exception ) | ~Ref |
[virtual]
Destructor.
Throws: Exception
inline T*
operator-> ()
throw ( Exception ) | operator-> |
[const]
Operator overload to make the reference seem like a pointer.
Returns: the pointer to the object referenced.
inline Ref throw ( Exception ) | operator= |
Assignment operator.
Parameters:
other | the Ref to assign to this one. |
Returns: a reference to this Ref.
Throws: Exception
inline Ref throw ( Exception ) | operator= |
Assignment operator.
Parameters:
obj | pointer to the object to assign to this Ref. |
Returns: a reference to this Ref.
Throws: Exception
inline void
set ( T * newobj )
throw ( Exception ) | set |
Set the object referenced. Deletes the old referenced object is this was it's last reference.
Parameters:
newobj | pointer to the object to reference by this Ref. |
Throws: Exception
inline T*
get ( void )
throw () | get |
[const]
Return object pointer. This method should be used with care because it breaks the encapsulation. Typically this method is needed for the method calls which require literal object pointer.
It may not be bad idea to pass the Ref objects as method arguments.
Returns: Object pointer or NULL.
inline bool
operator== ( const T * other )
throw () | operator== |
[const]
Equality operator.
Parameters:
other | the pointer to compare this with. |
Returns: true is this Ref refers to the same object as other, false otherwise.
inline bool
operator== ( const Ref throw () | operator== |
[const]
Equality operator.
Parameters:
other | the Ref to compare this with. |
Returns: true is the two Refs refer to the same object, false otherwise.
inline bool
operator!= ( const T * other )
throw () | operator!= |
[const]
Unequality operator.
Parameters:
other | the pointer to compare this with. |
Returns: false is this Ref refers to a different object then other, true otherwise.
inline bool
operator!= ( const Ref throw () | operator!= |
[const]
Unequality operator.
Parameters:
other | the Ref to compare this with. |
Returns: false is the two Refs refer to the same object, true otherwise.