Loading...
Searching...
No Matches
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.
AutoPtrArray & | operator= (AutoPtrArray &a_)
| Assignment operator deletes memory it owns and transfers the ownership from a_ to itself.
template<class T>
AutoPtrArray & | operator= (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.
AutoPtrArray & | operator= (AutoPtrArrayRef< X > ref_)
template<typename T>
| operator AutoPtrArrayRef< T > ()
template<typename T>
| operator AutoPtrArray< T > ()

## 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

## AutoPtrArray() [1/4]

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.

: m_ptr (p_) { /* no-op */ }
ASSA::AutoPtrArray
AutoPtrArray handles memory management of an array of objects.
Definition AutoPtr.h:198
ASSA::AutoPtrArray::m_ptr
X * m_ptr
Pointer to the object we own.
Definition AutoPtr.h:201

References m_ptr.

Referenced by AutoPtrArray(), AutoPtrArray(), operator AutoPtrArray< T >(), operator=(), operator=(), and operator=().

## 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.

: m_ptr (a_.release ()) {/* no-op */ }
ASSA::AutoPtrArray::release
X * release()
Give up the ownership of the memory.
Definition AutoPtr.h:291

References AutoPtrArray(), m_ptr, and release().

## 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.

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

References AutoPtrArray(), m_ptr, and release().

## ~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.

{
if (m_ptr) {
delete [] m_ptr;
}
}

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

AutoPtrArray<Derived> FooReturnsAutoPtrArray () { ... };
AutoPtrArray<Base> aptr = FooReturnsAutoPtrArray ();
ASSA::AutoPtrArray::AutoPtrArray
AutoPtrArray(X *p_=0)
Construct an AutoPtrArray from a raw pointer.
Definition AutoPtr.h:210

Definition at line 320 of file AutoPtr.h.

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

References m_ptr.

## 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.

{ return m_ptr; }

References m_ptr.

Referenced by operator=(), and 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.

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

References AutoPtrArray(), and 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.

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

References release().

## operator*()

template<class X>

X & ASSA::AutoPtrArray< X >::operator* | ( |  | ) | const

inline

Smart pointer dereferencing.

Definition at line 264 of file AutoPtr.h.

{ return *m_ptr; }

References m_ptr.

## operator->()

template<class X>

X * ASSA::AutoPtrArray< X >::operator-> | ( |  | ) | const

inline

Smart pointer dereferencing.

Definition at line 269 of file AutoPtr.h.

{ return m_ptr; }

References 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.

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

References AutoPtrArray(), release(), and 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.

{
reset (a_.release ());
return *this;
}

References AutoPtrArray(), release(), and reset().

## operator=() [3/3]

template<class X>

AutoPtrArray & ASSA::AutoPtrArray< X >::operator= | ( | AutoPtrArrayRef< X > | ref_ | ) |

inline

Definition at line 322 of file AutoPtr.h.

{
if (ref_.m_ptr != get ()) {
delete [] m_ptr;
m_ptr = ref_.m_ptr;
}
return *this;
}
ASSA::AutoPtrArray::get
X * get() const
Get a raw memory pointer without changing ownership status.
Definition AutoPtr.h:284

References AutoPtrArray(), get(), m_ptr, and ASSA::AutoPtrArrayRef< R >::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.

{
X* array = get ();
return (array [i]);
}

References 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.

{
X* tmp = m_ptr;
m_ptr = NULL;
return tmp;
}

References m_ptr.

Referenced by AutoPtrArray(), AutoPtrArray(), operator AutoPtrArray< T >(), operator AutoPtrArrayRef< T >(), operator=(), and operator=().

## 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.

{
if (p_ != m_ptr) {
delete [] m_ptr;
m_ptr = p_;
}
}

References m_ptr.

Referenced by operator=(), and operator=().

## Member Data Documentation

## m_ptr

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 AutoPtrArray(), AutoPtrArray(), AutoPtrArray(), AutoPtrArray(), get(), operator*(), operator->(), operator=(), release(), reset(), and ~AutoPtrArray().

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

- AutoPtr.h