Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
command-impl.hpp
Go to the documentation of this file.
1/*
2 COMMAND-IMPL.hpp - Steam-Layer command implementation (top level)
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
31#ifndef CONTROL_COMMAND_IMPL_H
32#define CONTROL_COMMAND_IMPL_H
33
37#include "lib/format-string.hpp"
38#include "lib/nocopy.hpp"
39
40#include <memory>
41#include <functional>
42
43
44namespace steam {
45namespace control {
46
47 using util::_Fmt;
48 using std::function;
49 using std::shared_ptr;
50
51
52
70 {
73
75
77
78
79 template<typename ARG>
80 struct _Type
81 {
82 using SIG_op = ARG::SIG_op;
83 using SIG_cap = ARG::SIG_cap;
84 using SIG_undo = ARG::SIG_undo;
85
89 };
90#define _TY(_ID_) typename _Type<ARG>::_ID_
91
92 public:
98 template<typename ARG>
100 ,_TY (Func_op) const& operFunctor
101 ,_TY (Func_cap) const& captFunctor
102 ,_TY (Func_undo) const& undoFunctor
103 )
107 , defaultPatt_(HandlingPattern::defaultID())
108 { }
109
110#undef _TY
111
112
113 ~CommandImpl();
114
115
135
136 explicit operator bool() const { return isValid(); }
137
138
143
144
154 void
156 {
157 ASSERT (pClo_);
158 pClo_->accept(visitor);
159 }
160
161
162 public: /* === implementation of command functionality === */
163
164 void
166 {
167 pClo_->bindArguments (args);
168 }
169
170 void
172 {
173 pClo_->bindArguments (paramData);
174 }
175
176 void
178 {
179 pClo_->unbindArguments();
180 }
181
184 void invokeUndo() { undo_(*pClo_); }
185
186
187
189
190 PattID
192 {
193 return defaultPatt_;
194 }
195
198 PattID
200 {
201 PattID currID = defaultPatt_;
202 defaultPatt_ = newID;
203 return currID;
204 }
205
206
207
208 /* === diagnostics === */
209
210 bool
216
217 bool
219 {
220 return isValid()
221 and pClo_->isValid();
222 }
223
224 bool
226 {
227 return isValid() and pClo_->isCaptured();
228 }
229
230 operator string() const
231 {
232 return _Fmt("Cmd|valid:%s, exec:%s, undo:%s |%s")
233 % isValid()
234 % canExec()
235 % canUndo()
236 % (pClo_? string(*pClo_) : util::FAILURE_INDICATOR);
237 }
238 };
239
240
241
242
243
244}} // namespace steam::control
245#endif
Token or Atom with distinct identity.
Definition symbol.hpp:120
object-like record of data.
Definition record.hpp:142
Visitor to support creating a CommandImpl clone.
Steam-Layer Command implementation.
void prepareClone(CommandImplCloneBuilder &visitor) const
assist with building a clone copy of this CommandImpl.
CommandImpl(CommandImpl const &orig, UndoMutation const &newUndo, shared_ptr< CmdClosure > const &newClosure)
bool isValid() const
< validity self-check: is basically usable.
void setArguments(lib::diff::Rec const &paramData)
shared_ptr< CmdClosure > pClo_
PattID getDefaultHandlingPattern() const
CommandImpl(shared_ptr< ARG > pStorageHolder, _TY(Func_op) const &operFunctor, _TY(Func_cap) const &captFunctor, _TY(Func_undo) const &undoFunctor)
build a new implementation frame, and do the initial wiring.
HandlingPattern::ID defaultPatt_
bool canUndo() const
< state check: has undo state been captured?
HandlingPattern::ID PattID
Symbol cmdID
human-readable marker for diagnostics, will be (re)assigned when activating this CommandImpl
bool canExec() const
< state check: sufficiently defined to be invoked
PattID setHandlingPattern(PattID newID)
define a handling pattern to be used by default
void setArguments(Arguments &args)
Interface: Operation Skeleton how to invoke or undo a command.
virtual bool isValid() const =0
static HandlingPattern const & get(ID id)
retrieve the pre-configured pattern
Unspecific command functor for implementing Steam-Layer Command.
Specialised version of the command Mutation functor, used to implement the UNDO functionality.
Mutation & captureState(CmdClosure &clo)
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
A front-end for using printf-style formatting.
A closure enabling self-contained execution of commands within the SteamDispatcher.
#define _TY(_ID_)
Core of a Steam-Layer command: functor containing the operation to be executed.
Steam-Layer command frontend.
Front-end for printf-style string template interpolation.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
Steam-Layer implementation namespace root.
Mix-Ins to allow or prohibit various degrees of copying and cloning.