From fa3d596a5960bb98fa9e821d8e05da0191e2abd7 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 12 Jul 2009 23:21:37 +0200 Subject: [PATCH] helper for accepting arguments passes unit test --- src/proc/control/argument-tuple-accept.hpp | 51 ++++++++------------ src/proc/control/command-argument-holder.hpp | 21 ++++---- tests/45controller.tests | 8 +++ tests/components/Makefile.am | 1 + 4 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/proc/control/argument-tuple-accept.hpp b/src/proc/control/argument-tuple-accept.hpp index 043a6d6fb..2c847d8d5 100644 --- a/src/proc/control/argument-tuple-accept.hpp +++ b/src/proc/control/argument-tuple-accept.hpp @@ -22,11 +22,11 @@ /** @file argument-tuple-accept.hpp - ** This template allows to mix in a \c bind(...) function. - ** Thereby, the correct number and types of arguments is derived - ** according to the function signature given as template parameter. - ** This helper template is used for the ArgumentHolder and generally - ** for binding arguments for Proc-Layer commands. + ** The ArgumentTupleAccept template allows to mix in a \c bind(...) function. + ** Thereby, the correct number and types of arguments is derived according to + ** the function signature given as template parameter. This helper template is + ** used for the ArgumentHolder and generally for binding the arguments when + ** defining Proc-Layer commands. ** ** @see CommandDef ** @see ArgumentHolder @@ -39,34 +39,22 @@ #ifndef CONTROL_ARGUMENT_TUPLE_ACCEPT_H #define CONTROL_ARGUMENT_TUPLE_ACCEPT_H -//#include "pre.hpp" -//#include "lib/error.hpp" #include "lib/meta/typelist.hpp" -#include "lib/meta/typelist-util.hpp" #include "lib/meta/function.hpp" #include "lib/meta/tuple.hpp" -//#include -//#include -//#include -//#include -//#include - namespace control { -// using lumiera::Symbol; -// using std::tr1::shared_ptr; -// using boost::scoped_ptr; -// using std::tr1::function; -// using std::ostream; -// using std::string; - namespace bind_arg { + namespace bind_arg { // internals.... using namespace lumiera::typelist; + + /** @internal mix in a \c bind() function + */ template< class TAR, class BA , typename TYPES > @@ -83,7 +71,7 @@ namespace control { void bind () { - static_cast (this) -> bind (tuple::makeNullTuple() ); + static_cast (this) -> bindArg (tuple::makeNullTuple() ); } }; @@ -97,7 +85,7 @@ namespace control { void bind (T1 a1) { - static_cast (this) -> bind (tuple::make (a1)); + static_cast (this) -> bindArg (tuple::make (a1)); } }; @@ -112,7 +100,7 @@ namespace control { void bind (T1 a1, T2 a2) { - static_cast (this) -> bind (tuple::make (a1,a2)); + static_cast (this) -> bindArg (tuple::make (a1,a2)); } }; @@ -128,7 +116,7 @@ namespace control { void bind (T1 a1, T2 a2, T3 a3) { - static_cast (this) -> bind (tuple::make (a1,a2,a3)); + static_cast (this) -> bindArg (tuple::make (a1,a2,a3)); } }; @@ -145,7 +133,7 @@ namespace control { void bind (T1 a1, T2 a2, T3 a3, T4 a4) { - static_cast (this) -> bind (tuple::make (a1,a2,a3,a4)); + static_cast (this) -> bindArg (tuple::make (a1,a2,a3,a4)); } }; @@ -155,7 +143,6 @@ namespace control { struct _Type { typedef typename FunctionSignature< function >::Args Args; - enum { ARG_CNT = count::value }; typedef Tuple ArgTuple; }; @@ -164,18 +151,18 @@ namespace control { - /** Helper: mix in a \c bind(...) function - * @param SIG function signature to mimic (regarding the arguments; return type will be void) - * @param TAR the target class providing a function \c bind(Tuple >) + /** Helper Template for Proc-Layer control::Command : mix in a \c bind(...) function + * @param SIG function signature to mimic (regarding the arguments; return type will be void) + * @param TAR the target class providing a function \c bindArg(Tuple >) * @param BASE the base class for inheritance chaining */ template class ArgumentTupleAccept - : bind_arg::AcceptArgs::Args> + : public bind_arg::AcceptArgs::Args> { }; - + } // namespace control diff --git a/src/proc/control/command-argument-holder.hpp b/src/proc/control/command-argument-holder.hpp index 351c5a7d5..e196e4698 100644 --- a/src/proc/control/command-argument-holder.hpp +++ b/src/proc/control/command-argument-holder.hpp @@ -46,6 +46,7 @@ //#include "pre.hpp" //#include "lib/error.hpp" #include "proc/control/command-closure.hpp" +#include "proc/control/memento-tie.hpp" //#include //#include @@ -89,7 +90,7 @@ namespace control { typedef typename CommandSignature::UndoOp_Sig SIG_undo; UntiedMemento() - : MementoTie (function, function) + : MementoTie (function(), function() ) { } }; @@ -99,9 +100,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 + * can be in \em empty state; there is no distinct + * lifecycle limitations. ArgumentHolder is part + * of Proc-Layer command's implementation + * and should not be used standalone. */ template class ArgumentHolder @@ -148,16 +154,13 @@ namespace control { * whereas the undo functions will be wired by #tie */ ArgumentHolder () - : arguments_(MissingArguments) - , memento_(UntiedMemento) + : arguments_(MissingArguments() ) + , memento_(UntiedMemento() ) { } /** has undo state capturing been invoked? */ - bool - canUndo () - { - return bool(memento_); - } + bool canUndo () { return bool(memento_); } + bool empty () { return !arguments_; } /** store a new argument tuple within this ArgumentHolder, diff --git a/tests/45controller.tests b/tests/45controller.tests index 5f4cc95f2..908d1ea6c 100644 --- a/tests/45controller.tests +++ b/tests/45controller.tests @@ -19,6 +19,14 @@ out: saved state: 11 END +TEST "build argument accepting function" ArgumentTupleAccept_test <