diff --git a/src/lib/util.hpp b/src/lib/util.hpp index ccbb23b80..a72f6c2b1 100644 --- a/src/lib/util.hpp +++ b/src/lib/util.hpp @@ -107,7 +107,7 @@ namespace util { /** shortcut for set value containment test */ template inline bool - contains (std::set& set, const T& val) + contains (std::set& set, T const& val) { return set.end() != set.find (val); } @@ -247,7 +247,7 @@ namespace util { \endverbatim * @see sanitised-identifier-test.cpp */ - string sanitise (const string& org); + string sanitise (string const& org); @@ -256,7 +256,7 @@ namespace util { * usable for printf with objects providing to-string conversion. */ inline const char* - cStr (const string& org) + cStr (string const& org) { return org.c_str(); } diff --git a/src/proc/control/command-registry.hpp b/src/proc/control/command-registry.hpp index 3d25fd016..b82a27986 100644 --- a/src/proc/control/command-registry.hpp +++ b/src/proc/control/command-registry.hpp @@ -161,11 +161,5 @@ namespace control { }; -// inline ostream& operator<< (ostream& os, Mutation const& muta) { return os << string(muta); } - - /** storage for the singleton factory used to access CommandRegistry */ - lumiera::Singleton CommandRegistry::instance; - - } // namespace control #endif diff --git a/src/proc/control/command.cpp b/src/proc/control/command.cpp index 89ffcb5c9..690c51b03 100644 --- a/src/proc/control/command.cpp +++ b/src/proc/control/command.cpp @@ -63,6 +63,11 @@ namespace control { LUMIERA_ERROR_DEFINE (MISSING_MEMENTO, "Undo functor not yet usable, because no undo state has been captured"); + + /** storage for the singleton factory used to access CommandRegistry */ + lumiera::Singleton CommandRegistry::instance; + + Command::~Command() { } @@ -81,6 +86,19 @@ namespace control { } + /** @todo this is a "nice-to-have"; it would allow to call a function as a command, + * almost as if it was a normal function. But this function needs to be defined + * as a command previously, together with a suitable UNDO function. Moreover + * this would probably require to build an additional index; + * thus this feature is unimplemented for the time being. + */ + Command + Command::get (FuncPtr funcP) + { + UNIMPLEMENTED ("find a command definition which was based on the given function (ptr)"); + } + + Command Command::fetchDef (Symbol cmdID) { @@ -221,33 +239,34 @@ namespace control { - void + ExecResult Command::undo () { HandlingPattern const& defaultPattern = HandlingPattern::get (getDefaultHandlingPattern()); - exec (defaultPattern.howtoUNDO()); + + return exec (defaultPattern.howtoUNDO()); } - void + ExecResult Command::exec (HandlingPattern const& execPattern) { - execPattern (*this); + return execPattern (*this); } - void + ExecResult Command::exec (HandlingPattern::ID pattID) { - HandlingPattern::get(pattID) (*this); + return HandlingPattern::get(pattID) (*this); } - void + ExecResult Command::execSync () { - exec (HandlingPattern::get(HandlingPattern::SYNC_THROW)); + return exec (HandlingPattern::get(HandlingPattern::SYNC_THROW)); } @@ -263,17 +282,6 @@ namespace control { { UNIMPLEMENTED ("manage handling patterns in general"); } - - - template - void - Command::bindArg (Tuple const& args) - { - UNIMPLEMENTED ("create an argument-binding, with runtime type check"); - } - - - diff --git a/src/proc/control/command.hpp b/src/proc/control/command.hpp index a4674279f..0cd713e1f 100644 --- a/src/proc/control/command.hpp +++ b/src/proc/control/command.hpp @@ -62,6 +62,8 @@ namespace control { LUMIERA_ERROR_DECLARE (INVALID_ARGUMENTS); ///< Arguments provided for binding doesn't match stored command function parameters + + typedef void* FuncPtr; class CommandDef; class CommandImpl; @@ -80,6 +82,7 @@ namespace control { public: /* === command registry === */ static Command get (Symbol cmdID); + static Command get (FuncPtr func); static bool remove (Symbol cmdID); static bool undef (Symbol cmdID); @@ -149,6 +152,16 @@ namespace control { } + template + inline Command& + Command::bindArg (Tuple const&) + { + UNIMPLEMENTED("delegate argument binding to command-impl"); + return *this; + } + + + inline bool operator== (Command const& c1, Command const& c2) { diff --git a/tests/components/proc/control/command-use1-test.cpp b/tests/components/proc/control/command-use1-test.cpp index 60f100361..f004f7006 100644 --- a/tests/components/proc/control/command-use1-test.cpp +++ b/tests/components/proc/control/command-use1-test.cpp @@ -32,7 +32,7 @@ //#include "proc/mobject/placement.hpp" //#include "proc/mobject/placement-index.hpp" //#include "proc/mobject/explicitplacement.hpp" -#include "proc/control/command.hpp" +#include "proc/control/command-invocation.hpp" #include "proc/control/command-def.hpp" //#include "lib/lumitime.hpp" #include "lib/format.hpp" @@ -157,11 +157,11 @@ namespace test { ASSERT ( 0 == command1::check_); // the following shortcut does the same: - Command::invoke ("test.command1.2", 1234); + invoke ("test.command1.2") (1234); ASSERT ( 1234 == command1::check_); // another shortcut, with static type check: - invoke (command1::operate, 5678); + invoke (command1::operate) (5678); ASSERT ( 1234+5678 == command1::check_); com.undo(); @@ -282,6 +282,7 @@ namespace test { ASSERT (Command::get("test.command1.4")); VERIFY_ERROR (INVALID_COMMAND, Command::get("miracle")); + VERIFY_ERROR (INVALID_COMMAND, invoke ("miracle") (1,2,3)); CommandDef unbelievable ("miracle"); ASSERT (!unbelievable); diff --git a/tests/components/proc/control/command-use3-test.cpp b/tests/components/proc/control/command-use3-test.cpp index 03048599c..f922c55d6 100644 --- a/tests/components/proc/control/command-use3-test.cpp +++ b/tests/components/proc/control/command-use3-test.cpp @@ -100,7 +100,7 @@ namespace test { .captureUndo (command1::capture) .undoOperation (command1::undoIt); - UNIMPLEMENTED ("more elaborate command handling patterns") + UNIMPLEMENTED ("more elaborate command handling patterns"); ////////////////////////////////////////////////////////////////////////////////TODO: devise tests for async, repeated and compound sequences ASSERT (cnt_inst == Command::instance_count()); diff --git a/tests/components/proc/control/test-dummy-commands.hpp b/tests/components/proc/control/test-dummy-commands.hpp index b3a2a9c45..fe24a059a 100644 --- a/tests/components/proc/control/test-dummy-commands.hpp +++ b/tests/components/proc/control/test-dummy-commands.hpp @@ -86,21 +86,21 @@ namespace test { namespace command1 { ///< test command just adding a given value - long check_ = 0; + static long check_ = 0; - void + inline void operate (int someVal) { check_ += someVal; } - long + inline long capture (int) { return check_; } - void + inline void undoIt (int, long oldVal) { check_ = oldVal; @@ -117,12 +117,12 @@ namespace test { using lumiera::error::External; - ostringstream check_; + static ostringstream check_; typedef function FunS; - void + inline void operate (FunS func, bool fail) { if (fail) throw External("simulated exception"); @@ -130,13 +130,13 @@ namespace test { check_ << func(); } - string + inline string capture (FunS, bool) { return check_.str(); } - void + inline void undoIt (FunS, bool fail, string previousProtocol) { if (fail) throw External("simulated exception in UNDO");