Command-Framework: mark anonymous commands

It turns out we *do* support the use of anonymous commands
(while it is not clear yet if we really need this feature).

Basically, client code may either create and register a new
instance from another command used as prototype, by invoking
Command::storeDef(ID). Or, alternatively it may just invoke
newInstance() on the command, which creates a new handle
and a valid new implementation (managed by the handle as
smart-ptr), but never stores this implementation into the
CommandRegistry. In that case, client code may use such a
command just fine, as long as it cares to hold onto that
handle; but it is not possible to retrieve this command
instance later by symbolic ID.

In the light of this (possible) usage pattern, it doesn't
make sense to throw when accessing a command-ID. Rather, we
now return a placeholder-Symbol ("_anonymous_")
This commit is contained in:
Fischlurch 2016-12-25 21:46:58 +01:00
parent 387a553e98
commit b58427e49f
4 changed files with 26 additions and 24 deletions

View file

@ -29,10 +29,10 @@
** command implementation need to be cloned and re-wired with the cloned partners,
** which requires re-creating the specifically typed context used at initial setup.
**
** Ticket #301 : it may well be that the need for such a facility is a symptom of
** misaligned design, but I rather doubt so -- because both the memento holder and
** @todo Ticket #301 : it may well be that the need for such a facility is a symptom
** of misaligned design, but I rather doubt so -- because both the memento holder and
** the command closure need a specifically typed context, and there is no reason
** for combining them into a single facility.
** for combining them into a single facility.
**
** @see CommandRegistry#createCloneImpl
** @see CommandImpl
@ -46,26 +46,17 @@
#ifndef CONTROL_COMMAND_IMPL_CLONE_BUILDER_H
#define CONTROL_COMMAND_IMPL_CLONE_BUILDER_H
//#include "proc/control/command.hpp"
//#include "proc/control/command-closure.hpp"
#include "proc/control/command-mutation.hpp"
#include "lib/typed-allocation-manager.hpp"
#include "lib/opaque-holder.hpp"
//#include "lib/bool-checkable.hpp"
#include <boost/noncopyable.hpp>
//#include <boost/operators.hpp>
//#include <memory>
//#include <functional>
namespace proc {
namespace control {
using lib::TypedAllocationManager;
// using std::function;
// using std::shared_ptr;
using lib::InPlaceBuffer;
@ -159,7 +150,7 @@ namespace control {
{
REQUIRE (!newContext_->isValid(), "Lifecycle-Error");
newContext_.create<impl::ClonedContext> (origArgHolder, allocator_);
newContext_.create<impl::ClonedContext> (origArgHolder, allocator_);
}

View file

@ -349,14 +349,29 @@ namespace control {
}
namespace {
const Symbol ANONYMOUS_CMD_SYMBOL("_anonymous_");
}
Symbol
Command::getID() const
{
////////////////////////////////////////////////////////////////////TODO do we need no-throw guarantee here?
Symbol id = CommandRegistry::instance().findDefinition (*this);
if (!id)
throw error::State("Encountered a NIL command handle while expecting a bound one."
,error::LUMIERA_ERROR_BOTTOM_VALUE);
return id;
return id? id
: ANONYMOUS_CMD_SYMBOL;
}
/** @return `true` when this command (front-end) was never registered
* with the CommandRegistry; typically this is the case with instances
* created from a prototype, when calling Command::newInstance instead
* of invoking Command::storeDef(Symbol).
*/
bool
Command::isAnonymous() const
{
return not CommandRegistry::instance().findDefinition (*this);
}
@ -367,13 +382,8 @@ namespace control {
Command::operator string() const
{
ostringstream repr;
repr << "Command";
////////////////////////////////////////////////////////////////////TODO do we need no-throw guarantee here?
Symbol id = CommandRegistry::instance().findDefinition (*this);
if (id)
repr << "(\""<<id<<"\") ";
else
repr << "(_xxx_) ";
repr << "Command(\""<<getID()<<"\") ";
if (!isValid())
repr << "NIL";
else

View file

@ -181,6 +181,7 @@ namespace control {
void duplicate_detected (Symbol) const;
Symbol getID() const;
bool isAnonymous() const;
operator string() const;
friend bool operator== (Command const&, Command const&);

View file

@ -99,7 +99,7 @@ out: Command\("test.command1.1"\) \{undo\}
out: Command\("test.command1.2"\) \{undo\}
out: Command\("test.command1.3"\) \{undo\}
out: Command\("test.command1.4"\) \{undo\}
out: Command\(_xxx_\) NIL
out: Command\("_anonymous_"\) NIL
out: Command\("test.command1.5"\) \{def\}
out: Command\("test.command1.5"\) \{exec\}
out: Command\("test.command1.5"\) \{undo\}