ASSA::AutoPtr< X > Class Template Reference

AutoPtr is based on SGI implementation of a auto_ptr template that makes memory handling a little bit easier. More...

#include <AutoPtr.h>

Collaboration diagram for ASSA::AutoPtr< X >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 AutoPtr (X *p_=0)
 Construct an AutoPtr from a raw pointer.
 AutoPtr (AutoPtr &a_)
 Construct AutoPtr from another AutoPtr.
template<typename T>
 AutoPtr (AutoPtr< T > &a_)
 Construct AutoPtr from another AutoPtr of different (but related) type.
AutoPtroperator= (AutoPtr &a_)
 Assignment operator deletes memory it owns and transfers the ownership from a_ to itself.
template<class T>
AutoPtroperator= (AutoPtr< T > &a_)
 Assignment from another AutoPtr of a different but related type.
 ~AutoPtr ()
 When AutoPtr goes out of scope, the object it owns is deleted.
X & operator * () const
 Smart pointer dereferencing.
X * operator-> () const
 Smart pointer dereferencing.
X * get () const
 Get a raw memory pointer without changing ownership status.
X * release ()
 Give up the ownership of the memory.
void reset (X *p_=0)
 Forcibly delete the managed object and assume the ownership of a_.
 AutoPtr (AutoPtrRef< X > ref_)
 Automagic conversions.
AutoPtroperator= (AutoPtrRef< X > ref_)
template<typename T>
 operator AutoPtrRef ()
template<typename T>
 operator AutoPtr ()

Private Attributes

X * m_ptr
 Pointer to the object we own.

Detailed Description

template<class X>
class ASSA::AutoPtr< X >

AutoPtr is based on SGI implementation of a auto_ptr template that makes memory handling a little bit easier.

AutoPtr interface does not completely confirm to that of auto_ptr as specified in C++ Standard.

Definition at line 49 of file AutoPtr.h.


Constructor & Destructor Documentation

template<class X>
ASSA::AutoPtr< X >::AutoPtr X *  p_ = 0  )  [inline, explicit]
 

Construct an AutoPtr from a raw pointer.

The word 'explicit' disallows implicit construction of objects, for example in function calls.

Parameters:
p_ pointer (defaults to NULL) to assume ownerwhip for.

Definition at line 61 of file AutoPtr.h.

00061 : m_ptr (p_) { /* no-op */ }

template<class X>
ASSA::AutoPtr< X >::AutoPtr AutoPtr< X > &  a_  )  [inline]
 

Construct AutoPtr from another AutoPtr.

Parameters:
a_ AutoPtr object that gives up its ownership.

Definition at line 67 of file AutoPtr.h.

00067 : m_ptr (a_.release ()) {/* no-op */ }

template<class X>
template<typename T>
ASSA::AutoPtr< X >::AutoPtr AutoPtr< T > &  a_  )  [inline]
 

Construct AutoPtr from another AutoPtr of different (but related) type.

A pointer to T must be convertible to a pointer to X.

Note:
Nonconstant parameter
Parameters:
a_ AutoPtr object that is released of ownership.

Definition at line 76 of file AutoPtr.h.

00076 : m_ptr (a_.release ()) { /* no-op */ }

template<class X>
ASSA::AutoPtr< X >::~AutoPtr  )  [inline]
 

When AutoPtr goes out of scope, the object it owns is deleted.

Not owning anything has no effect.

Definition at line 102 of file AutoPtr.h.

References ASSA::AutoPtr< X >::m_ptr.

00102                 { 
00103         if (m_ptr) { 
00104             delete m_ptr; 
00105         }  
00106     }

template<class X>
ASSA::AutoPtr< X >::AutoPtr AutoPtrRef< X >  ref_  )  [inline]
 

Automagic conversions.

These operations convert an AutoPtr into/from an AutoPtrRef as needed. This allows on-the-fly conversion between AutoPtr of different but related types (parent/child):

     AutoPtr<Derived> FooReturnsAutoPtr () { ... };

     AutoPtr<Base> aptr = FooReturnsAutoPtr ();

Definition at line 159 of file AutoPtr.h.

00159 : m_ptr (ref_.m_ptr) { /* no-op */ }


Member Function Documentation

template<class X>
X* ASSA::AutoPtr< X >::get  )  const [inline]
 

Get a raw memory pointer without changing ownership status.

Usefull when you need to pass a pointer to the function.

Returns:
The raw pointer being managed.

Definition at line 123 of file AutoPtr.h.

References ASSA::AutoPtr< X >::m_ptr.

