improve and clean up the Command interface

This commit is contained in:
Fischlurch 2009-09-26 02:14:07 +02:00
parent 8dc434a141
commit 4c9af94e1d
2 changed files with 24 additions and 17 deletions

View file

@ -79,12 +79,15 @@ namespace control {
/** */
/** Access existing command for use.
* @throw error::Invalid if command not
* registered or incompletely defined.
*/
Command
Command::get (Symbol cmdID)
{
Command cmd = CommandRegistry::instance().queryIndex (cmdID);
static format fmt("Command definition \"%s\" not found");
static format fmt("Command \"%s\" not found");
if (!cmd)
throw error::Invalid(str(fmt % cmdID), LUMIERA_ERROR_INVALID_COMMAND);
@ -99,13 +102,15 @@ namespace control {
* thus this feature is unimplemented for the time being.
*/
Command
Command::get (FuncPtr funcP)
Command::get (FuncPtr)
{
UNIMPLEMENTED ("find a command definition which was based on the given function (ptr)");
}
Command const&
/** @internal to be invoked by CommandDef
* when starting a new definition */
Command
Command::fetchDef (Symbol cmdID)
{
CommandRegistry& registry = CommandRegistry::instance();
@ -120,10 +125,11 @@ namespace control {
} // return new or currently registered cmd...
/** @internal to be invoked by CommandDef
/** @internal to be invoked through CommandDef to make a command ready
* @throw std::bad_alloc, in which case
* CommandRegistry::killCommandImpl is invoked */
Command&
* CommandRegistry::killCommandImpl is invoked.
* @throw error::Logic when this is already activated. */
void
Command::activate (shared_ptr<CommandImpl> const& implFrame)
{
static format fmt("Command \"%s\" already defined");
@ -135,7 +141,6 @@ namespace control {
_Handle::activate (implFrame);
INFO (command, "Command \"%s\" defined OK", cStr(*this));
return *this;
}

View file

@ -122,6 +122,16 @@ namespace control {
Command() { } ///< undefined command
~Command();
/* === command lifecycle === */
void activate (shared_ptr<CommandImpl> const&);
template<typename TYPES>
Command& bindArg (Tuple<TYPES> const&);
ExecResult operator() () ;
ExecResult undo () ;
@ -145,14 +155,6 @@ namespace control {
/* === command lifecycle === */
Command& activate (shared_ptr<CommandImpl> const&);
template<typename TYPES>
Command& bindArg (Tuple<TYPES> const&);
/* === diagnostics === */
static size_t definition_count();
@ -166,7 +168,7 @@ namespace control {
protected:
static Command const& fetchDef (Symbol cmdID);
static Command fetchDef (Symbol cmdID);
friend class CommandDef;