#include <FITSUtil.h>
Public Member Functions | |
auto_array_ptr (X *p=0) throw () | |
auto_array_ptr (auto_array_ptr< X > &right) throw () | |
~auto_array_ptr () | |
void | operator= (auto_array_ptr< X > &right) |
X & | operator * () throw () |
X & | operator[] (size_t i) throw () |
X | operator[] (size_t i) const throw () |
X * | get () const |
X * | release () throw () |
X * | reset (X *p) throw () |
Static Public Member Functions | |
static void | remove (X *&x) |
This code was written by Jack Reeves and first appeared C++ Report, March 1996 edition. Although some authors think one shouldn't need such a contrivance, there seems to be a need for it when wrapping C code.
Usage: replace
float* f = new float[200];
with
FITSUtil::auto_array_ptr<float> f(new float[200]);
Then the memory will be managed correctly in the presence of exceptions, and delete will be called automatically for f when leaving scope.
CCfits::FITSUtil::auto_array_ptr< X >::auto_array_ptr | ( | X * | p = 0 |
) | throw () [explicit] |
constructor. allows creation of pointer to null, can be modified by reset()
CCfits::FITSUtil::auto_array_ptr< X >::auto_array_ptr | ( | auto_array_ptr< X > & | right | ) | throw () [explicit] |
copy constructor
CCfits::FITSUtil::auto_array_ptr< X >::~auto_array_ptr | ( | ) |
destructor.
X * CCfits::FITSUtil::auto_array_ptr< X >::get | ( | ) | const |
return a token for the underlying content of *this
X & CCfits::FITSUtil::auto_array_ptr< X >::operator * | ( | ) | throw () |
deference operator
void CCfits::FITSUtil::auto_array_ptr< X >::operator= | ( | auto_array_ptr< X > & | right | ) |
assignment operator: transfer of ownership semantics
X CCfits::FITSUtil::auto_array_ptr< X >::operator[] | ( | size_t | i | ) | const throw () |
return a copy of the ith element of the array
X & CCfits::FITSUtil::auto_array_ptr< X >::operator[] | ( | size_t | i | ) | throw () |
return a reference to the ith element of the array
X * CCfits::FITSUtil::auto_array_ptr< X >::release | ( | ) | throw () |
return underlying content of *this, transferring memory ownership
void CCfits::FITSUtil::auto_array_ptr< X >::remove | ( | X *& | x | ) | [static] |
utility function to delete the memory owned by x and set it to null.
X * CCfits::FITSUtil::auto_array_ptr< X >::reset | ( | X * | p | ) | throw () |
change the content of the auto_array_ptr to p