Referenced by ASSA::Logger::log_open(), and ASSA::AutoPtr< X >::operator=().

00123 { return m_ptr; }

template<class X>
X& ASSA::AutoPtr< X >::operator *  )  const [inline]
 

Smart pointer dereferencing.

Definition at line 111 of file AutoPtr.h.

References ASSA::AutoPtr< X >::m_ptr.

00111 { return *m_ptr; }

template<class X>
template<typename T>
ASSA::AutoPtr< X >::operator AutoPtr  )  [inline]
 

Definition at line 173 of file AutoPtr.h.

References ASSA::AutoPtr< X >::release().

00173 { return AutoPtr<T> (release ()); }

template<class X>
template<typename T>
ASSA::AutoPtr< X >::operator AutoPtrRef  )  [inline]
 

Definition at line 170 of file AutoPtr.h.

References ASSA::AutoPtr< X >::release().

00170 { return AutoPtrRef<T> (release ()); }

template<class X>
X* ASSA::AutoPtr< X >::operator->  )  const [inline]
 

Smart pointer dereferencing.

Definition at line 116 of file AutoPtr.h.

References ASSA::AutoPtr< X >::m_ptr.

00116 { return m_ptr; }

template<class X>
AutoPtr& ASSA::AutoPtr< X >::operator= AutoPtrRef< X >  ref_  )  [inline]
 

Definition at line 161 of file AutoPtr.h.

References ASSA::AutoPtr< X >::get(), ASSA::AutoPtr< X >::m_ptr, and ASSA::AutoPtrRef< R >::m_ptr.

00161                                            {
00162         if (ref_.m_ptr != get ()) {
00163             delete m_ptr;
00164             m_ptr = ref_.m_ptr;
00165         }
00166         return *this;
00167     }

template<class X>
template<class T>
AutoPtr& ASSA::AutoPtr< X >::operator= AutoPtr< T > &  a_  )  [inline]
 

Assignment from another AutoPtr of a different but related type.

Note:
Nonconstant parameter
Parameters:
a_ AutoPtr to assume ownership of

Definition at line 93 of file AutoPtr.h.

References ASSA::AutoPtr< X >::release(), and ASSA::AutoPtr< X >::reset().

00093                                                          {
00094         reset (a_.release ());
00095         return *this;
00096     }

template<class X>
AutoPtr& ASSA::AutoPtr< X >::operator= AutoPtr< X > &  a_  )  [inline]
 

Assignment operator deletes memory it owns and transfers the ownership from a_ to itself.

Parameters:
a_ another AutoPtr of the same type.

Definition at line 83 of file AutoPtr.h.

References ASSA::AutoPtr< X >::release(), and ASSA::AutoPtr< X >::reset().

00083                                       {
00084         reset (a_.release ());
00085         return *this;
00086     }

template<class X>
X* ASSA::AutoPtr< X >::release  )  [inline]
 

Give up the ownership of the memory.

When AutoPtr gets out of scope, nothing happens. The caller becomes responsible for the memory management.

Definition at line 130 of file AutoPtr.h.

References ASSA::AutoPtr< X >::m_ptr.

Referenced by ASSA::Logger::log_open(), ASSA::AutoPtr< X >::operator AutoPtr(), ASSA::AutoPtr< X >::operator AutoPtrRef(), and ASSA::AutoPtr< X >::operator=().

00130                   {
00131         X* tmp = m_ptr;
00132         m_ptr = NULL;
00133         return tmp;
00134     }

template<class X>
void ASSA::AutoPtr< X >::reset X *  p_ = 0  )  [inline]
 

Forcibly delete the managed object and assume the ownership of a_.

Definition at line 140 of file AutoPtr.h.

References ASSA::AutoPtr< X >::m_ptr.

Referenced by ASSA::AutoPtr< X >::operator=().

00140                            {
00141         if (p_ != m_ptr) {
00142             delete m_ptr;
00143             m_ptr = p_;
00144         }
00145     }


Member Data Documentation

template<class X>
X* ASSA::AutoPtr< X >::m_ptr [private]
 

Pointer to the object we own.

Definition at line 52 of file AutoPtr.h.

Referenced by ASSA::AutoPtr< X >::get(), ASSA::AutoPtr< X >::operator *(), ASSA::AutoPtr< X >::operator->(), ASSA::AutoPtr< X >::operator=(), ASSA::AutoPtr< X >::release(), ASSA::AutoPtr< X >::reset(), and ASSA::AutoPtr< X >::~AutoPtr().


The documentation for this class was generated from the following file:
Generated on Sun Aug 13 15:08:18 2006 for libassa by  doxygen 1.4.6