Lumiera
0.pre.03
»edit your freedom«
|
#include "steam/control/memento-tie.hpp"
Binding together state capturing and execution of the undo operation.
MementoTie itself is a passive container object with a very specific type, depending on the type of the operation arguments and the type of the memento. It is to be allocated within the StorageHolder of the command, thereby wrapping the undo and capture function, setting up the necessary bindings and closures for allowing them to cooperate behind the scenes to carry out the UNDO functionality. On construction, the UndoMutation functor retrieves the wired up functions, storing them into generic containers (type erasure) for later invocation.
More specifically, the captureFunction
, which is expected to run immediately prior to the actual command operation, returns a memento value object (of unspecific type), which needs to be stored within the MementoTie. On UNDO, the undo-operation functor needs to be provided with a reference to this stored memento value through an additional parameter (which by convention is always the last argument of the undo function).
this
implicitly.SIG | signature of the command operation |
MEM | type of the memento state to capture. Needs to be default constructible and copyable |
Definition at line 79 of file memento-tie.hpp.
Public Member Functions | |
MementoTie (function< SIG_undo > const &undoFunc, function< SIG_cap > const &captureFunc) | |
creates an execution context tying together the provided functions. More... | |
void | clear () |
reverses the effect of capturing state and returns this memento holder into pristine state | |
MEM & | getState () |
access the currently captured memento state value More... | |
bool | isValid () const |
operator bool () const | |
conversion to bool() yields true if all functions are usable and memento state has been captured | |
operator std::string () const | |
for diagnostics: include format-util.hpp | |
function< SIG > | tieCaptureFunc () |
bind the capturing function to the internal memento store within this object. More... | |
function< SIG > | tieUndoFunc () |
bind the undo function to the internal memento store within this object. More... | |
Private Types | |
typedef CommandSignature< SIG, MEM >::CaptureSig | SIG_cap |
typedef CommandSignature< SIG, MEM >::UndoOp_Sig | SIG_undo |
Private Member Functions | |
void | capture (MEM const &mementoVal) |
to be chained behind the capture function | |
Private Attributes | |
function< SIG_cap > | capture_ |
bool | isCaptured_ |
ReplaceableItem< MEM > | memento_ |
storage holding the captured state for undo | |
function< SIG_undo > | undo_ |
|
inline |
creates an execution context tying together the provided functions.
Bound copies of these functors may be pulled from the MementoTie, in order to build the closures (with the concrete operation arguments) to be invoked later on command execution.
Definition at line 111 of file memento-tie.hpp.
|
inline |
bind the undo function to the internal memento store within this object.
Definition at line 137 of file memento-tie.hpp.
References MementoTie< SIG, MEM >::getState().
|
inline |
bind the capturing function to the internal memento store within this object.
Definition at line 152 of file memento-tie.hpp.
References MementoTie< SIG, MEM >::capture().
|
inline |
access the currently captured memento state value
when | the capturing function wasn't yet invoked |
Definition at line 164 of file memento-tie.hpp.
Referenced by MementoTie< SIG, MEM >::tieUndoFunc().