Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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
48namespace steam {
49namespace control {
50 namespace err = lumiera::error;
51
53 using std::string;
54
55
56
57
58
67 template<typename SIG>
69 : public CmdClosure
70 {
73
74 using ArgTuple = ArgHolder::ArgTuple;
75 using Args = lib::meta::RebindTupleTypes<ArgTuple>::Seq; // std::tuple<ARGS...> to Types<ARGS...>
76
77
78 /* ====== in-place argument storage ====== */
79
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
104 {
105 storeTuple (args.get<ArgTuple>());
106 }
107
113 virtual void
118
120 virtual void
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
161 : arguments_()
162 {
164 }
165
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
176 {
177 NOTREACHED();
178 }
179
180
182 bool canUndo () const { return false; }
183 bool empty () const { return !arguments_->isValid(); }
184
185
188 void
190 {
192 }
193
194 void
196 {
197 arguments_.template create<ArgHolder>();
198 }
199 };
200
201
202
203}} // namespace steam::control
204#endif /*CONTROL_COMMAND_SIMPLE_CLOSURE_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.
Dummy / proof-of-concept implementation of CmdClosure.
SimpleClosure()
per default, all data within StorageHolder is set up in empty state.
virtual bool isCaptured() const override
does this closure hold captured UNDO state?
virtual void unbindArguments() override
discard any argument data and return to empty state
bool canUndo() const
has undo state capturing been invoked?
void accept(CommandImplCloneBuilder &) const override
assist with creating clone closure without disclosing concrete type
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
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
SimpleClosure(SimpleClosure const &oAh)
lib::meta::RebindTupleTypes< ArgTuple >::Seq Args
Implementation of the concrete (sub)-closure of a command, responsible for invoking the actual comman...
#define LERR_(_NAME_)
Definition error.hpp:45
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.