Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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) 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 
44 #ifndef CONTROL_COMMAND_STORAGE_HOLDER_H
45 #define CONTROL_COMMAND_STORAGE_HOLDER_H
46 
51 #include "lib/opaque-holder.hpp"
52 
53 #include <string>
54 
55 
56 
57 namespace proc {
58 namespace control {
59 
60  using lib::InPlaceBuffer;
61  using std::string;
62 
63 
64 
65 
66 
78  template<typename SIG, typename MEM>
80  : public CmdClosure
81  {
84 
87 
88  using ArgTuple = typename ArgHolder::ArgTuple;
89  using Args = typename lib::meta::RebindTySeq<ArgTuple>::Seq; // std::tuple<ARGS...> to Types<ARGS...>
90 
91 
92  /* ====== in-place storage buffers ====== */
93 
96 
97 
98 
99  /* ==== proxied CmdClosure interface ==== */
100 
101  public:
102  virtual bool
103  isValid () const override
104  {
105  return arguments_->isValid();
106  }
107 
108  virtual bool
109  isCaptured() const override
110  {
111  return memento_->isValid();
112  }
113 
114 
115 
117  virtual void
118  bindArguments (Arguments& args) override
119  {
120  storeTuple (args.get<ArgTuple>());
121  }
122 
128  virtual void
129  bindArguments (lib::diff::Rec const& paramData) override
130  {
131  storeTuple (buildTuple<Args> (paramData));
132  }
133 
135  virtual void
136  unbindArguments() override
137  {
138  clearStorage();
139  }
140 
141 
142  virtual void
143  invoke (CmdFunctor const& func) override
144  {
145  if (!isValid())
146  throw lumiera::error::State ("Lifecycle error: can't bind functor, "
147  "command arguments not yet provided",
148  LERR_(UNBOUND_ARGUMENTS));
149 
150  arguments_->invoke(func);
151  }
152 
153 
154  virtual
155  operator string() const override
156  {
157  return "Command-State{ arguments="
158  + (arguments_->isValid()? string(*arguments_) : "unbound")
159  + ", "+string(*memento_)+"}"
160  ;
161  }
162 
163 
164 
171  : arguments_()
172  , memento_()
173  { }
174 
180  : arguments_()
181  , memento_()
182  {
183  if (oAh.arguments_->isValid()) // don't clone garbage from invalid arguments
184  arguments_.template create<ArgHolder> (*oAh.arguments_);
185 
186  // memento can be cloned as-is, irrespective of activation state
187  memento_.template create<MemHolder> (*oAh.memento_);
188  }
189 
190 
192  StorageHolder& operator= (StorageHolder const&) = delete;
193 
194 
195 
198  void
199  accept (CommandImplCloneBuilder& visitor) const override
200  {
201  visitor.buildCloneContext (*this);
202  }
203 
204 
206  bool canUndo () const { return memento_->isValid(); }
207  bool empty () const { return !arguments_->isValid(); }
208 
209 
212  void
213  storeTuple (ArgTuple const& argTup)
214  {
215  arguments_.template create<ArgHolder> (argTup);
216  }
217 
218  void
220  {
221  arguments_.template create<ArgHolder>();
222  memento_->clear();
223  }
224 
225 
229 
234  tie (function<SIG_undo> const& undoFunc,
235  function<SIG_cap> const& captureFunc)
236  {
237  return memento_.template create<MemHolder> (undoFunc,captureFunc);
238  }
239 
244  {
245  return *memento_;
246  }
247 
248 
249 
253  MEM&
255  {
256  return memento_->getState();
257  }
258 
259  bool
260  equals (CmdClosure const& other) const
261  {
262  const StorageHolder* toCompare = dynamic_cast<const StorageHolder*> (&other);
263  return (toCompare)
264  and (*this == *toCompare);
265  }
266 
268  friend bool
270  {
271  return (a1.arguments_->isValid() == a2.arguments_->isValid())
272  && (*a1.arguments_ == *a2.arguments_)
273  && (a1.memento_->isValid() == a2.memento_->isValid())
274  && (*a1.memento_ == *a2.memento_)
275  ;
276  }
277 
278  friend bool
280  {
281  return not (a1 == a2);
282  }
283  };
284 
285 
286 
287 }} // namespace proc::control
288 #endif /*CONTROL_COMMAND_STORAGE_HOLDER_H*/
Implementation of the concrete (sub)-closure of a command, responsible for invoking the actual comman...
virtual bool isCaptured() const override
does this closure hold captured UNDO state?
void storeTuple(ArgTuple const &argTup)
store a new argument tuple within this StorageHolder, discarding any previously stored arguments ...
typename lib::meta::RebindTySeq< ArgTuple >::Seq Args
virtual void bindArguments(Arguments &args) override
assign a new parameter tuple to this
Abstract foundation for building custom allocation managers.
CommandSignature< SIG, MEM >::OperateSig SIG_op
StorageHolder & operator=(StorageHolder const &)=delete
copy construction allowed(but no assignment)
typename FunctionTypedef< MEM, Args >::Sig CaptureSig
typename FunctionTypedef< void, Args >::Sig OperateSig
CommandSignature< SIG, MEM >::UndoOp_Sig SIG_undo
MEM & memento()
direct "backdoor" access to stored memento value.
friend bool operator!=(StorageHolder const &a1, StorageHolder const &a2)
virtual void invoke(CmdFunctor const &func) override
invoke functor using the stored parameter values
void buildCloneContext(ARG const &origArgHolder)
to be executed from within the specifically typed context of a concrete command StorageHolder; alloca...
A special binding used by Proc-Layer commands for capturing UNDO state information.
typename ArgHolder::ArgTuple ArgTuple
StorageHolder()
per default, all data within StorageHolder is set up in empty state.
closure to deal with the actual command operation.
friend bool operator==(StorageHolder const &a1, StorageHolder const &a2)
Supporting equality comparisons...
#define LERR_(_NAME_)
Definition: error.hpp:58
Generic wrapper carrying a function object while hiding the actual function signature.
This is "the" top level CmdClosure implementation.
LumieraError< LERR_(STATE)> State
Definition: error.hpp:214
void accept(CommandImplCloneBuilder &visitor) const override
assist with creating a clone copy; this results in invocation of the copy ctor
Helper allowing type erasure while holding the actual object inline.
CommandSignature< SIG, MEM >::CaptureSig SIG_cap
typename Types< TYPES...>::Seq Seq
Visitor to support creating a CommandImpl clone.
MementoTie< SIG, MEM > & getMementoWiring()
just re-access an existing memento storage wiring.
typename FunctionTypedef< void, ExtendedArgs >::Sig UndoOp_Sig
Helper for creating an implementation clone, based on the visitor pattern.
Binding together state capturing and execution of the undo operation.
Definition: memento-tie.hpp:90
bool equals(CmdClosure const &other) const
is equivalent to the given other closure?
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.
MementoTie< SIG, MEM > & tie(function< SIG_undo > const &undoFunc, function< SIG_cap > const &captureFunc)
create a new memento storage wiring, discarding existing memento state.
virtual void unbindArguments() override
discard any argument data and return to empty state
StorageHolder(StorageHolder const &oAh)
copy construction allowed(but no assignment).
bool canUndo() const
has undo state capturing been invoked?
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
object-like record of data.
Definition: record.hpp:143
virtual bool isValid() const override
does this closure hold a valid argument tuple?