fesa-core  4.3.1
fesa::wrappers::PointerWrapper< T, CallbackType > Class Template Reference

#include <Wrappers.h>

Public Member Functions

 PointerWrapper ()
 
 PointerWrapper (T *value, CallbackType callback=CallbackType())
 
 PointerWrapper (const PointerWrapper &other)
 
PointerWrapperoperator= (const PointerWrapper &other)
 
T * operator-> ()
 
void reset ()
 
bool isValid () const
 

Detailed Description

template<typename T, typename CallbackType>
class fesa::wrappers::PointerWrapper< T, CallbackType >

Wrapper on a pointer of type T, with an optional callback called on destruction or explicit reset. This class acts like an std::auto_ptr, but the pointed object is never deleted; the only action is to call the callback. Passing an instance of a PointerWrapper to the copy constructor or the assignment operator of another instance makes it invalid, e.g.: PointerWrapper a(&someValue); PointerWrapper b = a; // a is invalid after this line; trying to access the value throws. PointerWrapper c(b); // b is invalid after this line; trying to access the value throws.

Constructor & Destructor Documentation

template<typename T , typename CallbackType >
fesa::wrappers::PointerWrapper< T, CallbackType >::PointerWrapper ( )

Creates an instance in an invalid state.

template<typename T , typename CallbackType >
fesa::wrappers::PointerWrapper< T, CallbackType >::PointerWrapper ( T *  value,
CallbackType  callback = CallbackType() 
)

Creates an instance which wraps value.

template<typename T , typename CallbackType >
fesa::wrappers::PointerWrapper< T, CallbackType >::PointerWrapper ( const PointerWrapper< T, CallbackType > &  other)

Copy constructor. Sets other to an invalid state.

Member Function Documentation

template<typename T , typename CallbackType >
bool fesa::wrappers::PointerWrapper< T, CallbackType >::isValid ( ) const
Returns
true if this instance is in a valid state.
template<typename T , typename CallbackType >
T * fesa::wrappers::PointerWrapper< T, CallbackType >::operator-> ( )

Access the underlying data.

Exceptions
std::runtime_errorif this instance is not in a valid state (i.e. already reset, or initialized without a value)
template<typename T , typename CallbackType >
PointerWrapper< T, CallbackType > & fesa::wrappers::PointerWrapper< T, CallbackType >::operator= ( const PointerWrapper< T, CallbackType > &  other)

If this instance is in a valid state, callback is called; then it is overwritten with data from other. Sets other to an invalid state.

template<typename T , typename CallbackType >
void fesa::wrappers::PointerWrapper< T, CallbackType >::reset ( )

If this instance is in a valid state, the callback is called, and the instance is set to an invalid state. Any exception thrown by the callback function is propagated. If this instance is not in a valid state, nothing happens.


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