class Ref

Java-like object reference class. More...

Definition#include <Ref.h>
Template formRef<class T>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Private Members


Detailed Description

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

Referable

T* object

object

[private]

inline  Ref ( void )
throw ()

Ref

Default constructor.

inline  Ref ( const Ref & other )
throw ( Exception )

Ref

Copy constructor.

Parameters:
otherthe Ref to copy.

Throws: Exception

inline  Ref ( T * obj )
throw ( Exception )

Ref

Constructor based on an object to reference.

Parameters:
objthe 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 &  operator= ( Ref other )
throw ( Exception )

operator=

Assignment operator.

Parameters:
otherthe Ref to assign to this one.

Returns: a reference to this Ref.

Throws: Exception

inline Ref &  operator= ( T* obj )
throw ( Exception )

operator=

Assignment operator.

Parameters:
objpointer 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:
newobjpointer 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:
otherthe pointer to compare this with.

Returns: true is this Ref refers to the same object as other, false otherwise.

inline bool  operator== ( const Ref & other )
throw ()

operator==

[const]

Equality operator.

Parameters:
otherthe 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:
otherthe pointer to compare this with.

Returns: false is this Ref refers to a different object then other, true otherwise.

inline bool  operator!= ( const Ref & other )
throw ()

operator!=

[const]

Unequality operator.

Parameters:
otherthe Ref to compare this with.

Returns: false is the two Refs refer to the same object, true otherwise.