gxAutoPtr< T > Class Template Reference

Helper class to ensure that an object is deleted when the helper goes out of scope. More...

#include <gxAutoPtr.h>

List of all members.

Public Member Functions

 gxAutoPtr (T *ptr=NULL)
 Constructor allows an optional raw pointer to be attached to the auto pointer.
virtual ~gxAutoPtr ()
 Destructor ensures that the attached object (if any) is deleted when the auto pointer goes out of scope.
T ** operator & ()
 Override of the "&" operator returns the address of the raw pointer.
T * operator-> ()
 Override of the "->" operator allows the auto pointer to be dereferenced just like a raw pointer.
bool operator== (gxAutoPtr< T > &rhs)
 Override of the "==" operator.
bool operator== (T *rhs)
 Override of the "==" operator which compares the wrapped raw pointer with a supplied raw pointer.
gxAutoPtroperator= (T *rhs)
 The assignment operator only works with raw pointers.
 operator T * ()
 The assignment operator only works with raw pointers.
void clear ()
void assign (T *rhs)
 The assignment method only works with raw pointers.
T * detach ()
 Retrieve the current raw pointer and clear the auto ptr.

Public Attributes

T * m_ptr


Detailed Description

template<class T>
class gxAutoPtr< T >

Helper class to ensure that an object is deleted when the helper goes out of scope.

Serves the same purpose as the std::auto_ptr template class, but is easier to use within gxLib ( std::auto_ptr only allows the raw pointer to be assigned to the auto_ptr in the constructor) In gxLib it is convenient to pass the address of the auto_ptr to factory methods which return a pointer to the new object via an output param, as in the example below:

   extern objectFactory( object ** newObject );

   gxAutoPtr<object> myObject;
   objectFactory::create( &myObject );
 


Constructor & Destructor Documentation

template<class T>
gxAutoPtr< T >::gxAutoPtr T *  ptr = NULL  )  [inline]
 

Constructor allows an optional raw pointer to be attached to the auto pointer.

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

Destructor ensures that the attached object (if any) is deleted when the auto pointer goes out of scope.


Member Function Documentation

template<class T>
void gxAutoPtr< T >::assign T *  rhs  )  [inline]
 

The assignment method only works with raw pointers.

When you assign a raw pointer to the auto ptr, it deletes any existing object and replaces with the supplied pointer.

template<class T>
void gxAutoPtr< T >::clear  )  [inline]
 

template<class T>
T* gxAutoPtr< T >::detach  )  [inline]
 

Retrieve the current raw pointer and clear the auto ptr.

The object is not deleted.

template<class T>
T** gxAutoPtr< T >::operator &  )  [inline]
 

Override of the "&" operator returns the address of the raw pointer.

template<class T>
gxAutoPtr< T >::operator T *  )  [inline]
 

The assignment operator only works with raw pointers.

When you assign a raw pointer to the auto ptr, it deletes any existing object and replaces with the supplied pointer.

template<class T>
T* gxAutoPtr< T >::operator->  )  [inline]
 

Override of the "->" operator allows the auto pointer to be dereferenced just like a raw pointer.

template<class T>
gxAutoPtr& gxAutoPtr< T >::operator= T *  rhs  )  [inline]
 

The assignment operator only works with raw pointers.

When you assign a raw pointer to the auto ptr, it deletes any existing object and replaces with the supplied pointer.

template<class T>
bool gxAutoPtr< T >::operator== T *  rhs  )  [inline]
 

Override of the "==" operator which compares the wrapped raw pointer with a supplied raw pointer.

template<class T>
bool gxAutoPtr< T >::operator== gxAutoPtr< T > &  rhs  )  [inline]
 

Override of the "==" operator.

Two auto ptrs are equal if they contain the same raw pointer.


Member Data Documentation

template<class T>
T* gxAutoPtr< T >::m_ptr
 


The documentation for this class was generated from the following file:
Generated on Mon Nov 21 01:01:37 2005 for gxLib by  doxygen 1.4.5