Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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
48namespace steam {
49namespace control {
50 namespace err = lumiera::error;
51
53 using std::string;
54
55
56
57
58
70 template<typename SIG, typename MEM>
72 : public CmdClosure
73 {
76
79
80 using ArgTuple = ArgHolder::ArgTuple;
81 using Args = lib::meta::RebindTupleTypes<ArgTuple>::Seq; // std::tuple<ARGS...> to Types<ARGS...>
82
83
84 /* ====== in-place storage buffers ====== */
85
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
111 {
112 storeTuple (args.get<ArgTuple>());
113 }
114
120 virtual void
125
127 virtual void
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
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
206 {
208 }
209
210 void
212 {
213 arguments_.template create<ArgHolder>();
214 memento_->clear();
215 }
216
217
221
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*/
Buffer to place and maintain an object instance privately within another object.
object-like record of data.
Definition record.hpp:142
Visitor to support creating a CommandImpl clone.
void buildCloneContext(ARG const &origArgHolder)
to be executed from within the specifically typed context of a concrete command StorageHolder; alloca...
BuildFunType< void, ExtendedArgs >::Sig UndoOp_Sig
BuildFunType< MEM, Args >::Sig CaptureSig
BuildFunType< void, Args >::Sig OperateSig
This is "the" top level CmdClosure implementation.
void accept(CommandImplCloneBuilder &visitor) const override
assist with creating a clone copy; this results in invocation of the copy ctor
CommandSignature< SIG, MEM >::CaptureSig SIG_cap
virtual bool isCaptured() const override
does this closure hold captured UNDO state?
StorageHolder(StorageHolder const &oAh)
copy construction allowed(but no assignment).
CommandSignature< SIG, MEM >::UndoOp_Sig SIG_undo
StorageHolder & operator=(StorageHolder const &)=delete
copy construction allowed(but no assignment)
virtual void unbindArguments() override
discard any argument data and return to empty state
MEM & memento()
direct "backdoor" access to stored memento value.
MementoTie< SIG, MEM > & getMementoWiring()
just re-access an existing memento storage wiring.
StorageHolder()
per default, all data within StorageHolder is set up in empty state.
bool canUndo() const
has undo state capturing been invoked?
virtual bool isValid() const override
does this closure hold a valid argument tuple?
virtual void bindArguments(Arguments &args) override
assign a new parameter tuple to this
CommandSignature< SIG, MEM >::OperateSig SIG_op
virtual void bindArguments(lib::diff::Rec const &paramData) override
assign a new set of parameter values to this.
virtual void invoke(CmdFunctor const &func) override
invoke functor using the stored parameter values
void storeTuple(ArgTuple const &argTup)
store a new argument tuple within this StorageHolder, discarding any previously stored arguments
lib::meta::RebindTupleTypes< ArgTuple >::Seq Args
MementoTie< SIG, MEM > & tie(function< SIG_undo > const &undoFunc, function< SIG_cap > const &captureFunc)
create a new memento storage wiring, discarding existing memento state.
Helper for creating an implementation clone, based on the visitor pattern.
Implementation of the concrete (sub)-closure of a command, responsible for invoking the actual comman...
#define LERR_(_NAME_)
Definition error.hpp:45
A special binding used by Steam-Layer commands for capturing UNDO state information.
Types< TYPES... >::Seq Seq
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
LumieraError< LERR_(STATE)> State
Definition error.hpp:209
Steam-Layer implementation namespace root.
Helper allowing type erasure while holding the actual object inline.
Generic wrapper carrying a function object while hiding the actual function signature.
Abstract foundation for building custom allocation managers.