Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

Ref< T > Class Template Reference

#include <Ref.h>

Collaboration diagram for Ref< T >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class T>
class Ref< T >

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

Author:
Author
darkeye
Version:
Revision
1.5

Definition at line 82 of file Ref.h.

Public Member Functions

 Ref (void) throw ()
 Default constructor.
 Ref (const Ref< T > &other) throw ( Exception )
 Copy constructor.
 Ref (T *obj) throw ( Exception )
 Constructor based on an object to reference.
virtual ~Ref (void) throw ( Exception )
 Destructor.
T * operator-> () const throw ( Exception )
 Operator overload to make the reference seem like a pointer.
Ref< T > & operator= (Ref< T > other) throw ( Exception )
 Assignment operator.
Ref< T > & operator= (T *obj) throw ( Exception )
 Assignment operator.
void set (T *newobj) throw ( Exception )
 Set the object referenced.
T * get (void) const throw ()
 Return object pointer.
bool operator== (const T *other) const throw ()
 Equality operator.
bool operator== (const Ref< T > &other) const throw ()
 Equality operator.
bool operator!= (const T *other) const throw ()
 Unequality operator.
bool operator!= (const Ref< T > &other) const throw ()
 Unequality operator.


Constructor & Destructor Documentation

template<class T>
Ref< T >::Ref void   )  throw () [inline]
 

Default constructor.

Definition at line 102 of file Ref.h.

template<class T>
Ref< T >::Ref const Ref< T > &  other  )  throw ( Exception ) [inline]
 

Copy constructor.

Parameters:
other the Ref to copy.
Exceptions:
Exception 

Definition at line 114 of file Ref.h.

template<class T>
Ref< T >::Ref T *  obj  )  throw ( Exception ) [inline]
 

Constructor based on an object to reference.

Parameters:
obj the object to reference.
Exceptions:
Exception 

Definition at line 127 of file Ref.h.

template<class T>
virtual Ref< T >::~Ref void   )  throw ( Exception ) [inline, virtual]
 

Destructor.

Exceptions:
Exception 

Definition at line 139 of file Ref.h.


Member Function Documentation

template<class T>
T* Ref< T >::get void   )  const throw () [inline]
 

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.

Definition at line 230 of file Ref.h.

Referenced by Connector::attach(), CastSink::getSink(), and MultiThreadedConnector::sinkThread().

template<class T>
bool Ref< T >::operator!= const Ref< T > &  other  )  const throw () [inline]
 

Unequality operator.

Parameters:
other the Ref to compare this with.
Returns:
false is the two Refs refer to the same object, true otherwise.

Definition at line 282 of file Ref.h.

template<class T>
bool Ref< T >::operator!= const T *  other  )  const throw () [inline]
 

Unequality operator.

Parameters:
other the pointer to compare this with.
Returns:
false is this Ref refers to a different object then other, true otherwise.

Definition at line 269 of file Ref.h.

template<class T>
T* Ref< T >::operator->  )  const throw ( Exception ) [inline]
 

Operator overload to make the reference seem like a pointer.

Returns:
the pointer to the object referenced.

Definition at line 150 of file Ref.h.

template<class T>
Ref<T>& Ref< T >::operator= T *  obj  )  throw ( Exception ) [inline]
 

Assignment operator.

Parameters:
obj pointer to the object to assign to this Ref.
Returns:
a reference to this Ref.
Exceptions:
Exception 

Definition at line 181 of file Ref.h.

template<class T>
Ref<T>& Ref< T >::operator= Ref< T >  other  )  throw ( Exception ) [inline]
 

Assignment operator.

Parameters:
other the Ref to assign to this one.
Returns:
a reference to this Ref.
Exceptions:
Exception 

Definition at line 167 of file Ref.h.

template<class T>
bool Ref< T >::operator== const Ref< T > &  other  )  const throw () [inline]
 

Equality operator.

Parameters:
other the Ref to compare this with.
Returns:
true is the two Refs refer to the same object, false otherwise.

Definition at line 256 of file Ref.h.

template<class T>
bool Ref< T >::operator== const T *  other  )  const throw () [inline]
 

Equality operator.

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

Definition at line 243 of file Ref.h.

template<class T>
void Ref< T >::set T *  newobj  )  throw ( Exception ) [inline]
 

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.
Exceptions:
Exception 

Definition at line 195 of file Ref.h.

Referenced by Ref< FileSink >::operator=(), Ref< FileSink >::Ref(), and Ref< FileSink >::~Ref().


The documentation for this class was generated from the following file:
Generated on Sat Oct 22 13:17:07 2005 for DarkIce by  doxygen 1.4.4