From 246c53556967b68cc19a0e93ece802e286e77188 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 21 Sep 2009 03:15:06 +0200 Subject: [PATCH] Rewrite CmdClosure to actually invoke rather then to create a tr1::bind term basically this should close Ticket #205 (some details missing) --- src/proc/control/command-argument-holder.hpp | 4 +- src/proc/control/command-closure.hpp | 40 ++++++++----------- src/proc/control/command-impl.cpp | 10 ++++- src/proc/control/command-impl.hpp | 23 ++++++----- src/proc/control/command-mutation.hpp | 4 +- .../proc/control/command-argument-test.cpp | 7 ++-- .../proc/control/command-mutation-test.cpp | 19 ++------- 7 files changed, 51 insertions(+), 56 deletions(-) diff --git a/src/proc/control/command-argument-holder.hpp b/src/proc/control/command-argument-holder.hpp index 0d04a25df..f707efe4a 100644 --- a/src/proc/control/command-argument-holder.hpp +++ b/src/proc/control/command-argument-holder.hpp @@ -151,14 +151,14 @@ namespace control { } - virtual CmdFunctor closeArguments (CmdFunctor const& func) + virtual void invoke (CmdFunctor const& func) { if (!isValid()) throw lumiera::error::State ("Lifecycle error: can't bind functor, " "command arguments not yet provided", LUMIERA_ERROR_UNBOUND_ARGUMENTS); - return arguments_->closeArguments(func); + arguments_->invoke(func); } diff --git a/src/proc/control/command-closure.hpp b/src/proc/control/command-closure.hpp index c1be0c4eb..da173bb8d 100644 --- a/src/proc/control/command-closure.hpp +++ b/src/proc/control/command-closure.hpp @@ -126,13 +126,13 @@ namespace control { public: virtual ~CmdClosure() {} - virtual operator string() const =0; + virtual operator string() const =0; - virtual bool isValid () const =0; + virtual bool isValid () const =0; - virtual void bindArguments (Arguments&) =0; + virtual void bindArguments (Arguments&) =0; - virtual CmdFunctor closeArguments (CmdFunctor const&) =0; + virtual void invoke (CmdFunctor const&) =0; virtual PClo createClone (TypedAllocationManager&) =0; }; @@ -213,8 +213,8 @@ namespace control { typedef typename FunctionSignature< function >::Args Args; - typedef BuildTupleAccessor Accessor; - typedef typename BuildAccessor::Accessor ParamStorageTuple; + typedef BuildTupleAccessor Builder; + typedef typename Builder::Accessor ParamStorageTuple; ParamStorageTuple params_; @@ -222,7 +222,7 @@ namespace control { typedef Tuple ArgTuple; Closure (ArgTuple const& args) - : params_(Accessor(args)) + : params_(Builder (args)) { } /** create a clone copy of this, without disclosing the exact type */ @@ -240,26 +240,19 @@ namespace control { } - /** Core operation: use the embedded argument tuple - * to close a given functor over its arguments. - * @param unboundFunctor an function object, whose - * function arguments are required to match - * the types of the embedded ParamStorageTuple - * @return new functor object containing the function, - * which is created by binding all arguments of the - * input functor. + /** Core operation: use the embedded argument tuple for invoking a functor + * @param unboundFunctor an function object, whose function arguments are + * required to match the types of the embedded ParamStorageTuple * @note ASSERTION failure if the function signature * doesn't match the argument types tuple. - * @note when finally invoked, the functor, which is - * bound here to the argument tuple, might actually - * \em modify the param values. Thus this function - * can't be const. + * @note the functor might actually \em modify the param values. + * Thus this function can't be const. */ - CmdFunctor - closeArguments (CmdFunctor const& unboundFunctor) + void + invoke (CmdFunctor const& unboundFunctor) { - return CmdFunctor (TupleApplicator (params_) - .bind ( unboundFunctor.getFun()) ); + TupleApplicator apply_this_arguments(params_); + apply_this_arguments (unboundFunctor.getFun()); } @@ -289,6 +282,5 @@ namespace control { - } // namespace control #endif diff --git a/src/proc/control/command-impl.cpp b/src/proc/control/command-impl.cpp index f8b31dd2b..79e5cfddd 100644 --- a/src/proc/control/command-impl.cpp +++ b/src/proc/control/command-impl.cpp @@ -31,6 +31,7 @@ #include "proc/control/command-impl.hpp" +#include "proc/control/command-argument-holder.hpp" //#include "proc/mobject/mobject-ref.hpp" //#include "proc/mobject/mobject.hpp" //#include "proc/mobject/placement.hpp" @@ -49,7 +50,14 @@ namespace control { /////////////////////////////////////////TODO: is this impl file actually necessary?? - + bool + CommandImpl::hasUndoState (CmdClosure const& closure) + { + UNIMPLEMENTED ("how the hell do we get at the memento-captured state???"); +// REQUIRE (INSTANCEOF (ArgumentHolder, &closure)); +// return static_cast (closure).canUndo(); + } + diff --git a/src/proc/control/command-impl.hpp b/src/proc/control/command-impl.hpp index a3551dd90..561a10331 100644 --- a/src/proc/control/command-impl.hpp +++ b/src/proc/control/command-impl.hpp @@ -43,8 +43,8 @@ #define CONTROL_COMMAND_IMPL_H #include "proc/control/command.hpp" +#include "proc/control/command-closure.hpp" #include "proc/control/command-mutation.hpp" -#include "proc/control/command-argument-holder.hpp" #include "proc/control/typed-allocation-manager.hpp" #include "lib/bool-checkable.hpp" @@ -59,11 +59,15 @@ namespace control { using std::tr1::function; using std::tr1::shared_ptr; - + /** - * @todo Type-comment + * Proc-Layer Command implementation. + * Data record holding together the parts necessary for command execution + * - command operation functor + * - a functor to UNDO the command effect + * - closure holding actual parameters and UNDO state */ class CommandImpl : public lib::BoolCheckable +#include #include #include #include @@ -325,9 +326,9 @@ namespace test { typedef function OpFun; // now close all the functions with the stored parameter values... - OpFun bound_doItFun = args.closeArguments (CmdFunctor(doItFun)).getFun(); - OpFun bound_undoFun = args.closeArguments (CmdFunctor(undoFun)).getFun(); - OpFun bound_captFun = args.closeArguments (CmdFunctor(captFun)).getFun(); + OpFun bound_doItFun = std::tr1::bind (&CmdClosure::invoke, args, CmdFunctor(doItFun)); + OpFun bound_undoFun = std::tr1::bind (&CmdClosure::invoke, args, CmdFunctor(undoFun)); + OpFun bound_captFun = std::tr1::bind (&CmdClosure::invoke, args, CmdFunctor(captFun)); protocol.seekp(0); protocol << "START..."; diff --git a/tests/components/proc/control/command-mutation-test.cpp b/tests/components/proc/control/command-mutation-test.cpp index f8f8877ad..d02822743 100644 --- a/tests/components/proc/control/command-mutation-test.cpp +++ b/tests/components/proc/control/command-mutation-test.cpp @@ -98,11 +98,12 @@ namespace test { void checkMutation () { - function funky = testFunc; + typedef void SIG_fun(int); + function funky = testFunc; Mutation functor (funky); - MissingArguments nullClosure; + MissingArguments nullClosure; ASSERT (!nullClosure); cout << "empty placeholder closure: " << nullClosure << endl; VERIFY_ERROR (UNBOUND_ARGUMENTS, functor(nullClosure) ); @@ -151,14 +152,13 @@ namespace test { UndoMutation undoFunctor (mementoHolder); ASSERT (!mementoHolder); - MissingArguments nullClosure; + MissingArguments nullClosure; VERIFY_ERROR (UNBOUND_ARGUMENTS, undoFunctor(nullClosure) ); VERIFY_ERROR (UNBOUND_ARGUMENTS, undoFunctor.captureState(nullClosure) ); Tuple > param; Closure clo (param); - undoFunctor.close(clo); ASSERT (!mementoHolder); VERIFY_ERROR (MISSING_MEMENTO, undoFunctor (clo) ); VERIFY_ERROR (MISSING_MEMENTO, mementoHolder.getState() ); @@ -182,17 +182,6 @@ namespace test { testVal = 9; undoFunctor(clo); ASSERT (testVal == 42); - - UndoMutation clonedFunc (undoFunctor); // refers to the same state - ASSERT (clonedFunc); - - ASSERT (33 == mementoHolder.getState()); - clonedFunc.captureState(clo); - ASSERT (42 == mementoHolder.getState()); // and captures into the same storage - - testVal = 0; - clonedFunc(clo); - ASSERT (testVal == 42); }