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) Lumiera.org
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
45 #ifndef CONTROL_COMMAND_MUTATION_H
46 #define CONTROL_COMMAND_MUTATION_H
47 
48 #include "lib/error.hpp"
51 
52 
53 
54 namespace steam {
55 namespace control {
56  namespace err = lumiera::error;
57 
58 
66  class Mutation
67  {
68  const CmdFunctor func_;
69 
70  public:
71  template<typename SIG>
72  Mutation (function<SIG> const& func)
73  : func_(func)
74  { }
75 
76 
77 
78  void
79  operator() (CmdClosure& clo)
80  {
81  if (!clo)
82  throw err::State{"Lifecycle error: function arguments not ready"
83  , LERR_(UNBOUND_ARGUMENTS)};
84  clo.invoke (func_);
85  }
86  };
87 
88 
89 
90 
91 
92 
93 
94 
95 
109  : public Mutation
110  {
111  Mutation captureMemento_;
112 
113  public:
114  template<typename SIG, typename MEM>
115  UndoMutation (MementoTie<SIG,MEM> & mementoHolder)
116  : Mutation (mementoHolder.tieUndoFunc())
117  , captureMemento_(mementoHolder.tieCaptureFunc())
118  { }
119 
120 
121  Mutation&
122  captureState (CmdClosure& clo)
123  {
124  if (!clo)
125  throw err::State{"need additional function arguments to be able to capture UNDO state"
126  , LERR_(UNBOUND_ARGUMENTS)};
127 
128  captureMemento_(clo);
129  return *this;
130  }
131 
132 
133  };
134 
135 
136 }} // namespace steam::control
137 #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:199
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:88