The Original CHomP Software
Public Types | Public Member Functions | Private Attributes | List of all members
chomp::homology::auto_array< T > Class Template Reference

An auto_array template that mimics selected behaviors of the std::auto_ptr template, but releases the memory with delete[], and thus should be applied to arrays. More...

#include <autoarray.h>

Public Types

typedef T element_type
 The type of the elements in the array. More...
 

Public Member Functions

 auto_array (element_type *p=0) throw ()
 The constructor. More...
 
 auto_array (auto_array &a) throw ()
 Copy constructor. More...
 
auto_arrayoperator= (auto_array &a) throw ()
 Assignment operator. More...
 
 ~auto_array ()
 The destructor. More...
 
element_typeget () const throw ()
 Returns the internally stored pointer to an array. More...
 
element_typerelease () throw ()
 Releases the pointer and returns it. More...
 
void reset (element_type *p=0) throw ()
 Resets the object to hold another pointer. More...
 

Private Attributes

T * ptr
 

Detailed Description

template<typename T>
class chomp::homology::auto_array< T >

An auto_array template that mimics selected behaviors of the std::auto_ptr template, but releases the memory with delete[], and thus should be applied to arrays.

This template is based on what I found in the g++ header file "memory".

Definition at line 53 of file autoarray.h.

Member Typedef Documentation

◆ element_type

template<typename T >
typedef T chomp::homology::auto_array< T >::element_type

The type of the elements in the array.

Definition at line 60 of file autoarray.h.

Constructor & Destructor Documentation

◆ auto_array() [1/2]

template<typename T >
chomp::homology::auto_array< T >::auto_array ( element_type p = 0)
throw (
)
inlineexplicit

The constructor.

Definition at line 63 of file autoarray.h.

63: ptr (p) {}

◆ auto_array() [2/2]

template<typename T >
chomp::homology::auto_array< T >::auto_array ( auto_array< T > &  a)
throw (
)
inline

Copy constructor.

Definition at line 66 of file autoarray.h.

66: ptr (a. release ()) {}
element_type * release()
Releases the pointer and returns it.
Definition: autoarray.h:90

◆ ~auto_array()

template<typename T >
chomp::homology::auto_array< T >::~auto_array ( )
inline

The destructor.

Definition at line 76 of file autoarray.h.

77 {
78 if (ptr)
79 delete [] ptr;
80 return;
81 }

References chomp::homology::auto_array< T >::ptr.

Member Function Documentation

◆ get()

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

Returns the internally stored pointer to an array.

Definition at line 84 of file autoarray.h.

85 {
86 return ptr;
87 }

References chomp::homology::auto_array< T >::ptr.

◆ operator=()

template<typename T >
auto_array & chomp::homology::auto_array< T >::operator= ( auto_array< T > &  a)
throw (
)
inline

Assignment operator.

Definition at line 69 of file autoarray.h.

70 {
71 reset (a. release ());
72 return *this;
73 }
void reset(element_type *p=0)
Resets the object to hold another pointer.
Definition: autoarray.h:98

References chomp::homology::auto_array< T >::release(), and chomp::homology::auto_array< T >::reset().

◆ release()

template<typename T >
element_type * chomp::homology::auto_array< T >::release ( )
throw (
)
inline

Releases the pointer and returns it.

Definition at line 90 of file autoarray.h.

91 {
92 element_type *tmp = ptr;
93 ptr = 0;
94 return tmp;
95 }
T element_type
The type of the elements in the array.
Definition: autoarray.h:60

References chomp::homology::auto_array< T >::ptr.

Referenced by chomp::homology::auto_array< T >::operator=().

◆ reset()

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

Resets the object to hold another pointer.

Definition at line 98 of file autoarray.h.

99 {
100 if (p != ptr)
101 {
102 if (ptr)
103 delete [] ptr;
104 ptr = p;
105 }
106 }

References chomp::homology::auto_array< T >::ptr.

Referenced by chomp::homology::auto_array< T >::operator=().

Member Data Documentation

◆ ptr

template<typename T >
T* chomp::homology::auto_array< T >::ptr
private

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