Lumiera  0.pre.03
»edit your freedom«
command-storage-holder.hpp
Go to the documentation of this file.
1 /*
2  COMMAND-STORAGE-HOLDER.hpp - specifically typed container for storage of command arguments
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 
35 #ifndef CONTROL_COMMAND_STORAGE_HOLDER_H
36 #define CONTROL_COMMAND_STORAGE_HOLDER_H
37 
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 
70  template<typename SIG, typename MEM>
72  : public CmdClosure
73  {
74  using ArgHolder = OpClosure<SIG>;
76 
79 
80  using ArgTuple = typename ArgHolder::ArgTuple;
81  using Args = typename lib::meta::RebindTupleTypes<ArgTuple>::Seq; // std::tuple<ARGS...> to Types<ARGS...>
82 
83 
84  /* ====== in-place storage buffers ====== */
85 
86  ArgumentBuff arguments_;
87  MementoBuff memento_;
88 
89 
90 
91  /* ==== proxied CmdClosure interface ==== */
92 
93  public:
94  virtual bool
95  isValid () const override
96  {
97  return arguments_->isValid();
98  }
99 
100  virtual bool
101  isCaptured() const override
102  {
103  return memento_->isValid();
104  }
105 
106 
107 
109  virtual void
110  bindArguments (Arguments& args) override
111  {
112  storeTuple (args.get<ArgTuple>());
113  }
114 
120  virtual void
121  bindArguments (lib::diff::Rec const& paramData) override
122  {
123  storeTuple (buildTuple<Args> (paramData));
124  }
125 
127  virtual void
128  unbindArguments() override
129  {
130  clearStorage();
131  }
132 
133 
134  virtual void
135  invoke (CmdFunctor const& func) override
136  {
137  if (!isValid())
138  throw err::State{"Lifecycle error: can't bind functor, "
139  "command arguments not yet provided"
140  , LERR_(UNBOUND_ARGUMENTS)};
141 
142  arguments_->invoke(func);
143  }
144 
145 
146  virtual
147  operator string() const override
148  {
149  return "Command-State{ arguments="
150  + (arguments_->isValid()? string(*arguments_) : "unbound")
151  + ", "+string(*memento_)+"}"
152  ;
153  }
154 
155 
156 
163  : arguments_()
164  , memento_()
165  { }
166 
172  : arguments_()
173  , memento_()
174  {
175  if (oAh.arguments_->isValid()) // don't clone garbage from invalid arguments
176  arguments_.template create<ArgHolder> (*oAh.arguments_);
177 
178  // memento can be cloned as-is, irrespective of activation state
179  memento_.template create<MemHolder> (*oAh.memento_);
180  }
181 
182 
184  StorageHolder& operator= (StorageHolder const&) = delete;
185 
186 
187 
190  void
191  accept (CommandImplCloneBuilder& visitor) const override
192  {
193  visitor.buildCloneContext (*this);
194  }
195 
196 
198  bool canUndo () const { return memento_->isValid(); }
199  bool empty () const { return !arguments_->isValid(); }
200 
201 
204  void
205  storeTuple (ArgTuple const& argTup)
206  {
207  arguments_.template create<ArgHolder> (argTup);
208  }
209 
210  void
211  clearStorage ()
212  {
213  arguments_.template create<ArgHolder>();
214  memento_->clear();
215  }
216 
217 
218  typedef typename CommandSignature<SIG,MEM>::OperateSig SIG_op;
219  typedef typename CommandSignature<SIG,MEM>::CaptureSig SIG_cap;
220  typedef typename CommandSignature<SIG,MEM>::UndoOp_Sig SIG_undo;
221 
226  tie (function<SIG_undo> const& undoFunc,
227  function<SIG_cap> const& captureFunc)
228  {
229  return memento_.template create<MemHolder> (undoFunc,captureFunc);
230  }
231 
236  {
237  return *memento_;
238  }
239 
240 
241 
245  MEM&
247  {
248  return memento_->getState();
249  }
250  };
251 
252 
253 
254 }} // namespace steam::control
255 #endif /*CONTROL_COMMAND_STORAGE_HOLDER_H*/
Implementation of the concrete (sub)-closure of a command, responsible for invoking the actual comman...
bool canUndo() const
has undo state capturing been invoked?
Abstract foundation for building custom allocation managers.
void buildCloneContext(ARG const &origArgHolder)
to be executed from within the specifically typed context of a concrete command StorageHolder; alloca...
virtual void unbindArguments() override
discard any argument data and return to empty state
MEM & memento()
direct "backdoor" access to stored memento value.
StorageHolder(StorageHolder const &oAh)
copy construction allowed(but no assignment).
Steam-Layer implementation namespace root.
StorageHolder & operator=(StorageHolder const &)=delete
copy construction allowed(but no assignment)
MementoTie< SIG, MEM > & tie(function< SIG_undo > const &undoFunc, function< SIG_cap > const &captureFunc)
create a new memento storage wiring, discarding existing memento state.
closure to deal with the actual command operation.
A special binding used by Steam-Layer commands for capturing UNDO state information.
MementoTie< SIG, MEM > & getMementoWiring()
just re-access an existing memento storage wiring.
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.
virtual bool isValid() const override
does this closure hold a valid argument tuple?
Helper allowing type erasure while holding the actual object inline.
virtual void invoke(CmdFunctor const &func) override
invoke functor using the stored parameter values
Visitor to support creating a CommandImpl clone.
void storeTuple(ArgTuple const &argTup)
store a new argument tuple within this StorageHolder, discarding any previously stored arguments ...
Helper for creating an implementation clone, based on the visitor pattern.
virtual void bindArguments(lib::diff::Rec const &paramData) override
assign a new set of parameter values to this.
Buffer to place and maintain an object instance privately within another object.
virtual bool isCaptured() const override
does this closure hold captured UNDO state?
void accept(CommandImplCloneBuilder &visitor) const override
assist with creating a clone copy; this results in invocation of the copy ctor
virtual void bindArguments(Arguments &args) override
assign a new parameter tuple to this
object-like record of data.
Definition: record.hpp:141
Binding together state capturing and execution of the undo operation.
Definition: memento-tie.hpp:79
This is "the" top level CmdClosure implementation.
StorageHolder()
per default, all data within StorageHolder is set up in empty state.