libassa 3.5.1
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
ASSA::AutoPtrArray< X > Class Template Reference

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

#include <AutoPtr.h>

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.
 
Xoperator* () const
 Smart pointer dereferencing.
 
Xoperator-> () const
 Smart pointer dereferencing.
 
Xoperator[] (int i) const
 Access operator.
 
Xget () const
 Get a raw memory pointer without changing ownership status.
 
Xrelease ()
 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< T > ()
 
template<typename T >
 operator AutoPtrArray< T > ()
 

Private Attributes

Xm_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

◆ AutoPtrArray() [1/4]

template<class X >
ASSA::AutoPtrArray< X >::AutoPtrArray ( X p_ = 0)
inlineexplicit

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.

210: m_ptr (p_) { /* no-op */ }
X * m_ptr
Pointer to the object we own.
Definition AutoPtr.h:201

◆ AutoPtrArray() [2/4]

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.

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

◆ AutoPtrArray() [3/4]

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.

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

◆ ~AutoPtrArray()

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.

255 {
256 if (m_ptr) {
257 delete [] m_ptr;
258 }
259 }

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

◆ AutoPtrArray() [4/4]

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):

A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32

Definition at line 320 of file AutoPtr.h.

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

Member Function Documentation

◆ get()

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.

284{ return m_ptr; }

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

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

◆ operator AutoPtrArray< T >()

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

Definition at line 334 of file AutoPtr.h.

334{ return AutoPtrArray<T> (release ()); }
X * release()
Give up the ownership of the memory.
Definition AutoPtr.h:291

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

◆ operator AutoPtrArrayRef< T >()

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

Definition at line 331 of file AutoPtr.h.

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

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

◆ operator*()

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

Smart pointer dereferencing.

Definition at line 264 of file AutoPtr.h.

264{ return *m_ptr; }

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

◆ operator->()

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

Smart pointer dereferencing.

Definition at line 269 of file AutoPtr.h.

269{ return m_ptr; }

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

◆ operator=() [1/3]

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.

235 {
236 reset (a_.release ());
237 return *this;
238 }
void reset(X *p_=0)
Forcibly delete the managed object and assume the ownership of a_.
Definition AutoPtr.h:301

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

◆ operator=() [2/3]

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.

246 {
247 reset (a_.release ());
248 return *this;
249 }

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

◆ operator=() [3/3]

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

Definition at line 322 of file AutoPtr.h.

322 {
323 if (ref_.m_ptr != get ()) {
324 delete [] m_ptr;
325 m_ptr = ref_.m_ptr;
326 }
327 return *this;
328 }
X * get() const
Get a raw memory pointer without changing ownership status.
Definition AutoPtr.h:284

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

◆ operator[]()

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

Access operator.

Definition at line 274 of file AutoPtr.h.

274 {
275 X* array = get ();
276 return (array [i]);
277 }

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

◆ release()

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.

291 {
292 X* tmp = m_ptr;
293 m_ptr = NULL;
294 return tmp;
295 }

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

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

◆ reset()

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.

301 {
302 if (p_ != m_ptr) {
303 delete [] m_ptr;
304 m_ptr = p_;
305 }
306 }

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

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

Member Data Documentation

◆ m_ptr

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

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