31 #ifndef CONTROL_MEMENTO_TIE_H 32 #define CONTROL_MEMENTO_TIE_H 41 #include <boost/operators.hpp> 50 using boost::equality_comparable;
53 using lib::meta::equals_safeInvoke;
78 template<
typename SIG,
typename MEM>
80 :
public equality_comparable<MementoTie<SIG,MEM>>
82 typedef typename CommandSignature<SIG,MEM>::CaptureSig SIG_cap;
83 typedef typename CommandSignature<SIG,MEM>::UndoOp_Sig SIG_undo;
89 function<SIG_undo> undo_;
90 function<SIG_cap> capture_;
96 memento_ = mementoVal;
103 :
MementoTie (function<SIG_undo>(), function<SIG_cap>())
112 function<SIG_cap>
const& captureFunc)
116 , capture_(captureFunc)
141 return bindLast( undo_
154 return chained(capture_
155 ,[
this](MEM
const& mementoVal){
capture (mementoVal); }
167 throw err::State{
"need to invoke memento state capturing beforehand" 168 , LERR_(MISSING_MEMENTO)};
178 operator bool()
const 186 return undo_ && capture_ && isCaptured_;
190 operator std::string()
const;
195 template<
typename SIG,
typename MEM>
198 if (!undo_ || !capture_)
202 return "<mem:missing>";
function< SIG > tieCaptureFunc()
bind the capturing function to the internal memento store within this object.
helpers for fail-safe invocation of comparison operations from generic code.
function< SIG > tieUndoFunc()
bind the undo function to the internal memento store within this object.
Partial function application and building a complete function closure.
Steam-Layer implementation namespace root.
_PapE< SIG >::FunType::Functor bindLast(SIG &f, TERM const &arg)
bind the last function argument to an arbitrary term, which especially might be a (nested) binder...
Derived specific exceptions within Lumiera's exception hierarchy.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
void capture(MEM const &mementoVal)
to be chained behind the capture function
auto chained(FUN1 &&f1, FUN2 &&f2)
build a functor chaining the given functions: feed the result of f1 into f2.
void clear()
reverses the effect of capturing state and returns this memento holder into pristine state ...
Adapter container to take snapshots from non-assignable values.
MementoTie(function< SIG_undo > const &undoFunc, function< SIG_cap > const &captureFunc)
creates an execution context tying together the provided functions.
Metaprogramming helpers for deriving the precise function signatures necessary to implement a given c...
ReplaceableItem< MEM > memento_
storage holding the captured state for undo
MEM & getState()
access the currently captured memento state value
Adapter wrapper to treat non-assignable values as if they were assignable.
Binding together state capturing and execution of the undo operation.