#include <FITSUtil.h>
Public Methods | |
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 Methods | |
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.
|
constructor. allows creation of pointer to null, can be modified by reset().
|
|
copy constructor.
|
|
destructor.
|
|
return a token for the underlying content of *this.
|
|
deference operator.
|
|
assignment operator: transfer of ownership semantics.
|
|
return a copy of the ith element of the array.
|
|
return a reference to the ith element of the array.
|
|
return underlying content of *this, transferring memory ownership.
|
|
utility function to delete the memory owned by x and set it to null.
|
|
change the content of the auto_array_ptr to p.
|