Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Compound Members   Related Pages  

CCfits::FITSUtil::auto_array_ptr Class Template Reference

A class that mimics the std:: library auto_ptr class, but works with arrays. More...

#include <FITSUtil.h>

List of all members.

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 ()
operator[] (size_t i) const throw ()
X* get () const
X* release () throw ()
X* reset (X *p) throw ()

Static Public Methods

void remove (X *&x)


Detailed Description

template<typename X> class CCfits::FITSUtil::auto_array_ptr

A class that mimics the std:: library auto_ptr class, but works with arrays.

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 & Destructor Documentation

template<typename X>
CCfits::FITSUtil::auto_array_ptr< X >::auto_array_ptr<X> ( X * p = 0 ) throw () [explicit]
 

constructor. allows creation of pointer to null, can be modified by reset().

template<typename X>
CCfits::FITSUtil::auto_array_ptr< X >::auto_array_ptr<X> ( auto_array_ptr< X > & right ) throw () [explicit]
 

copy constructor.

template<typename X>
CCfits::FITSUtil::auto_array_ptr< X >::~auto_array_ptr<X> ( )
 

destructor.


Member Function Documentation

template<typename X>
X * CCfits::FITSUtil::auto_array_ptr< X >::get ( ) const
 

return a token for the underlying content of *this.

template<typename X>
X & CCfits::FITSUtil::auto_array_ptr< X >::operator * ( ) throw ()
 

deference operator.

template<typename X>
void CCfits::FITSUtil::auto_array_ptr< X >::operator= ( auto_array_ptr< X > & right )
 

assignment operator: transfer of ownership semantics.

template<typename X>
X CCfits::FITSUtil::auto_array_ptr< X >::operator[] ( size_t i ) const throw ()
 

return a copy of the ith element of the array.

template<typename X>
X & CCfits::FITSUtil::auto_array_ptr< X >::operator[] ( size_t i ) throw ()
 

return a reference to the ith element of the array.

template<typename X>
X * CCfits::FITSUtil::auto_array_ptr< X >::release ( ) throw ()
 

return underlying content of *this, transferring memory ownership.

template<typename X>
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.

template<typename X>
X * CCfits::FITSUtil::auto_array_ptr< X >::reset ( X * p ) throw ()
 

change the content of the auto_array_ptr to p.


The documentation for this class was generated from the following file:
Generated at Fri Apr 11 16:05:09 2003 for CCfits by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001