57 using std::ostringstream;
66 LUMIERA_ERROR_DEFINE (DUPLICATE_COMMAND,
"Attempt to redefine an already existing command definition");
67 LUMIERA_ERROR_DEFINE (INVALID_ARGUMENTS,
"Arguments provided for binding doesn't match stored command function parameters");
68 LUMIERA_ERROR_DEFINE (UNBOUND_ARGUMENTS,
"Command mutation functor not yet usable, because arguments aren't bound");
69 LUMIERA_ERROR_DEFINE (MISSING_MEMENTO,
"Undo functor not yet usable, because no undo state has been captured");
83 if (!handle->isValid())
85 , LERR_(INVALID_COMMAND));
89 ___check_isBound (
const Command *handle)
92 if (!handle->canExec())
93 throw error::State (
"Lifecycle error: command arguments not bound" 94 , LERR_(UNBOUND_ARGUMENTS));
98 ___check_canUndo (
const Command *handle)
101 if (!handle->canUndo())
102 throw error::State (
"Lifecycle error: command has not yet captured UNDO information" 103 , LERR_(UNBOUND_ARGUMENTS));
115 Command::~Command() { }
116 CommandImpl::~CommandImpl() { }
131 Command cmd = CommandRegistry::instance().queryIndex (cmdID);
134 , LERR_(INVALID_COMMAND));
136 ENSURE (cmdID == CommandRegistry::instance().findDefinition(cmd));
149 Command::maybeGetNewInstance (
Symbol cmdID)
151 Command cmd = CommandRegistry::instance().queryIndex (cmdID);
161 return CommandRegistry::instance().queryIndex (cmdID);
176 duplicate_detected (cmdID);
178 _Handle::activate (move (implFrame));
181 CommandRegistry::instance().track (cmdID, *
this);
182 impl().cmdID = cmdID;
185 TRACE (command,
"%s defined OK",
cStr(*
this));
192 Command::storeDef (
Symbol newCmdID)
const 196 ___check_notBottom (
this,
"Cloning");
198 duplicate_detected (newCmdID);
202 ENSURE (cloneDefinition);
203 return cloneDefinition;
209 Command::newInstance ()
const 211 ___check_notBottom (
this,
"Cloning");
239 Command::duplicate_detected (
Symbol newCmdID)
const 242 "ID \"%s\" is already in use")
245 , LERR_(DUPLICATE_COMMAND));
250 Command::remove (
Symbol cmdID)
252 return CommandRegistry::instance().remove (cmdID);
262 ___check_notBottom (
this,
"Binding arguments of");
263 _Handle::impl().setArguments(args);
275 ___check_notBottom (
this,
"Binding arguments of");
276 _Handle::impl().setArguments(paramData);
290 ___check_notBottom (
this,
"Un-binding arguments of");
291 _Handle::impl().discardArguments();
298 Command::definition_count()
300 return CommandRegistry::instance().index_size();
307 Command::instance_count()
309 return CommandRegistry::instance().instance_count();
316 was_activated (
Command const& com)
318 return com.isValid();
322 registered_for (
Symbol id)
324 return CommandRegistry::instance().queryIndex (
id);
335 CommandDef::~CommandDef()
337 if (!was_activated (prototype_))
338 CommandRegistry::instance().remove (this->id_);
349 CommandDef::isValid()
const 351 return (was_activated (prototype_))
352 && (prototype_ == registered_for (this->id_))
359 Command::canExec()
const 367 Command::canUndo()
const 375 Command::getID()
const noexcept
377 return isValid()? impl().cmdID
388 Command::isAnonymous()
const 390 return not CommandRegistry::instance().findDefinition (*
this);
398 Command::operator string()
const 402 repr <<
"Command(\""<<getID()<<
"\") ";
423 ___check_notBottom (
this,
"Invoking");
424 ___check_isBound (
this);
426 string cmdName{*
this};
428 return execPattern.
exec (thisCommand, cmdName);
435 ___check_notBottom (
this,
"UNDOing");
436 ___check_canUndo (
this);
438 string cmdName{*
this};
440 return execPattern.
undo (thisCommand, cmdName);
445 Command::exec (HandlingPattern::ID pattID)
447 return exec (HandlingPattern::get(pattID));
454 return undo (HandlingPattern::get(pattID));
461 return exec (HandlingPattern::get(HandlingPattern::DUMMY));
466 Command::getDefaultHandlingPattern()
const 468 ___check_notBottom (
this,
"Accessing");
469 return impl().getDefaultHandlingPattern();
474 Command::setHandlingPattern (HandlingPattern::ID pattID)
476 ___check_notBottom (
this,
"Configuring");
477 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.