Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/classcasa_1_1SPtrHolder.html
Дата изменения: Unknown
Дата индексирования: Mon Feb 14 21:37:36 2011
Кодировка:

Поисковые слова: annular solar eclipse
casacore: casa::SPtrHolder< T > Class Template Reference
Public Member Functions | Private Member Functions | Private Attributes

casa::SPtrHolder< T > Class Template Reference
[Utilities_module]

Hold and delete pointers not deleted by object destructors. More...

#include <PtrHolder.h>

List of all members.

Public Member Functions

 SPtrHolder (T *ptr=0)
 Construct an SPtrHolder from a pointer which MUST have been allocated from new, since the destructor will After the pointer is placed into the holder, the user should not manually delete the pointer unless the transfer function is called.
 ~SPtrHolder ()
void reset (T *ptr)
 Reset the pointer.
T * transfer ()
 Transfer ownership of the pointer.
void release ()
 Release the pointer.
T & operator* ()
 Make it possible to dereference the pointer object.
const T & operator* () const
T * operator-> ()
 Make it possible to use -> on the pointer object.
const T * operator-> () const
T * ptr ()
 Get the pointer for use.
const T * ptr () const

Private Member Functions

 SPtrHolder (const SPtrHolder< T > &other)
 SPrtHolder cannot be copied.
SPtrHolder< T > & operator= (const SPtrHolder< T > &other)

Private Attributes

T * itsPtr

Detailed Description

template<class T>
class casa::SPtrHolder< T >

Hold and delete pointers not deleted by object destructors.

Intended use:

Public interface

Review Status

Test programs:
tPtrHolder

Prerequisite

Synopsis

SPtrHolders hold allocated pointers to non-array objects which should be deleted when an exception is thrown. SPtrHolder is similar to PtrHolder, but easier to use and only valid for pointer to a single object, thus not to a C-array of objects.

Example

       void func(Table *ptr); // some other function that takes a pointer
       // ..\.
       // True below means it's an array, False (the default) would mean
       // a singleton object.
       SPtrHolder<Int> iholder(new Table(...));
       func(iholder);                           // converts automatically to ptr
       Table* tab = iholder.transfer();         // transfer ownership

If an exception is thrown in function func, the Table will be deleted automatically. After the function call, the ownership is tranfered back to the 'user'

Motivation

std::autoptr is harder to use and its future is unclear.
PtrHolder is not fully inlined and has C-array overhead. Furthermore the automatic conversion to a T* is dangerous, because the programmer may not be aware that the pointer is maybe taken over.

Definition at line 194 of file PtrHolder.h.


Constructor & Destructor Documentation

template<class T>
casa::SPtrHolder< T >::SPtrHolder ( T *  ptr = 0  )  [inline, explicit]

Construct an SPtrHolder from a pointer which MUST have been allocated from new, since the destructor will After the pointer is placed into the holder, the user should not manually delete the pointer unless the transfer function is called.

The pointer must also only be put into one holder to avoid double deletion.

Definition at line 203 of file PtrHolder.h.

template<class T>
casa::SPtrHolder< T >::~SPtrHolder (  )  [inline]

Definition at line 206 of file PtrHolder.h.

References casa::SPtrHolder< T >::itsPtr.

template<class T>
casa::SPtrHolder< T >::SPtrHolder ( const SPtrHolder< T > &  other  )  [private]

SPrtHolder cannot be copied.


Member Function Documentation

template<class T>
T& casa::SPtrHolder< T >::operator* (  )  [inline]

Make it possible to dereference the pointer object.

Definition at line 224 of file PtrHolder.h.

References casa::SPtrHolder< T >::itsPtr.

template<class T>
const T& casa::SPtrHolder< T >::operator* (  )  const [inline]

Definition at line 226 of file PtrHolder.h.

References casa::SPtrHolder< T >::itsPtr.

template<class T>
T* casa::SPtrHolder< T >::operator-> (  )  [inline]

Make it possible to use -> on the pointer object.

Definition at line 232 of file PtrHolder.h.

References casa::SPtrHolder< T >::itsPtr.

template<class T>
const T* casa::SPtrHolder< T >::operator-> (  )  const [inline]

Definition at line 234 of file PtrHolder.h.

References casa::SPtrHolder< T >::itsPtr.

template<class T>
SPtrHolder<T>& casa::SPtrHolder< T >::operator= ( const SPtrHolder< T > &  other  )  [private]
template<class T>
T* casa::SPtrHolder< T >::ptr (  )  [inline]

Get the pointer for use.

Definition at line 240 of file PtrHolder.h.

References casa::SPtrHolder< T >::itsPtr.

Referenced by casa::SPtrHolder< T >::transfer().

template<class T>
const T* casa::SPtrHolder< T >::ptr (  )  const [inline]

Definition at line 242 of file PtrHolder.h.

References casa::SPtrHolder< T >::itsPtr.

template<class T>
void casa::SPtrHolder< T >::release (  )  [inline]

Release the pointer.

Definition at line 219 of file PtrHolder.h.

References casa::SPtrHolder< T >::itsPtr.

template<class T>
void casa::SPtrHolder< T >::reset ( T *  ptr  )  [inline]

Reset the pointer.

Definition at line 210 of file PtrHolder.h.

References casa::SPtrHolder< T >::itsPtr.

template<class T>
T* casa::SPtrHolder< T >::transfer (  )  [inline]

Transfer ownership of the pointer.

I.e. return the pointer and set it to 0 in the object.

Definition at line 215 of file PtrHolder.h.

References casa::SPtrHolder< T >::itsPtr, and casa::SPtrHolder< T >::ptr().


Member Data Documentation

template<class T>
T* casa::SPtrHolder< T >::itsPtr [private]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines