diff --git a/src/lib/meta/function-erasure.hpp b/src/lib/meta/function-erasure.hpp index eaca137d0..c267be175 100644 --- a/src/lib/meta/function-erasure.hpp +++ b/src/lib/meta/function-erasure.hpp @@ -128,7 +128,7 @@ namespace typelist{ template function& - getFun () + getFun () const { return get >(); } @@ -157,7 +157,7 @@ namespace typelist{ template SIG& - getFun () + getFun () const { SIG *fun = get(); REQUIRE (fun); diff --git a/src/proc/control/command-argument-holder.hpp b/src/proc/control/command-argument-holder.hpp index 72ce6a013..ef82f7fc6 100644 --- a/src/proc/control/command-argument-holder.hpp +++ b/src/proc/control/command-argument-holder.hpp @@ -22,18 +22,17 @@ /** @file command-argument-holder.hpp - ** A simple container record holding the actual command arguments. + ** A passive container record holding the actual command arguments & UNDO state. ** While all command objects themselves have a common type (type erasure), - ** the actual argument tuple and the state memento for undo can't. Especially, + ** the actual argument tuple and the state memento for UNDO can't. Especially, ** the size of arguments and memento will depend on their respective types. ** Thus, to manage somehow the storage of this data, we create a common holder, - ** to be managed by a custom allocator. + ** which can than be managed by a custom allocator / object pool. ** - ** @todo doing just plain heap allocation for now :-P - ** ** @see Command - ** @see UndoMutation - ** @see MementoTie + ** @see CmdClosure storage of command arguments + ** @see MementoTie wiring of UNDO functions & memento + ** @see UndoMutation execution of UNDO ** @see command-argument-test.cpp ** */ @@ -43,20 +42,17 @@ #ifndef CONTROL_COMMAND_ARGUMENT_HOLDER_H #define CONTROL_COMMAND_ARGUMENT_HOLDER_H -//#include "pre.hpp" #include "proc/control/argument-tuple-accept.hpp" #include "proc/control/command-closure.hpp" #include "proc/control/memento-tie.hpp" #include "lib/opaque-holder.hpp" -#include #include namespace control { - using boost::noncopyable; using lib::InPlaceBuffer; using std::string; @@ -96,14 +92,14 @@ namespace control { /** - * Specifically typed CmdClosure, which serves for + * Specifically typed CmdClosure, which serves for * actually allocating storage to hold the command arguments - * and the undo state (memento) for Proc-Layer commands. - * Both the contained components within ArgumentHolder + * and the UNDO state (memento) for Proc-Layer commands. + * Both the contained components within ArgumentHolder * can be in \em empty state; there are no distinct * lifecycle limitations. ArgumentHolder is part * of Proc-Layer command's implementation - * and should not be used standalone. + * and should not be used standalone. */ template class ArgumentHolder @@ -111,8 +107,10 @@ namespace control { , ArgumentHolder // target class providing the implementation , CmdClosure // base class to inherit from > - , private noncopyable { + /** copy construction allowed(but no assignment)*/ + ArgumentHolder& operator= (ArgumentHolder const&); + typedef Closure ArgHolder; typedef MementoTie MemHolder; @@ -132,13 +130,14 @@ namespace control { /* ==== proxied CmdClosure interface ==== */ + public: virtual bool isValid () const { return arguments_->isValid(); } - virtual CmdFunctor bindArguments (CmdFunctor& func) + virtual CmdFunctor bindArguments (CmdFunctor const& func) { if (!isValid()) throw lumiera::error::State ("Lifecycle error: can't bind functor, " @@ -158,7 +157,7 @@ namespace control { } - public: + /** per default, all data within ArgumentHolder * is set up in \em empty state. Later on, the * command arguments are to be provided by #bind , @@ -169,6 +168,16 @@ namespace control { , memento_() { } + /** copy construction allowed(but no assignment) */ + ArgumentHolder (ArgumentHolder const& oAh) + : arguments_() + , memento_() + { + arguments_.template create (*oAh.arguments_); + memento_.template create (*oAh.memento_); + } + + /** has undo state capturing been invoked? */ bool canUndo () const { return memento_->isValid(); } bool empty () const { return !arguments_->isValid(); } diff --git a/src/proc/control/command-closure.hpp b/src/proc/control/command-closure.hpp index 47cf48d07..d18aefbf1 100644 --- a/src/proc/control/command-closure.hpp +++ b/src/proc/control/command-closure.hpp @@ -100,7 +100,7 @@ namespace control { virtual bool isValid () const =0; - virtual CmdFunctor bindArguments (CmdFunctor&) =0; + virtual CmdFunctor bindArguments (CmdFunctor const&) =0; }; @@ -207,7 +207,7 @@ namespace control { * can't be const. */ CmdFunctor - bindArguments (CmdFunctor& unboundFunctor) + bindArguments (CmdFunctor const& unboundFunctor) { return CmdFunctor (TupleApplicator (params_) .bind ( unboundFunctor.getFun()) ); @@ -221,7 +221,7 @@ namespace control { params_.dump (buff << "Closure(" ); string dumped (buff.str()); - if (1 < dumped.length()) + if (8 < dumped.length()) // remove trailing comma... return dumped.substr (0, dumped.length()-1) +")"; else diff --git a/tests/45controller.tests b/tests/45controller.tests index 908d1ea6c..d93c7f5a0 100644 --- a/tests/45controller.tests +++ b/tests/45controller.tests @@ -7,11 +7,35 @@ PLANNED "CommandBasic_test" CommandBasic_test <. +out: would be serialised.....Command-State. arguments=Closure\(\), ·noUNDO·. +out: would be serialised.....Command-State. arguments=Closure\(.\), ·noUNDO·. +out: would be serialised.....Command-State. arguments=Closure\(.,00:..:....00\), ·noUNDO·. +out: would be serialised.....Command-State. arguments=Closure\(00:..:....00,glorious,..\), . +out: sizeof\( .+control1.ArgumentHolder.+ \) = .+ +out: Command-State. arguments=Closure\(00:..:....00,Lumiera rocks,..\), ·noUNDO·. +out: capture state... +out: captured state: START...Lumiera rocks +out: Command-State. arguments=Closure\(00:..:....00,Lumiera rocks,..\), . +out: invoke operation... +out: START...doIt\( Time=00:..:....00 "Lumiera rocks" rand=.. \) +out: undo... memento=START...Lumiera rocks +out: START...doIt\( Time=00:..:....00 "Lumiera rocks" rand=.. \)undoIt\(time=00:..:....00\)----memento-:START...Lumiera rocks +out: capture state... +out: modified: Command-State. arguments=Closure\(00:00:00.123,unbelievable,..\), . +out: copied : Command-State. arguments=Closure\(00:..:....00,Lumiera rocks,..\), . +out: undo... memento=START...doIt\( Time=00:..:....00 "Lumiera rocks" rand=.. \)undoIt\(time=00:..:....00\)----memento-:START...Lumiera rocksLumiera rocks +out: RESET...undoIt\(time=00:..:....00\)----memento-:START...doIt\( Time=00:..:....00 "Lumiera rocks" rand=.. \)undoIt\(time=00:..:....00\)----memento-:START...Lumiera rocksLumiera rocks END -TEST "Command functor" CommandMutation_test < #include #include #include #include #include -//using std::tr1::bind; -//using std::tr1::placeholders::_1; -//using std::tr1::placeholders::_2; -//using std::tr1::function; using util::isnil; -//using util::and_all; using util::for_each; -using boost::format; using lumiera::Time; -//using util::contains; +using boost::format; using std::string; -using std::rand; using std::ostream; using std::ostringstream; +using std::rand; using std::cout; using std::endl; @@ -70,13 +52,6 @@ namespace test { using lib::test::showSizeof; using lib::test::randTime; -// using session::test::TestClip; -// using lumiera::P; -// using namespace lumiera::typelist; -// using lumiera::typelist::Tuple; - -// using control::CmdClosure; - @@ -87,6 +62,10 @@ namespace test { ostringstream protocol; ///< used to verify the test function calls + /** + * watching the instance creation + * of some parameter values + */ template struct Tracker { @@ -116,26 +95,32 @@ namespace test { int Tracker::instanceCnt (0); + /* === functions to implement test-"operation" & UNDO === */ void doIt (Tracker