Lumiera  0.pre.03
»edit your freedom«
command-simple-closure.hpp
Go to the documentation of this file.
1 /*
2  COMMAND-SIMPLE-CLOSURE.hpp - demo implementation of command closure
3 
4  Copyright (C) Lumiera.org
5  2016, 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 
46 #ifndef CONTROL_COMMAND_SIMPLE_CLOSURE_H
47 #define CONTROL_COMMAND_SIMPLE_CLOSURE_H
48 
51 #include "lib/opaque-holder.hpp"
52 
53 #include <string>
54 
55 
56 
57 namespace steam {
58 namespace control {
59  namespace err = lumiera::error;
60 
61  using lib::InPlaceBuffer;
62  using std::string;
63 
64 
65 
66 
67 
76  template<typename SIG>
78  : public CmdClosure
79  {
80  using ArgHolder = OpClosure<SIG>;
82 
83  using ArgTuple = typename ArgHolder::ArgTuple;
84  using Args = typename lib::meta::RebindTupleTypes<ArgTuple>::Seq; // std::tuple<ARGS...> to Types<ARGS...>
85 
86 
87  /* ====== in-place argument storage ====== */
88 
89  ArgumentBuff arguments_;
90 
91 
92 
93  /* ==== proxied CmdClosure interface ==== */
94 
95  public:
96  virtual bool
97  isValid () const override
98  {
99  return arguments_->isValid();
100  }
101 
102  virtual bool
103  isCaptured() const override
104  {
105  return false;
106  }
107 
108 
109 
111  virtual void
112  bindArguments (Arguments& args) override
113  {
114  storeTuple (args.get<ArgTuple>());
115  }
116 
122  virtual void
123  bindArguments (lib::diff::Rec const& paramData) override
124  {
125  storeTuple (buildTuple<Args> (paramData));
126  }
127 
129  virtual void
130  unbindArguments() override
131  {
132  clearStorage();
133  }
134 
135 
136  virtual void
137  invoke (CmdFunctor const& func) override
138  {
139  if (!isValid())
140  throw err::State{"Lifecycle error: can't bind functor, "
141  "command arguments not yet provided"
142  , LERR_(UNBOUND_ARGUMENTS)};
143 
144  arguments_->invoke(func);
145  }
146 
147 
148  virtual
149  operator string() const override
150  {
151  return "Command-Closure{ arguments="
152  + (arguments_->isValid()? string(*arguments_) : "unbound")
153  + " }"
154  ;
155  }
156 
157 
158 
165  : arguments_()
166  { }
167 
168  explicit
169  SimpleClosure (ArgTuple const& args)
170  : arguments_()
171  {
172  storeTuple (args);
173  }
174 
175  SimpleClosure (SimpleClosure const& oAh)
176  : arguments_()
177  {
178  if (oAh.arguments_->isValid()) // don't clone garbage from invalid arguments
179  arguments_.template create<ArgHolder> (*oAh.arguments_);
180  }
181 
182 
183  void
184  accept (CommandImplCloneBuilder&) const override
185  {
186  NOTREACHED();
187  }
188 
189 
191  bool canUndo () const { return false; }
192  bool empty () const { return !arguments_->isValid(); }
193 
194 
197  void
198  storeTuple (ArgTuple const& argTup)
199  {
200  arguments_.template create<ArgHolder> (argTup);
201  }
202 
203  void
204  clearStorage ()
205  {
206  arguments_.template create<ArgHolder>();
207  }
208  };
209 
210 
211 
212 }} // namespace steam::control
213 #endif /*CONTROL_COMMAND_SIMPLE_CLOSURE_H*/
Implementation of the concrete (sub)-closure of a command, responsible for invoking the actual comman...
Abstract foundation for building custom allocation managers.
void storeTuple(ArgTuple const &argTup)
store a new argument tuple within this StorageHolder, discarding any previously stored arguments ...
Steam-Layer implementation namespace root.
closure to deal with the actual command operation.
virtual void bindArguments(lib::diff::Rec const &paramData) override
assign a new set of parameter values to this.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
virtual void bindArguments(Arguments &args) override
assign a new parameter tuple to this
Generic wrapper carrying a function object while hiding the actual function signature.
void accept(CommandImplCloneBuilder &) const override
assist with creating clone closure without disclosing concrete type
virtual void invoke(CmdFunctor const &func) override
invoke functor using the stored parameter values
Helper allowing type erasure while holding the actual object inline.
Dummy / proof-of-concept implementation of CmdClosure.
Visitor to support creating a CommandImpl clone.
virtual void unbindArguments() override
discard any argument data and return to empty state
Buffer to place and maintain an object instance privately within another object.
virtual bool isCaptured() const override
does this closure hold captured UNDO state?
virtual bool isValid() const override
does this closure hold a valid argument tuple?
SimpleClosure()
per default, all data within StorageHolder is set up in empty state.
bool canUndo() const
has undo state capturing been invoked?
object-like record of data.
Definition: record.hpp:150