Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
command.hpp
Go to the documentation of this file.
1/*
2 COMMAND.hpp - Key abstraction for steam/edit operations and UNDO management
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
59#ifndef CONTROL_COMMAND_H
60#define CONTROL_COMMAND_H
61
62#include "lib/error.hpp"
63#include "lib/symbol.hpp"
64#include "steam/common.hpp"
69#include "lib/diff/gen-node.hpp"
70#include "lib/handle.hpp"
71
72#include <string>
73
74
75namespace lumiera {
76namespace error {
77 LUMIERA_ERROR_DECLARE (UNBOUND_ARGUMENTS);
78 LUMIERA_ERROR_DECLARE (INVALID_COMMAND);
79 LUMIERA_ERROR_DECLARE (DUPLICATE_COMMAND);
80 LUMIERA_ERROR_DECLARE (INVALID_ARGUMENTS);
81 LUMIERA_ERROR_DECLARE (MISSING_MEMENTO);
82}}
83
84namespace steam {
85namespace control {
86
87 using std::string;
88 using lib::Symbol;
89 using std::shared_ptr;
90 using lib::meta::Tuple;
91 using lib::meta::Types;
92
93 using FuncPtr = void*;
94
95 class CommandDef;
96 class CommandImpl;
97
98
116 : public AcceptAnyBinding<Command // accepts arbitrary bind(..) calls (with runtime check)
117 , Command& // (return value of bind() functions is *this)
118 , lib::Handle<CommandImpl> // actually implemented as ref counting Handle
119 > //
120 {
122
123 public:
124 /* === command registry === */
125 static Command get (Symbol cmdID);
126 static bool remove (Symbol cmdID);
127
130 Command newInstance () const;
131
132 static Command maybeGetNewInstance (Symbol cmdID);
133
134
135 Command (Symbol cmdID) { *this = get (cmdID); }
136 Command() { }
137 ~Command();
138
139 // default copy acceptable
140 Command (Command &&) = default;
141 Command (Command const&) = default;
142 Command& operator= (Command &&) = default;
143 Command& operator= (Command const&) = default;
144
145
146
147 /* === command lifecycle === */
148
149 template<typename...TYPES>
150 Command& bindArg (std::tuple<TYPES...> const&);
151
153
154 Command& unbind();
155
156
158 ExecResult exec () ;
159 ExecResult undo () ;
160
161
168
171
174
177
181
182
183
184 /* === diagnostics === */
185
186 static size_t definition_count();
187 static size_t instance_count();
188
189 bool canExec() const;
190 bool canUndo() const;
191
192 static bool defined (Symbol cmdID);
193 static bool canExec (Symbol cmdID);
194 static bool canUndo (Symbol cmdID);
195
196 void duplicate_detected (Symbol) const;
197
199 bool isAnonymous() const;
200
201 operator string() const;
202 friend bool operator== (Command const&, Command const&);
203 friend bool operator< (Command const&, Command const&);
204
205
206 protected:
208 void activate (shared_ptr<CommandImpl> &&, Symbol cmdID =0);
209
210 friend class CommandDef; //...invoking those two functions during definition stage
211
212
213 private:
214 void setArguments (Arguments&);
215 void setArguments (lib::diff::Rec const&);
216 };
217
218
219
220
221
223 Command::operator() ()
224 {
226 }
227
228 inline ExecResult
230 {
232 }
233
234 inline ExecResult
236 {
238 }
239
240
241 template<typename...TYPES>
242 inline Command&
243 Command::bindArg (std::tuple<TYPES...> const& tuple)
244 {
245 TypedArguments<std::tuple<TYPES...>> args(tuple);
246 this->setArguments (args);
247 return *this;
248 }
249
250
251 inline Command&
253 {
254 this->setArguments (paramData);
255 return *this;
256 }
257
258
259
260
261 /* == state predicate shortcuts == */
262
263 inline bool
265 {
266 return fetchDef(cmdID).isValid();
267 }
268
269
270#define _FAILSAFE_COMMAND_QUERY(_ID_, _QUERY_) \
271 try \
272 { \
273 return Command::get(_ID_)._QUERY_; \
274 } \
275 catch(lumiera::error::Invalid&) \
276 { \
277 lumiera_error(); /* ignore errorstate */ \
278 return false; \
279 }
280
281
282 inline bool
284 {
286 }
287
288
289 inline bool
291 {
293 }
294
295#undef _FAILSAFE_COMMAND_QUERY
296
297
298
299
300 inline bool
302 {
303 return (!c1 and !c2)
304 or ( c1 and c2 and (&c1.impl() == &c2.impl()));
305 }
306
307 inline bool
309 {
310 return not (c1 == c2);
311 }
312
314 inline bool
315 operator< (Command const& c1, Command const& c2)
316 {
317 return (!c1 and c2)
318 or ( c1 and c2 and (&c1.impl() < &c2.impl()));
319 }
320
321
322
323
324}} // namespace steam::control
325#endif
Implementation helper to bind Steam-Layer commands with arbitrary argument tuples.
Mixin-templates providing arbitrary function call operators and argument binding functions.
Token or Atom with distinct identity.
Definition symbol.hpp:120
object-like record of data.
Definition record.hpp:142
Helper Template for control::Command, mix-in complete set of bind(...) functions.
Helper class used solely for defining a Command-Object.
Steam-Layer Command implementation.
Handle object representing a single Command instance to be used by client code.
Definition command.hpp:120
Command(Command &&)=default
Command(Symbol cmdID)
Definition command.hpp:135
ExecResult execSync()
invoke using a default "synchronous" execution pattern
Definition command.cpp:450
Command & bindArg(std::tuple< TYPES... > const &)
Definition command.hpp:243
ExecResult operator()()
Definition command.hpp:223
void duplicate_detected(Symbol) const
Definition command.cpp:230
HandlingPattern::ID setHandlingPattern(HandlingPattern::ID)
define a handling pattern to be used by default
Definition command.cpp:465
friend bool operator<(Command const &, Command const &)
allow for sets and associative containers
Definition command.hpp:315
Command(Command const &)=default
static Command maybeGetNewInstance(Symbol cmdID)
try to access an existing command definition and immediately create a new clone copy by calling newIn...
Definition command.cpp:140
bool isAnonymous() const
Definition command.cpp:379
static bool defined(Symbol cmdID)
Definition command.hpp:264
static size_t definition_count()
Definition command.cpp:289
static Command fetchDef(Symbol cmdID)
Definition command.cpp:150
friend bool operator==(Command const &, Command const &)
Definition command.hpp:301
Command()
undefined command
Definition command.hpp:136
Command & operator=(Command &&)=default
Command & unbind()
discard any argument data previously bound.
Definition command.cpp:279
void activate(shared_ptr< CommandImpl > &&, Symbol cmdID=0)
Definition command.cpp:162
void setArguments(Arguments &)
Definition command.cpp:251
Command newInstance() const
create independent (anonymous) clone copy of this command
Definition command.cpp:200
Symbol getID() const noexcept
Definition command.cpp:366
static Command get(Symbol cmdID)
Access existing command for use.
Definition command.cpp:120
HandlingPattern::ID getDefaultHandlingPattern() const
Definition command.cpp:457
static bool remove(Symbol cmdID)
Definition command.cpp:241
Command storeDef(Symbol newCmdID) const
create a clone definition
Definition command.cpp:183
static size_t instance_count()
Definition command.cpp:298
Result (Status) of command execution.
Interface: Operation Skeleton how to invoke or undo a command.
#define _FAILSAFE_COMMAND_QUERY(_ID_, _QUERY_)
Definition command.hpp:270
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition error.h:62
Lumiera error handling (C++ interface).
Generic building block for tree shaped (meta)data structures.
A generic opaque handle to an implementation entity, including lifecycle management.
Pre-defined command execution skeletons.
BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
variadic sequence of types
Definition typelist.hpp:102
Implementation namespace for support and library code.
Lumiera public interface.
Definition advice.hpp:102
bool operator!=(Command const &c1, Command const &c2)
Definition command.hpp:308
void * FuncPtr
Definition command.hpp:93
Steam-Layer implementation namespace root.
Basic set of definitions and includes commonly used together.
Marker types to indicate a literal string and a Symbol.
Metaprogramming with tuples-of-types and the std::tuple record.