40 #ifndef CONTROL_MEMENTO_TIE_H 41 #define CONTROL_MEMENTO_TIE_H 50 #include <boost/operators.hpp> 59 using boost::equality_comparable;
62 using lib::meta::equals_safeInvoke;
87 template<
typename SIG,
typename MEM>
89 :
public equality_comparable<MementoTie<SIG,MEM>>
91 typedef typename CommandSignature<SIG,MEM>::CaptureSig SIG_cap;
92 typedef typename CommandSignature<SIG,MEM>::UndoOp_Sig SIG_undo;
98 function<SIG_undo> undo_;
99 function<SIG_cap> capture_;
105 memento_ = mementoVal;
112 :
MementoTie (function<SIG_undo>(), function<SIG_cap>())
121 function<SIG_cap>
const& captureFunc)
125 , capture_(captureFunc)
150 return bindLast( undo_
163 return chained(capture_
164 ,[
this](MEM
const& mementoVal){
capture (mementoVal); }
176 throw err::State{
"need to invoke memento state capturing beforehand" 177 , LERR_(MISSING_MEMENTO)};
187 operator bool()
const 195 return undo_ && capture_ && isCaptured_;
199 operator std::string()
const;
204 template<
typename SIG,
typename MEM>
207 if (!undo_ || !capture_)
211 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.