48 using std::ostringstream;
57 LUMIERA_ERROR_DEFINE (DUPLICATE_COMMAND,
"Attempt to redefine an already existing command definition");
58 LUMIERA_ERROR_DEFINE (INVALID_ARGUMENTS,
"Arguments provided for binding doesn't match stored command function parameters");
59 LUMIERA_ERROR_DEFINE (UNBOUND_ARGUMENTS,
"Command mutation functor not yet usable, because arguments aren't bound");
60 LUMIERA_ERROR_DEFINE (MISSING_MEMENTO,
"Undo functor not yet usable, because no undo state has been captured");
74 if (!handle->isValid())
76 , LERR_(INVALID_COMMAND));
80 ___check_isBound (
const Command *handle)
83 if (!handle->canExec())
84 throw error::State (
"Lifecycle error: command arguments not bound" 85 , LERR_(UNBOUND_ARGUMENTS));
89 ___check_canUndo (
const Command *handle)
92 if (!handle->canUndo())
93 throw error::State (
"Lifecycle error: command has not yet captured UNDO information" 94 , LERR_(UNBOUND_ARGUMENTS));
106 Command::~Command() { }
107 CommandImpl::~CommandImpl() { }
122 Command cmd = CommandRegistry::instance().queryIndex (cmdID);
125 , LERR_(INVALID_COMMAND));
127 ENSURE (cmdID == CommandRegistry::instance().findDefinition(cmd));
140 Command::maybeGetNewInstance (
Symbol cmdID)
142 Command cmd = CommandRegistry::instance().queryIndex (cmdID);
152 return CommandRegistry::instance().queryIndex (cmdID);
167 duplicate_detected (cmdID);
169 _Handle::activate (move (implFrame));
172 CommandRegistry::instance().track (cmdID, *
this);
173 impl().cmdID = cmdID;
176 TRACE (command,
"%s defined OK",
cStr(*
this));
183 Command::storeDef (
Symbol newCmdID)
const 187 ___check_notBottom (
this,
"Cloning");
189 duplicate_detected (newCmdID);
193 ENSURE (cloneDefinition);
194 return cloneDefinition;
200 Command::newInstance ()
const 202 ___check_notBottom (
this,
"Cloning");
230 Command::duplicate_detected (
Symbol newCmdID)
const 233 "ID \"%s\" is already in use")
236 , LERR_(DUPLICATE_COMMAND));
241 Command::remove (
Symbol cmdID)
243 return CommandRegistry::instance().remove (cmdID);
253 ___check_notBottom (
this,
"Binding arguments of");
254 _Handle::impl().setArguments(args);
266 ___check_notBottom (
this,
"Binding arguments of");
267 _Handle::impl().setArguments(paramData);
281 ___check_notBottom (
this,
"Un-binding arguments of");
282 _Handle::impl().discardArguments();
289 Command::definition_count()
291 return CommandRegistry::instance().index_size();
298 Command::instance_count()
300 return CommandRegistry::instance().instance_count();
307 was_activated (
Command const& com)
309 return com.isValid();
313 registered_for (
Symbol id)
315 return CommandRegistry::instance().queryIndex (
id);
326 CommandDef::~CommandDef()
328 if (!was_activated (prototype_))
329 CommandRegistry::instance().remove (this->id_);
340 CommandDef::isValid()
const 342 return (was_activated (prototype_))
343 && (prototype_ == registered_for (this->id_))
350 Command::canExec()
const 358 Command::canUndo()
const 366 Command::getID()
const noexcept
368 return isValid()? impl().cmdID
379 Command::isAnonymous()
const 381 return not CommandRegistry::instance().findDefinition (*
this);
389 Command::operator string()
const 393 repr <<
"Command(\""<<getID()<<
"\") ";
414 ___check_notBottom (
this,
"Invoking");
415 ___check_isBound (
this);
417 string cmdName{*
this};
419 return execPattern.
exec (thisCommand, cmdName);
426 ___check_notBottom (
this,
"UNDOing");
427 ___check_canUndo (
this);
429 string cmdName{*
this};
431 return execPattern.
undo (thisCommand, cmdName);
436 Command::exec (HandlingPattern::ID pattID)
438 return exec (HandlingPattern::get(pattID));
445 return undo (HandlingPattern::get(pattID));
452 return exec (HandlingPattern::get(HandlingPattern::DUMMY));
457 Command::getDefaultHandlingPattern()
const 459 ___check_notBottom (
this,
"Accessing");
460 return impl().getDefaultHandlingPattern();
465 Command::setHandlingPattern (HandlingPattern::ID pattID)
467 ___check_notBottom (
this,
"Configuring");
468 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
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
ExecResult exec(CommandImpl &command, string) const
main functionality: invoke a command, detect errors.
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)
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
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.
Derived specific exceptions within Lumiera's exception hierarchy.
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.
Result (Status) of command execution.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Steam-Layer command frontend.
Visitor to support creating a CommandImpl clone.
Pre-defined command execution skeletons.
Lumiera error handling (C++ interface).
Helper for creating an implementation clone, based on the visitor pattern.
Handle object representing a single Command instance to be used by client code.
Lumiera public interface.
shared_ptr< CommandImpl > createCloneImpl(CommandImpl const &refObject)
create an allocation for holding a clone of the given CommandImpl data.
Steam-Layer Command implementation.
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.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.