AutoPtr< T, P > Class Template Reference

#include <autoPtr.h>

Inheritance diagram for AutoPtr< T, P >:

Inheritance graph
[legend]
List of all members.

Detailed Description


template<class T, class P = DeleteSingle> class AutoPtr< T, P >

A simple smart pointer.

An extended version of std::auto_ptr which supports a deletion policy. The delete policy indicates how the ptr is to be deleted. DeleteSingle, the default, is used to delete individual objects. DeleteArray can can be used to delete arrays. AutoPtr<Object> ptr(new Object); AutoPtr<Object,DeleteSingle> ptr(new Object); AutoPtr<Object,DeleteArray> ptr(new Object[10]); AutoPtrs do not perform reference counting and assume total ownership of any object assigned to them. Assigning an AutoPtr to another transfers that ownership and resets the source AutoPtr to 0.


Public Types

typedef T ValueType

Public Member Functions

 AutoPtr (T *ptr=0)
 ~AutoPtr ()
 AutoPtr (AutoPtr &rhs)
template<class U>
 AutoPtr (AutoPtr< U, P > &rhs)
AutoPtroperator= (AutoPtr &rhs)
 Transfer ownership, any object currently be referenced is deleted and rhs is set to 0.
template<class U>
AutoPtroperator= (AutoPtr< U, P > &rhs)
T * ptr () const
T & operator * () const
T * operator-> () const
T & operator[] (size_t index)
T * release ()
 Release ownership of the object without deleting it.
void reset (T *ptr=0)
 Equivalent to *this = (T*)ptr, except that operator=(T*) isn't provided for.
 AutoPtr (AutoPtrRef< T > ref)
AutoPtroperator= (AutoPtrRef< T > ref)
bool isNull () const
bool isValid () const
template<class U>
 operator AutoPtrRef ()
template<class U>
 operator AutoPtr ()

Private Attributes

T * _ptr


Member Typedef Documentation

template<class T, class P = DeleteSingle>
typedef T AutoPtr< T, P >::ValueType


Constructor & Destructor Documentation

template<class T, class P = DeleteSingle>
AutoPtr< T, P >::AutoPtr ( T *  ptr = 0  )  [inline, explicit]

template<class T, class P = DeleteSingle>
AutoPtr< T, P >::~AutoPtr (  )  [inline]

template<class T, class P = DeleteSingle>
AutoPtr< T, P >::AutoPtr ( AutoPtr< T, P > &  rhs  )  [inline]

template<class T, class P = DeleteSingle>
template<class U>
AutoPtr< T, P >::AutoPtr ( AutoPtr< U, P > &  rhs  )  [inline]

template<class T, class P = DeleteSingle>
AutoPtr< T, P >::AutoPtr ( AutoPtrRef< T >  ref  )  [inline]


Member Function Documentation

template<class T, class P = DeleteSingle>
AutoPtr& AutoPtr< T, P >::operator= ( AutoPtr< T, P > &  rhs  )  [inline]

Transfer ownership, any object currently be referenced is deleted and rhs is set to 0.

template<class T, class P = DeleteSingle>
template<class U>
AutoPtr& AutoPtr< T, P >::operator= ( AutoPtr< U, P > &  rhs  )  [inline]

template<class T, class P = DeleteSingle>
T* AutoPtr< T, P >::ptr (  )  const [inline]

template<class T, class P = DeleteSingle>
T& AutoPtr< T, P >::operator * (  )  const [inline]

template<class T, class P = DeleteSingle>
T* AutoPtr< T, P >::operator-> (  )  const [inline]

template<class T, class P = DeleteSingle>
T& AutoPtr< T, P >::operator[] ( size_t  index  )  [inline]

template<class T, class P = DeleteSingle>
T* AutoPtr< T, P >::release (  )  [inline]

Release ownership of the object without deleting it.

template<class T, class P = DeleteSingle>
void AutoPtr< T, P >::reset ( T *  ptr = 0  )  [inline]

Equivalent to *this = (T*)ptr, except that operator=(T*) isn't provided for.

template<class T, class P = DeleteSingle>
AutoPtr& AutoPtr< T, P >::operator= ( AutoPtrRef< T >  ref  )  [inline]

template<class T, class P = DeleteSingle>
bool AutoPtr< T, P >::isNull (  )  const [inline]

template<class T, class P = DeleteSingle>
bool AutoPtr< T, P >::isValid (  )  const [inline]

template<class T, class P = DeleteSingle>
template<class U>
AutoPtr< T, P >::operator AutoPtrRef (  )  [inline]

template<class T, class P = DeleteSingle>
template<class U>
AutoPtr< T, P >::operator AutoPtr (  )  [inline]


Member Data Documentation

template<class T, class P = DeleteSingle>
T* AutoPtr< T, P >::_ptr [private]