Public Member Functions

jsplib::array_autoptr< T > Class Template Reference

a template which emulates the operation and semantics of std::auto_ptr but works with arrays only More...

#include <Cj_array_autoptr.hh>

List of all members.

Public Member Functions

 array_autoptr (T *p=0)
 Creates a new array_autoptr and optionally initialises it with the specified pointer, taking ownership of array of objects pointed to by it.
 array_autoptr (const array_autoptr< T > &that)
 Copies the array_autoptr and takes ownership of the array the original pointed to.
 ~array_autoptr ()
 Destroys the array_autoptr and calls delete [] on the array pointed to.
T * release ()
 Returns a pointer to the owned array, relinquishing ownership of the pointed to array.
T * get ()
 Returns a pointer to the owned array, but does not relinquish ownership.

Detailed Description

template<typename T>
class jsplib::array_autoptr< T >

a template which emulates the operation and semantics of std::auto_ptr but works with arrays only

boost::scoped_array may not be suitable because it is noncopyable and doesn't have a release method. boost::shared_array is overkill. Use of std::vector and std::auto_ptr is recommended in many cases over a dynamically created array, but sometimes this is a better idea. jsplib::array_autoptr is useful when implementing exception safety - create at start of function and release at the end after anything to throw.


Constructor & Destructor Documentation

template<typename T>
jsplib::array_autoptr< T >::array_autoptr ( const array_autoptr< T > &  that  )  [inline]

Copies the array_autoptr and takes ownership of the array the original pointed to.

post-conditon: The original is set to a null pointer


Member Function Documentation

template<typename T>
T* jsplib::array_autoptr< T >::get (  )  [inline]

Returns a pointer to the owned array, but does not relinquish ownership.

On destruction of this object the array will still be deleted [] unless release is called before destruction

template<typename T>
T* jsplib::array_autoptr< T >::release (  )  [inline]

Returns a pointer to the owned array, relinquishing ownership of the pointed to array.

The array is not deleted [] on release and the array_autoptr is initialised to a null pointer


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator