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)
5  2016, 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 
37 #ifndef CONTROL_COMMAND_SIMPLE_CLOSURE_H
38 #define CONTROL_COMMAND_SIMPLE_CLOSURE_H
39 
42 #include "lib/opaque-holder.hpp"
43 
44 #include <string>
45 
46 
47 
48 namespace steam {
49 namespace control {
50  namespace err = lumiera::error;
51 
52  using lib::InPlaceBuffer;
53  using std::string;
54 
55 
56 
57 
58 
67  template<typename SIG>
69  : public CmdClosure
70  {
71  using ArgHolder = OpClosure<SIG>;
73 
74  using ArgTuple = typename ArgHolder::ArgTuple;
75  using Args = typename lib::meta::RebindTupleTypes<ArgTuple>::Seq; // std::tuple<ARGS...> to Types<ARGS...>
76 
77 
78  /* ====== in-place argument storage ====== */
79 
80  ArgumentBuff arguments_;
81 
82 
83 
84  /* ==== proxied CmdClosure interface ==== */
85 
86  public:
87  virtual bool
88  isValid () const override
89  {
90  return arguments_->isValid();
91  }
92 
93  virtual bool
94  isCaptured() const override
95  {
96  return false;
97  }
98 
99 
100 
102  virtual void
103  bindArguments (Arguments& args) override
104  {
105  storeTuple (args.get<ArgTuple>());
106  }
107 
113  virtual void
114  bindArguments (lib::diff::Rec const& paramData) override
115  {
116  storeTuple (buildTuple<Args> (paramData));
117  }
118 
120  virtual void
121  unbindArguments() override
122  {
123  clearStorage();
124  }
125 
126 
127  virtual void
128  invoke (CmdFunctor const& func) override
129  {
130  if (!isValid())
131  throw err::State{"Lifecycle error: can't bind functor, "
132  "command arguments not yet provided"
133  , LERR_(UNBOUND_ARGUMENTS)};
134 
135  arguments_->invoke(func);
136  }
137 
138 
139  virtual
140  operator string() const override
141  {
142  return "Command-Closure{ arguments="
143  + (arguments_->isValid()? string(*arguments_) : "unbound")
144  + " }"
145  ;
146  }
147 
148 
149 
156  : arguments_()
157  { }
158 
159  explicit
160  SimpleClosure (ArgTuple const& args)
161  : arguments_()
162  {
163  storeTuple (args);
164  }
165 
166  SimpleClosure (SimpleClosure const& oAh)
167  : arguments_()
168  {
169  if (oAh.arguments_->isValid()) // don't clone garbage from invalid arguments
170  arguments_.template create<ArgHolder> (*oAh.arguments_);
171  }
172 
173 
174  void
175  accept (CommandImplCloneBuilder&) const override
176  {
177  NOTREACHED();
178  }
179 
180 
182  bool canUndo () const { return false; }
183  bool empty () const { return !arguments_->isValid(); }
184 
185 
188  void
189  storeTuple (ArgTuple const& argTup)
190  {
191  arguments_.template create<ArgHolder> (argTup);
192  }
193 
194  void
195  clearStorage ()
196  {
197  arguments_.template create<ArgHolder>();
198  }
199  };
200 
201 
202 
203 }} // namespace steam::control
204 #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:190
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:141