Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
command-mutation.hpp
Go to the documentation of this file.
1 /*
2  COMMAND-MUTATION.hpp - functor encapsulating the actual operation of proc-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 proc {
55 namespace control {
56 
57 
58 
66  class Mutation
67  {
69 
70  public:
71  template<typename SIG>
72  Mutation (function<SIG> const& func)
73  : func_(func)
74  { }
75 
76 
77 
78  void
80  {
81  if (!clo)
82  throw lumiera::error::State ("Lifecycle error: function arguments not ready",
83  LERR_(UNBOUND_ARGUMENTS));
84  clo.invoke (func_);
85  }
86 
87 
88 
90  friend bool
91  operator== (Mutation const& m1, Mutation const& m2)
92  {
93  return (m1.func_ == m2.func_);
94  }
95 
96  friend bool
97  operator!= (Mutation const& m1, Mutation const& m2)
98  {
99  return not (m1==m2);
100  }
101  };
102 
103 
104 
105 
106 
107 
108 
109 
110 
124  : public Mutation
125  {
127 
128  public:
129  template<typename SIG, typename MEM>
131  : Mutation (mementoHolder.tieUndoFunc())
132  , captureMemento_(mementoHolder.tieCaptureFunc())
133  { }
134 
135 
136  Mutation&
138  {
139  if (!clo)
140  throw lumiera::error::State ("need additional function arguments to be able to capture UNDO state",
141  LERR_(UNBOUND_ARGUMENTS));
142 
143  captureMemento_(clo);
144  return *this;
145  }
146 
147 
148  };
149 
150 
151 }} // namespace proc::control
152 #endif
Unspecific command functor for implementing Proc-Layer Command.
friend bool operator!=(Mutation const &m1, Mutation const &m2)
friend bool operator==(Mutation const &m1, Mutation const &m2)
Supporting equality comparisons...
UndoMutation(MementoTie< SIG, MEM > &mementoHolder)
A special binding used by Proc-Layer commands for capturing UNDO state information.
#define LERR_(_NAME_)
Definition: error.hpp:58
Generic wrapper carrying a function object while hiding the actual function signature.
void operator()(CmdClosure &clo)
LumieraError< LERR_(STATE)> State
Definition: error.hpp:214
Mutation(function< SIG > const &func)
Lumiera error handling (C++ interface).
Mutation & captureState(CmdClosure &clo)
Binding together state capturing and execution of the undo operation.
Definition: memento-tie.hpp:90
A closure enabling self-contained execution of commands within the ProcDispatcher.
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
virtual void invoke(CmdFunctor const &)=0
invoke functor using the stored parameter values
Specialised version of the command Mutation functor, used to implement the UNDO functionality.