|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |
#include "ot/base/ArrayAutoPtr.h"
A variation of std::auto_ptr which holds a pointer to an array and uses the associated delete [] syntax when it needs to destroy the array.
The following example shows how an ArrayAutoPtr is initialized with a new array pointer and manages the memory even in the presence of exceptions:
// create a scope for the automatic deletion of the array { ArrayAutoPtr<float> apArray(new float[20]); // use operator[] to access the array members apArray[0] = 3.142; throw Exception(OT_T("test")); // array is automatically freed at exit from scope }
Constructor/Destructor Summary | |
ArrayAutoPtr(T* ptr) Creates an ArrayAutoPtr which takes ownership of the array starting at ptr. | |
ArrayAutoPtr(const ArrayAutoPtr< T >& rhs) Copy constructor which takes ownership of the array currently owned by rhs. | |
~ArrayAutoPtr() Destructor which deletes the contained array pointer if it is 'owned' by this object. |
Method Summary | |
T* |
get() const Returns the contained array pointer. |
T& |
operator *() const Dereference operator which returns a reference to the first element of the contained array. |
T& |
operator[](size_t n) const Dereference operator which returns a reference to the nth element of the contained array. |
ArrayAutoPtr< T >& |
operator=(const ArrayAutoPtr< T >& rhs) Assignment operator which takes ownership of the array currently owned by rhs. |
T* |
release() const Returns the contained pointer and revokes 'ownership', so that the destructor or assignment will not delete the contained pointer. |
Typedefs |
typedef T element_type
Constructor/Destructor Detail |
ArrayAutoPtr(T* ptr)
ArrayAutoPtr(const ArrayAutoPtr< T >& rhs)
~ArrayAutoPtr()
Method Detail |
T* get() const
T& operator *() const
T& operator[](size_t n) const
ArrayAutoPtr< T >& operator=(const ArrayAutoPtr< T >& rhs)
Note that rhs is modified by this operation even though it is marked as const.
T* release() const
|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |