ASSA::AutoPtrArray< X > Class Template Reference

AutoPtrArray handles memory management of an array of objects. More...

#include <AutoPtr.h>

Collaboration diagram for ASSA::AutoPtrArray< X >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 AutoPtrArray (X *p_=0)
 Construct an AutoPtrArray from a raw pointer.
 AutoPtrArray (AutoPtrArray &a_)
 Construct AutoPtrArray from another AutoPtrArray.
template<typename T>
 AutoPtrArray (AutoPtrArray< T > &a_)
 Construct AutoPtrArray from another AutoPtrArray of different (but related) type.
AutoPtrArrayoperator= (AutoPtrArray &a_)
 Assignment operator deletes memory it owns and transfers the ownership from a_ to itself.
template<class T>
AutoPtrArrayoperator= (AutoPtrArray< T > &a_)
 Assignment from another AutoPtrArray of a different but related type.
 ~AutoPtrArray ()
 When AutoPtrArray goes out of scope, the object it owns is deleted.
X & operator * () const
 Smart pointer dereferencing.
X * operator-> () const
 Smart pointer dereferencing.
X & operator[] (int i) const
 Access operator.
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_.
 AutoPtrArray (AutoPtrArrayRef< X > ref_)
 Automagic conversions.
AutoPtrArrayoperator= (AutoPtrArrayRef< X > ref_)
template<typename T>
 operator AutoPtrArrayRef ()
template<typename T>
 operator AutoPtrArray ()

Private Attributes

X * m_ptr
 Pointer to the object we own.

Detailed Description

template<class X>
class ASSA::AutoPtrArray< X >

AutoPtrArray handles memory management of an array of objects.

Definition at line 198 of file AutoPtr.h.


Constructor & Destructor Documentation

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

Construct an AutoPtrArray 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 210 of file AutoPtr.h.

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

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

Construct AutoPtrArray from another AutoPtrArray.

Parameters:
a_ AutoPtrArray object that gives up its ownership.

Definition at line 216 of file AutoPtr.h.

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

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

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

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

Note:
Nonconstant paramenter
Parameters:
a_ AutoPtrArray object that is released of ownership.

Definition at line 226 of file AutoPtr.h.

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

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

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

Not owning anything has no effect.

Definition at line 255 of file AutoPtr.h.

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

00255                      { 
00256         if (m_ptr) { 
00257             delete [] m_ptr; 
00258         }  
00259     }

template<class X>
ASSA::AutoPtrArray< X >::AutoPtrArray AutoPtrArrayRef< X >  ref_  )  [inline]
 

Automagic conversions.

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

     AutoPtrArray<Derived> FooReturnsAutoPtrArray () { ... };

     AutoPtrArray<Base> aptr = FooReturnsAutoPtrArray ();

Definition at line 320 of file AutoPtr.h.

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


Member Function Documentation

template<class X>
X* ASSA::AutoPtrArray< 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 284 of file AutoPtr.h.

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

Referenced by ASSA::AutoPtrArray< X >::operator=(), and ASSA::AutoPtrArray< X >::operator[]().

00284 { return m_ptr; }

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

Smart pointer dereferencing.

Definition at line 264 of file AutoPtr.h.

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

00264 { return *m_ptr; }

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

Definition at line 334 of file AutoPtr.h.

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

00334 { return AutoPtrArray<T> (release ()); }

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

Definition at line 331 of file AutoPtr.h.

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

00331 { return AutoPtrArrayRef<T> (release ()); }

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

Smart pointer dereferencing.

Definition at line 269 of file AutoPtr.h.

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

00269 { return m_ptr; }

template<class X>
AutoPtrArray& ASSA::AutoPtrArray< X >::operator= AutoPtrArrayRef< X >  ref_  )  [inline]
 

Definition at line 322 of file AutoPtr.h.

References ASSA::AutoPtrArray< X >::get(), ASSA::AutoPtrArray< X >::m_ptr, and ASSA::AutoPtrArrayRef< R >::m_ptr.

00322                                                      {
00323         if (ref_.m_ptr != get ()) {
00324             delete [] m_ptr;
00325             m_ptr = ref_.m_ptr;
00326         }
00327         return *this;
00328     }

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

Assignment from another AutoPtrArray of a different but related type.

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

Definition at line 246 of file AutoPtr.h.

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

00246                                                  {
00247         reset (a_.release ());
00248         return *this;
00249     }

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

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

Note:
Nonconstant parameter
Parameters:
a_ another AutoPtrArray of the same type.

Definition at line 235 of file AutoPtr.h.

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

00235                                                 {
00236         reset (a_.release ());
00237         return *this;
00238     }

template<class X>
X& ASSA::AutoPtrArray< X >::operator[] int  i  )  const [inline]
 

Access operator.

Definition at line 274 of file AutoPtr.h.

References ASSA::AutoPtrArray< X >::get().

00274                                 {
00275         X* array = get ();
00276         return (array [i]);
00277     }

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

Give up the ownership of the memory.

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

Definition at line 291 of file AutoPtr.h.

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

Referenced by ASSA::AutoPtrArray< X >::operator AutoPtrArray(), ASSA::AutoPtrArray< X >::operator AutoPtrArrayRef(), and ASSA::AutoPtrArray< X >::operator=().

00291                   {
00292         X* tmp = m_ptr;
00293         m_ptr = NULL;
00294         return tmp;
00295     }

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

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

Definition at line 301 of file AutoPtr.h.

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

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

00301                            {
00302         if (p_ != m_ptr) {
00303             delete [] m_ptr;
00304             m_ptr = p_;
00305         }
00306     }


Member Data Documentation

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

Pointer to the object we own.

Definition at line 201 of file AutoPtr.h.

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


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