auto_array< _Tp > Class Template Reference

A simple smart array providing strict ownership semantics. More...

#include <ncutMemory.h>

List of all members.

Public Types

typedef _Tp element_type
 The pointed-to type.

Public Member Functions

 auto_array (element_type *__p=0) throw ()
 An auto_array is usually constructed from a raw array.
 auto_array (auto_array &__a) throw ()
 An auto_array can be constructed from another auto_array.
template<typename _Tp1>
 auto_array (auto_array< _Tp1 > &__a) throw ()
 An auto_array can be constructed from another auto_array.
auto_arrayoperator= (auto_array &__a) throw ()
 auto_array assignment operator.
template<typename _Tp1>
auto_arrayoperator= (auto_array< _Tp1 > &__a) throw ()
 auto_array assignment operator.
 ~auto_array ()
element_typeoperator[] (unsigned int i) const throw ()
 Smart array element access.
element_typeoperator * () const throw ()
 Smart array dereferencing.
element_typeoperator-> () const throw ()
 Smart array dereferencing.
element_typeget () const throw ()
 Bypassing the smart array.
element_typerelease () throw ()
 Bypassing the smart array.
void reset (element_type *__p=0) throw ()
 Forcibly deletes the managed array.
 auto_array (auto_array_ref< element_type > __ref) throw ()
 Automatic conversions.
auto_arrayoperator= (auto_array_ref< element_type > __ref) throw ()
template<typename _Tp1>
 operator auto_array_ref () throw ()
template<typename _Tp1>
 operator auto_array () throw ()


Detailed Description

template<typename _Tp>
class auto_array< _Tp >

A simple smart array providing strict ownership semantics.

An auto_array owns the array it holds a pointer to. Copying an auto_array copies the pointer and transfers ownership to the destination. If more than one auto_array owns the same array at the same time the behavior of the program is undefined.

The uses of auto_array include providing temporary exception-safety for dynamically allocated memory, passing ownership of dynamically allocated memory to a function, and returning dynamically allocated memory from a function. auto_array does not meet the CopyConstructible and Assignable requirements for Standard Library container elements and thus instantiating a Standard Library container with an auto_array results in undefined behavior.


Constructor & Destructor Documentation

template<typename _Tp>
auto_array< _Tp >::auto_array element_type __p = 0  )  throw () [inline, explicit]
 

An auto_array is usually constructed from a raw array.

Parameters:
__p A pointer (defaults to NULL).
This object now owns the array pointed to by p.

template<typename _Tp>
auto_array< _Tp >::auto_array auto_array< _Tp > &  __a  )  throw () [inline]
 

An auto_array can be constructed from another auto_array.

Parameters:
__a Another auto_array of the same type.
This object now owns the object previously owned by a, which has given up ownsership.

template<typename _Tp>
template<typename _Tp1>
auto_array< _Tp >::auto_array auto_array< _Tp1 > &  __a  )  throw () [inline]
 

An auto_array can be constructed from another auto_array.

Parameters:
__a Another auto_array of a different but related type.
A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type.

This object now owns the object previously owned by a, which has given up ownsership.

template<typename _Tp>
auto_array< _Tp >::~auto_array  )  [inline]
 

When the auto_array goes out of scope, the object it owns is deleted. If it no longer owns anything (i.e., get() is NULL), then this has no effect.

The C++ standard says there is supposed to be an empty throw specification here, but omitting it is standard conforming. Its presence can be detected only if _Tp::~_Tp() throws, but this is prohibited. [17.4.3.6]/2

template<typename _Tp>
auto_array< _Tp >::auto_array auto_array_ref< element_type __ref  )  throw () [inline]
 

Automatic conversions.

These operations convert an auto_array into and from an auto_arary_ref automatically as needed. This allows constructs such as

    auto_array<Derived>  func_returning_auto_array(.....);
    ...
    auto_array<Base> ptr = func_returning_auto_array(.....);


Member Function Documentation

template<typename _Tp>
element_type* auto_array< _Tp >::get  )  const throw () [inline]
 

Bypassing the smart array.

Returns:
The raw pointer being managed.
You can get a copy of the pointer that this object owns, for situations such as passing to a function which only accepts a raw pointer.

Note:
This auto_array still owns the memory.

template<typename _Tp>
element_type& auto_array< _Tp >::operator *  )  const throw () [inline]
 

Smart array dereferencing.

If this auto_array no longer owns anything, then this operation will crash. (For a smart pointer, "no longer owns anything" is the same as being a null pointer, and you know what happens when you dereference one of those...)

template<typename _Tp>
element_type* auto_array< _Tp >::operator->  )  const throw () [inline]
 

Smart array dereferencing.

This returns the pointer itself, which the language then will automatically cause to be dereferenced.

template<typename _Tp>
template<typename _Tp1>
auto_array& auto_array< _Tp >::operator= auto_array< _Tp1 > &  __a  )  throw () [inline]
 

auto_array assignment operator.

Parameters:
__a Another auto_array of a different but related type.
A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type.

This object now owns the object previously owned by a, which has given up ownsership. The object that this one used to own and track has been deleted.

template<typename _Tp>
auto_array& auto_array< _Tp >::operator= auto_array< _Tp > &  __a  )  throw () [inline]
 

auto_array assignment operator.

Parameters:
__a Another auto_array of the same type.
This object now owns the object previously owned by a, which has given up ownsership. The object that this one used to own and track has been deleted.

template<typename _Tp>
element_type& auto_array< _Tp >::operator[] unsigned int  i  )  const throw () [inline]
 

Smart array element access.

If this auto_array no longer owns anything, then this operation will crash. (For a smart pointer, "no longer owns anything" is the same as being a null pointer, and you know what happens when you dereference one of those...)

template<typename _Tp>
element_type* auto_array< _Tp >::release  )  throw () [inline]
 

Bypassing the smart array.

Returns:
The raw pointer being managed.
You can get a copy of the pointer that this object owns, for situations such as passing to a function which only accepts a raw pointer.

Note:
This auto_array no longer owns the memory. When this object goes out of scope, nothing will happen.

template<typename _Tp>
void auto_array< _Tp >::reset element_type __p = 0  )  throw () [inline]
 

Forcibly deletes the managed array.

Parameters:
__p A pointer (defaults to NULL).
This object now owns the object pointed to by p. The previous object has been deleted.


The documentation for this class was generated from the following file:
Generated on Thu Jun 22 14:47:20 2006 for ncut.kdevelop by  doxygen 1.4.6