Zero  0.1.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
guard_base_t< T, Impl > Class Template Reference

A generic pointer guard base class. An action will be performed exactly once on the stored pointer, either with an explicit call to done() or when the guard goes out of scope, whichever comes first. More...

#include <guard.h>

Inheritance diagram for guard_base_t< T, Impl >:
pointer_guard_base_t< void *, array_guard_t< void * > > array_guard_t< void *>

Public Types

typedef guard_base_t< T, Impl > Base
 

Public Member Functions

 guard_base_t (T obj)
 
 guard_base_t (const guard_base_t &other)
 
guard_base_toperator= (const guard_base_t &other)
 
 operator T () const
 
T get () const
 
T release () const
 Notifies this guard that its services are no longer needed because some other entity has assumed ownership of the pointer. More...
 
void done () const
 Notifies this guard that its action should be performed now rather than at destruct time. More...
 
 ~guard_base_t ()
 

Static Public Member Functions

static T null_value ()
 
static bool different (const T &a, const T &b)
 

Protected Member Functions

void assign (T obj) const
 

Protected Attributes

T _obj
 

Detailed Description

template<class T, class Impl>
class guard_base_t< T, Impl >

A generic pointer guard base class. An action will be performed exactly once on the stored pointer, either with an explicit call to done() or when the guard goes out of scope, 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.

This class DOES NOT support being cast as "const" in the traditional sense. Other than disallowing use of the assignment operator '=' it always allows modification of its contents so that it do its job properly. This should not be a problem in practice because a "const T" (with T = <pointer to="" some="" type>="">, eg int*) does not actually protect a pointer's contents from modification anyway. Use T = <pointer to="" some="" const="" type>=""> for that, eg const int*.

Member Typedef Documentation

§ Base

template<class T, class Impl>
typedef guard_base_t<T, Impl> guard_base_t< T, Impl >::Base

Constructor & Destructor Documentation

§ guard_base_t() [1/2]

template<class T, class Impl>
guard_base_t< T, Impl >::guard_base_t ( T  obj)
inline

§ guard_base_t() [2/2]

template<class T, class Impl>
guard_base_t< T, Impl >::guard_base_t ( const guard_base_t< T, Impl > &  other)
inline

§ ~guard_base_t()

template<class T, class Impl>
guard_base_t< T, Impl >::~guard_base_t ( )
inline

Member Function Documentation

§ assign()

template<class T, class Impl>
void guard_base_t< T, Impl >::assign ( T  obj) const
inlineprotected

§ different()

template<class T, class Impl>
static bool guard_base_t< T, Impl >::different ( const T a,
const T b 
)
inlinestatic

§ done()

template<class T, class Impl>
void guard_base_t< T, Impl >::done ( ) const
inline

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

§ get()

template<class T, class Impl>
T guard_base_t< T, Impl >::get ( ) const
inline

§ null_value()

template<class T, class Impl>
static T guard_base_t< T, Impl >::null_value ( )
inlinestatic

§ operator T()

template<class T, class Impl>
guard_base_t< T, Impl >::operator T ( ) const
inline

§ operator=()

template<class T, class Impl>
guard_base_t& guard_base_t< T, Impl >::operator= ( const guard_base_t< T, Impl > &  other)
inline

§ release()

template<class T, class Impl>
T guard_base_t< T, Impl >::release ( ) const
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

§ _obj

template<class T, class Impl>
T guard_base_t< T, Impl >::_obj
mutableprotected

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