Zero  0.1.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
guard< T > Class Template Reference

A generic RAII guard class. More...

#include <guard.h>

Public Member Functions

 guard (T *ptr=nullptr)
 
 guard (guard &other)
 
 guard (guard const &)
 
guardoperator= (const guard &)
 
guardoperator= (guard &other)
 
guardoperator= (T *ptr)
 
 operator T* ()
 
 operator T const * () const
 
Toperator* ()
 
T const & operator* () const
 
Toperator-> ()
 
T const * operator-> () const
 
Tget ()
 
T const * get () const
 
Trelease ()
 Notifies this guard that its services are no longer needed because some other entity has assumed ownership of the pointer. More...
 
void done ()
 Notifies this guard that its action should be performed now rather than at destruct time. More...
 
 ~guard ()
 

Private Member Functions

void action (T *ptr)
 
void assign (T *ptr)
 
template<>
void action (FILE *ptr)
 

Private Attributes

T_ptr
 

Detailed Description

template<typename T>
class guard< T >

A generic RAII guard class.

This class ensures that the object it encloses will be properly disposed of when it goes out of scope, or with an explicit call to done(), whichever comes first.

This class is much like the auto_ptr class, other than allowing actions besides delete upon destruct. In particular it is NOT SAFE to use it in STL containers because it does not fulfill the Assignable concept.

TODO: make generic and configurable (ie, use templates to determine what "null" and "action" are)

Constructor & Destructor Documentation

§ guard() [1/3]

template<typename T>
guard< T >::guard ( T ptr = nullptr)
inline

§ guard() [2/3]

template<typename T>
guard< T >::guard ( guard< T > &  other)
inline

§ guard() [3/3]

template<typename T>
guard< T >::guard ( guard< T > const &  )

§ ~guard()

template<typename T>
guard< T >::~guard ( )
inline

Member Function Documentation

§ action() [1/2]

template<typename T>
void guard< T >::action ( T ptr)
inlineprivate

§ action() [2/2]

template<>
void guard< FILE >::action ( FILE *  ptr)
inlineprivate

§ assign()

template<typename T>
void guard< T >::assign ( T ptr)
inlineprivate

§ done()

template<typename T>
void guard< T >::done ( )
inline

Notifies this guard that its action should be performed now rather than at destruct time.

§ get() [1/2]

template<typename T>
T* guard< T >::get ( )
inline

§ get() [2/2]

template<typename T>
T const* guard< T >::get ( ) const
inline

§ operator T const *()

template<typename T>
guard< T >::operator T const * ( ) const
inline

§ operator T*()

template<typename T>
guard< T >::operator T* ( )
inline

§ operator*() [1/2]

template<typename T>
T& guard< T >::operator* ( )
inline

§ operator*() [2/2]

template<typename T>
T const& guard< T >::operator* ( ) const
inline

§ operator->() [1/2]

template<typename T>
T* guard< T >::operator-> ( )
inline

§ operator->() [2/2]

template<typename T>
T const* guard< T >::operator-> ( ) const
inline

§ operator=() [1/3]

template<typename T>
guard& guard< T >::operator= ( const guard< T > &  )

§ operator=() [2/3]

template<typename T>
guard& guard< T >::operator= ( guard< T > &  other)
inline

§ operator=() [3/3]

template<typename T>
guard& guard< T >::operator= ( T ptr)
inline

§ release()

template<typename T>
T* guard< T >::release ( )
inline

Notifies this guard that its services are no longer needed because some other entity has assumed ownership of the pointer.

NOTE: this function is marked const so that the assignment operator and copy constructor can work properly.

Member Data Documentation

§ _ptr

template<typename T>
T* guard< T >::_ptr
private

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