fesa-core
5.0.1
|
#include <Wrappers.h>
Public Member Functions | |
PointerWrapper () | |
PointerWrapper (T *value, CallbackType callback=CallbackType()) | |
PointerWrapper (const PointerWrapper &other) | |
PointerWrapper & | operator= (const PointerWrapper &other) |
T * | operator-> () |
void | reset () |
bool | isValid () const |
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.
fesa::wrappers::PointerWrapper< T, CallbackType >::PointerWrapper | ( | ) |
Creates an instance in an invalid state.
fesa::wrappers::PointerWrapper< T, CallbackType >::PointerWrapper | ( | T * | value, |
CallbackType | callback = CallbackType() |
||
) |
Creates an instance which wraps value.
fesa::wrappers::PointerWrapper< T, CallbackType >::PointerWrapper | ( | const PointerWrapper< T, CallbackType > & | other | ) |
Copy constructor. Sets other to an invalid state.
bool fesa::wrappers::PointerWrapper< T, CallbackType >::isValid | ( | ) | const |
T * fesa::wrappers::PointerWrapper< T, CallbackType >::operator-> | ( | ) |
Access the underlying data.
std::runtime_error | if this instance is not in a valid state (i.e. already reset, or initialized without a value) |
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.
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.