Lumiera  0.pre.03
»edit your freedom«
command-mutation.hpp
Go to the documentation of this file.
1 /*
2  COMMAND-MUTATION.hpp - functor encapsulating the actual operation of steam-Command
3 
4  Copyright (C)
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
36 #ifndef CONTROL_COMMAND_MUTATION_H
37 #define CONTROL_COMMAND_MUTATION_H
38 
39 #include "lib/error.hpp"
42 
43 
44 
45 namespace steam {
46 namespace control {
47  namespace err = lumiera::error;
48 
49 
57  class Mutation
58  {
59  const CmdFunctor func_;
60 
61  public:
62  template<typename SIG>
63  Mutation (function<SIG> const& func)
64  : func_(func)
65  { }
66 
67 
68 
69  void
70  operator() (CmdClosure& clo)
71  {
72  if (!clo)
73  throw err::State{"Lifecycle error: function arguments not ready"
74  , LERR_(UNBOUND_ARGUMENTS)};
75  clo.invoke (func_);
76  }
77  };
78 
79 
80 
81 
82 
83 
84 
85 
86 
100  : public Mutation
101  {
102  Mutation captureMemento_;
103 
104  public:
105  template<typename SIG, typename MEM>
106  UndoMutation (MementoTie<SIG,MEM> & mementoHolder)
107  : Mutation (mementoHolder.tieUndoFunc())
108  , captureMemento_(mementoHolder.tieCaptureFunc())
109  { }
110 
111 
112  Mutation&
113  captureState (CmdClosure& clo)
114  {
115  if (!clo)
116  throw err::State{"need additional function arguments to be able to capture UNDO state"
117  , LERR_(UNBOUND_ARGUMENTS)};
118 
119  captureMemento_(clo);
120  return *this;
121  }
122 
123 
124  };
125 
126 
127 }} // namespace steam::control
128 #endif
function< SIG > tieCaptureFunc()
bind the capturing function to the internal memento store within this object.
function< SIG > tieUndoFunc()
bind the undo function to the internal memento store within this object.
Steam-Layer implementation namespace root.
Specialised version of the command Mutation functor, used to implement the UNDO functionality.
virtual void invoke(CmdFunctor const &)=0
invoke functor using the stored parameter values
A special binding used by Steam-Layer commands for capturing UNDO state information.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
Generic wrapper carrying a function object while hiding the actual function signature.
Unspecific command functor for implementing Steam-Layer Command.
Lumiera error handling (C++ interface).
A closure enabling self-contained execution of commands within the SteamDispatcher.
Binding together state capturing and execution of the undo operation.
Definition: memento-tie.hpp:79