Reference< T > Class Template Reference

A container for reference-counted objects. More...

#include <reference.h>

List of all members.

Public Member Functions

 Reference (T *_pointer=NULL)
 Create a reference to the object pointed to by the given pointer.
 Reference (const Reference< T > &other)
 A copy constructor.
Referenceoperator= (T *_ptr)
 Assigns the pointer this instance of Reference holds.
Referenceoperator= (const Reference< T > &other)
 Have this reference the object held by other.
T * operator-> () const
 Return the underlying pointer.
 operator bool () const
 Convert the the reference to a boolean, which is true if the underlying object is not NULL.
bool operator== (T *_ptr) const
 Check whether this holds the given pointer.
bool operator!= (T *_ptr) const
 Check whether this holds a difference pointer than the given pointer.
bool operator== (const Reference< T > &other) const
 Check whether this holds the same object as other does.
bool operator!= (const Reference< T > &other_) const
 Check whether this holds a difference object than other does.
bool operator< (T *_ptr) const
 Compere this with the given pointer.
bool operator< (const Reference< T > &other)
 Compare the pointer this holds with the one other holds.
virtual ~Reference ()
 Destroy the reference by setting the pointer it holds to NULL.
T * get_pointer ()
 Return the underlying pointer.

Private Attributes

T * pointer_
 the pointer to a reference-counted object.


Detailed Description

template<class T>
class Reference< T >

A container for reference-counted objects.

Reference holds a pointer to objects of class ReferenceCounted. When you assign such a pointer to Reference, the reference count is automatically increased. Also, when the pointer Reference holds changes, Reference automatically decreases the reference count of the old pointer, thereby facilitating automatic destruction of the object.

Reference behaves like other "smart pointer" objects in C++ such as boost::shared_ptr. You assign, compare, and use the -> operator on Reference.


Constructor & Destructor Documentation

template<class T>
Reference< T >::Reference ( T *  _pointer = NULL  )  [inline]

Create a reference to the object pointed to by the given pointer.

Parameters:
_pointer a pointer to a reference-counted object or NULL. It is defaulted to NULL.

template<class T>
Reference< T >::Reference ( const Reference< T > &  other  )  [inline]

A copy constructor.

Notes that this constructor increases the reference count of the object other holds by one.

template<class T>
virtual Reference< T >::~Reference (  )  [inline, virtual]

Destroy the reference by setting the pointer it holds to NULL.

This would cause the reference count to the held object to be decremented, thereby facilitating automatic desctruction of the held object.


Member Function Documentation

template<class T>
T* Reference< T >::get_pointer (  )  [inline]

Return the underlying pointer.

template<class T>
Reference< T >::operator bool (  )  const [inline]

Convert the the reference to a boolean, which is true if the underlying object is not NULL.

template<class T>
bool Reference< T >::operator!= ( const Reference< T > &  other_  )  const [inline]

Check whether this holds a difference object than other does.

template<class T>
bool Reference< T >::operator!= ( T *  _ptr  )  const [inline]

Check whether this holds a difference pointer than the given pointer.

template<class T>
T* Reference< T >::operator-> (  )  const [inline]

Return the underlying pointer.

Use this method to access the underlying object's fields or invoking methods.

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

Compare the pointer this holds with the one other holds.

template<class T>
bool Reference< T >::operator< ( T *  _ptr  )  const [inline]

Compere this with the given pointer.

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

Have this reference the object held by other.

template<class T>
Reference& Reference< T >::operator= ( T *  _ptr  )  [inline]

Assigns the pointer this instance of Reference holds.

The method also automatically decreases the reference of the old object held if it is neither NULL nor equal to to the new object being assigned.

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

Check whether this holds the same object as other does.

template<class T>
bool Reference< T >::operator== ( T *  _ptr  )  const [inline]

Check whether this holds the given pointer.


Member Data Documentation

template<class T>
T* Reference< T >::pointer_ [private]

the pointer to a reference-counted object.


The documentation for this class was generated from the following file:

Generated on Tue Sep 8 02:20:35 2009 for cglib by  doxygen 1.5.9