Commands: define typical standard usage of CommandSetup

This commit is contained in:
Fischlurch 2017-03-31 04:14:45 +02:00
parent b303bcebc0
commit 49102ff18f
3 changed files with 59 additions and 8 deletions

View file

@ -80,7 +80,7 @@ namespace control {
CommandSetup::~CommandSetup() { }
/** Start a command setup for defining a Proc-Layer command with the given cmdID */
CommandSetup::CommandSetup(Literal cmdID)
CommandSetup::CommandSetup(Symbol cmdID)
: cmdID_(cmdID)
{ }

View file

@ -69,7 +69,7 @@ namespace control {
using std::string;
// using lib::Symbol;
using lib::Literal;
using lib::Symbol;
//using std::shared_ptr;
class CommandDef;
@ -83,16 +83,16 @@ namespace control {
*/
class CommandSetup
{
Literal cmdID_;
Symbol cmdID_;
public:
~CommandSetup();
CommandSetup (Literal cmdID);
CommandSetup (Symbol cmdID);
CommandSetup (CommandSetup const&) = default;
CommandSetup (CommandSetup &&) = default;
CommandSetup& operator= (CommandSetup const&) = delete;
operator Literal const&() const
operator Symbol const&() const
{
return cmdID_;
}
@ -125,8 +125,13 @@ namespace control {
/** */
/**
* Macro to write command definitions in a compact form.
* On expansion, a variable of type CommandSetup will be defined in the current scope,
* and immediately be assigned by a lambda, whose body is what follows the macro invocation
*/
#define COMMAND_DEFINITION(_NAME_) \
CommandSetup _NAME_ = CommandSetup{STRINGIFY(_NAME_)} = [&](CommandDef& def)

View file

@ -91,6 +91,16 @@ namespace test {
{
testString = oldVal;
}
/* ==== prepare a dummy command definition ==== */
COMMAND_DEFINITION (test_CommandSetup_test)
{
def.operation(operate)
.captureUndo(capture)
.undoOperation(undoIt);
};
}
@ -234,7 +244,43 @@ namespace test {
void
verify_standardUsage()
{
UNIMPLEMENTED ("cover standard usage of command definitions");
Command{test_CommandSetup_test}
.storeDef("c1")
.storeDef("c2");
Command c1{"c1"}, c2{"c2"};
CHECK (not c1.canExec());
CHECK (not c2.canExec());
c1.bind (string{"wuz.*"}, string{"the Devonian"});
c2.bind (string{"\\s*\\w+$"}, string{""});
CHECK (c1.canExec());
CHECK (c2.canExec());
CHECK (not Command::canExec(test_CommandSetup_test));
CHECK (testString == "Ichthyostega wuz here");
c1();
CHECK (testString == "Ichthyostega the Devonian");
c2();
CHECK (testString == "Ichthyostega the");
c2();
CHECK (testString == "Ichthyostega");
c2();
CHECK (testString == "");
c1.undo();
CHECK (testString == "Ichthyostega wuz here");
Command::remove("c1");
Command::remove("c2");
CHECK (not Command::defined("c1"));
CHECK (not Command::defined("c2"));
CHECK (Command::defined(test_CommandSetup_test));
}
};