57 using std::ostringstream;
69 LUMIERA_ERROR_DEFINE (DUPLICATE_COMMAND,
"Attempt to redefine an already existing command definition");
70 LUMIERA_ERROR_DEFINE (INVALID_ARGUMENTS,
"Arguments provided for binding doesn't match stored command function parameters");
71 LUMIERA_ERROR_DEFINE (UNBOUND_ARGUMENTS,
"Command mutation functor not yet usable, because arguments aren't bound");
72 LUMIERA_ERROR_DEFINE (MISSING_MEMENTO,
"Undo functor not yet usable, because no undo state has been captured");
81 if (!handle->isValid())
83 , LERR_(INVALID_COMMAND));
87 ___check_isBound (
const Command *handle)
90 if (!handle->canExec())
91 throw error::State (
"Lifecycle error: command arguments not bound" 92 , LERR_(UNBOUND_ARGUMENTS));
96 ___check_canUndo (
const Command *handle)
99 if (!handle->canUndo())
100 throw error::State (
"Lifecycle error: command has not yet captured UNDO information" 101 , LERR_(UNBOUND_ARGUMENTS));
113 Command::~Command() { }
114 CommandImpl::~CommandImpl() { }
132 , LERR_(INVALID_COMMAND));
134 ENSURE (cmdID == CommandRegistry::instance().findDefinition(cmd));
174 duplicate_detected (cmdID);
176 _Handle::activate (move (implFrame));
180 impl().cmdID = cmdID;
183 TRACE (command,
"%s defined OK", cStr(*
this));
194 ___check_notBottom (
this,
"Cloning");
196 duplicate_detected (newCmdID);
200 ENSURE (cloneDefinition);
201 return cloneDefinition;
209 ___check_notBottom (
this,
"Cloning");
237 Command::duplicate_detected (
Symbol newCmdID)
const 240 "ID \"%s\" is already in use")
243 , LERR_(DUPLICATE_COMMAND));
248 Command::remove (
Symbol cmdID)
260 ___check_notBottom (
this,
"Binding arguments of");
261 _Handle::impl().setArguments(args);
273 ___check_notBottom (
this,
"Binding arguments of");
274 _Handle::impl().setArguments(paramData);
288 ___check_notBottom (
this,
"Un-binding arguments of");
289 _Handle::impl().discardArguments();
314 was_activated (
Command const& com)
316 return com.isValid();
320 registered_for (
Symbol id)
335 if (!was_activated (prototype_))
349 return (was_activated (prototype_))
350 && (prototype_ == registered_for (this->id_))
357 Command::canExec()
const 365 Command::canUndo()
const 373 Command::getID()
const noexcept
375 return isValid()? impl().cmdID
396 Command::operator string()
const 400 repr <<
"Command(\""<<getID()<<
"\") ";
421 ___check_notBottom (
this,
"Invoking");
422 ___check_isBound (
this);
424 string cmdName{*
this};
426 return execPattern.
exec (thisCommand, cmdName);
433 ___check_notBottom (
this,
"UNDOing");
434 ___check_canUndo (
this);
436 string cmdName{*
this};
438 return execPattern.
undo (thisCommand, cmdName);
443 Command::exec (HandlingPattern::ID pattID)
450 Command::undo (HandlingPattern::ID pattID)
466 ___check_notBottom (
this,
"Accessing");
467 return impl().getDefaultHandlingPattern();
474 ___check_notBottom (
this,
"Configuring");
475 return impl().setHandlingPattern(pattID);
ExecResult undo(CommandImpl &command, string) const
likewise invoke the configured UNDO operation
UndoMutation const & clonedUndoMutation()
after visitation: use pre-built bits to provide a cloned UndoFunctor
HandlingPattern::ID setHandlingPattern(HandlingPattern::ID)
define a handling pattern to be used by default
static size_t definition_count()
ExecResult exec(CommandImpl &command, string) const
main functionality: invoke a command, detect errors.
~CommandDef()
when starting a CommandDef, we immediately place a yet empty Command object into the index...
Top level of the command implementation.
inline string literal This is a marker type to indicate that
PClo const & clonedClosuere()
after visitation: provide cloned StorageHolder, but already stripped down to the generic usage type ...
void activate(shared_ptr< CommandImpl > &&, Symbol cmdID=0)
void undo(short param, int memento)
bool isValid() const
is this a valid command definition? especially.
Managing command definitions and the storage of individual command objects.
void prepareClone(CommandImplCloneBuilder &visitor) const
assist with building a clone copy of this CommandImpl.
Command newInstance() const
create independent (anonymous) clone copy of this command
const char * cStr(string const &org)
convenience shortcut: conversion to c-String via string.
static Command get(Symbol cmdID)
Access existing command for use.
Command storeDef(Symbol newCmdID) const
create a clone definition
Registry managing command implementation objects (Singleton).
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
Access point to singletons and other kinds of dependencies designated by type.
static Command maybeGetNewInstance(Symbol cmdID)
try to access an existing command definition and immediately create a new clone copy by calling newIn...
Derived specific exceptions within Lumiera's exception hierarchy.
static size_t instance_count()
Token or Atom with distinct identity.
Command queryIndex(Symbol cmdID)
query the command index by ID
Marker types to indicate a literal string and a Symbol.
Command & unbind()
discard any argument data previously bound.
Result (Status) of command execution.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
void setArguments(Arguments &)
Steam-Layer command frontend.
Visitor to support creating a CommandImpl clone.
Pre-defined command execution skeletons.
static Command fetchDef(Symbol cmdID)
Lumiera error handling (C++ interface).
Helper for creating an implementation clone, based on the visitor pattern.
ExecResult execSync()
invoke using a default "synchronous" execution pattern
Handle object representing a single Command instance to be used by client code.
shared_ptr< CommandImpl > createCloneImpl(CommandImpl const &refObject)
create an allocation for holding a clone of the given CommandImpl data.
HandlingPattern::ID getDefaultHandlingPattern() const
Steam-Layer Command implementation.
static HandlingPattern const & get(ID id)
retrieve the pre-configured pattern
Actually defining a command and binding it to execution parameters.
object-like record of data.
Interface: Operation Skeleton how to invoke or undo a command.
static lib::Depend< CommandRegistry > instance
storage for the singleton factory used to access CommandRegistry
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.