Serial-TCP/IPbridge  1.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
auto_array< T > Class Template Reference

Limited version of std::auto_ptr for dynamic arrays. More...

#include <auto_array.h>

Public Member Functions

 auto_array (T *p=0) throw ()
 Constructs an auto_array object from an array pointer. More...
 
 ~auto_array () throw ()
 Deallocates the block of memory the object "points to" using delete[] and destructs the object. More...
 
T * get () const throw ()
 Returns the stored pointer. More...
 
T * release () throw ()
 Returns the stored pointer and sets the internal pointer to 0. More...
 
void reset (T *p=0) throw ()
 Deallocates the array that the auto_array points to and sets a new value. More...
 

Private Member Functions

 auto_array (auto_array &a) throw ()
 
template<class Y >
 auto_array (auto_array< Y > &a) throw ()
 
T & operator* () const throw ()
 
T * operator-> () const throw ()
 
auto_arrayoperator= (auto_array &a) throw ()
 
template<class Y >
auto_arrayoperator= (auto_array< Y > &a) throw ()
 
template<class Y >
 operator auto_array< Y > () throw ()
 

Private Attributes

T * _p
 Stored pointer. More...
 

Detailed Description

template<typename T>
class auto_array< T >

Limited version of std::auto_ptr for dynamic arrays.

As you know, one cannot use std::auto_ptr for storing dynamic arrays because std::auto_ptr calls delete instead of delete[] in its destructor. This version provides the same functinality for dynamic arrays.

Todo:
Only a limited support is currently available, so add the rest of the functionality that is provided by the std::auto_ptr template class.

Constructor & Destructor Documentation

template<typename T>
auto_array< T >::auto_array ( T *  p = 0)
throw (
)
inlineexplicit

Constructs an auto_array object from an array pointer.

Parameters
pPointer to a dynamically allocated array. If this parameter is 0 the auto_array is a null pointer (points to nowhere).
template<typename T>
auto_array< T >::~auto_array ( )
throw (
)
inline

Deallocates the block of memory the object "points to" using delete[] and destructs the object.

References auto_array< T >::_p.

template<typename T>
auto_array< T >::auto_array ( auto_array< T > &  a)
throw (
)
private
template<typename T>
template<class Y >
auto_array< T >::auto_array ( auto_array< Y > &  a)
throw (
)
private

Member Function Documentation

template<typename T>
T* auto_array< T >::get ( ) const
throw (
)
inline

Returns the stored pointer.

Returns
Pointer to the array pointed by the auto_array object, if any, or zero if it does not point to any array.

References auto_array< T >::_p.

template<typename T>
template<class Y >
auto_array< T >::operator auto_array< Y > ( )
throw (
)
private
template<typename T>
T& auto_array< T >::operator* ( ) const
throw (
)
private
template<typename T>
T* auto_array< T >::operator-> ( ) const
throw (
)
private
template<typename T>
auto_array& auto_array< T >::operator= ( auto_array< T > &  a)
throw (
)
private
template<typename T>
template<class Y >
auto_array& auto_array< T >::operator= ( auto_array< Y > &  a)
throw (
)
private
template<typename T>
T* auto_array< T >::release ( )
throw (
)
inline

Returns the stored pointer and sets the internal pointer to 0.

Returns
Pointer to the array pointed by the auto_array object, if any, or zero if it does not point to any array.

Sets the auto_array internal pointer to null pointer (which indicates it points to no array) without destructing the array currently pointed by the auto_array.

References auto_array< T >::_p.

template<typename T>
void auto_array< T >::reset ( T *  p = 0)
throw (
)
inline

Deallocates the array that the auto_array points to and sets a new value.

Destructs the array pointed by the auto_array object, if any, and deallocates its memory (by calling operator delete[]). If a value for p is specified, the internal pointer is initialized to that value (otherwise it is set to the null pointer).

References auto_array< T >::_p.

Member Data Documentation

template<typename T>
T* auto_array< T >::_p
private

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