Lumiera  0.pre.03
»edit your freedom«
MementoTie< SIG, MEM > Class Template Reference

#include "steam/control/memento-tie.hpp"

Description

template<typename SIG, typename MEM>
class steam::control::MementoTie< SIG, MEM >

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).

Warning
take care of the MementoTie storage location, as the bound functions returned by tieCaptureFunc and tieUndoFunc refer to this implicitly.
Parameters
SIGsignature of the command operation
MEMtype of the memento state to capture. Needs to be default constructible and copyable

Definition at line 88 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_
 

Constructor & Destructor Documentation

◆ MementoTie()

MementoTie ( function< SIG_undo > const &  undoFunc,
function< SIG_cap > const &  captureFunc 
)
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 120 of file memento-tie.hpp.

Member Function Documentation

◆ tieUndoFunc()

function<SIG> tieUndoFunc ( )
inline

bind the undo function to the internal memento store within this object.

Returns
a functor, which, when invoked with the remaining arguments, will automatically call getState() to retrieve the current memento value.
Note
similar to getState(), the returned functor will throw when the state capturing wasn't yet invoked

Definition at line 146 of file memento-tie.hpp.

References MementoTie< SIG, MEM >::getState().

+ Here is the call graph for this function:

◆ tieCaptureFunc()

function<SIG> tieCaptureFunc ( )
inline

bind the capturing function to the internal memento store within this object.

Returns
a functor, which on invocation will automatically store the return value of the capturing function (= the current memento value) into the field memento_ within this object

Definition at line 161 of file memento-tie.hpp.

References MementoTie< SIG, MEM >::capture().

+ Here is the call graph for this function:

◆ getState()

MEM& getState ( )
inline

access the currently captured memento state value

Exceptions
whenthe capturing function wasn't yet invoked

Definition at line 173 of file memento-tie.hpp.

Referenced by MementoTie< SIG, MEM >::tieUndoFunc().

+ Here is the caller graph for this function:
+ Inheritance diagram for MementoTie< SIG, MEM >:
+ Collaboration diagram for MementoTie< SIG, MEM >:

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