helper for accepting arguments passes unit test

This commit is contained in:
Fischlurch 2009-07-12 23:21:37 +02:00
parent 30db042b16
commit fa3d596a59
4 changed files with 40 additions and 41 deletions

View file

@ -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 <tr1/memory>
//#include <boost/scoped_ptr.hpp>
//#include <tr1/functional>
//#include <iostream>
//#include <string>
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<TAR*> (this) -> bind (tuple::makeNullTuple() );
static_cast<TAR*> (this) -> bindArg (tuple::makeNullTuple() );
}
};
@ -97,7 +85,7 @@ namespace control {
void
bind (T1 a1)
{
static_cast<TAR*> (this) -> bind (tuple::make (a1));
static_cast<TAR*> (this) -> bindArg (tuple::make (a1));
}
};
@ -112,7 +100,7 @@ namespace control {
void
bind (T1 a1, T2 a2)
{
static_cast<TAR*> (this) -> bind (tuple::make (a1,a2));
static_cast<TAR*> (this) -> bindArg (tuple::make (a1,a2));
}
};
@ -128,7 +116,7 @@ namespace control {
void
bind (T1 a1, T2 a2, T3 a3)
{
static_cast<TAR*> (this) -> bind (tuple::make (a1,a2,a3));
static_cast<TAR*> (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<TAR*> (this) -> bind (tuple::make (a1,a2,a3,a4));
static_cast<TAR*> (this) -> bindArg (tuple::make (a1,a2,a3,a4));
}
};
@ -155,7 +143,6 @@ namespace control {
struct _Type
{
typedef typename FunctionSignature< function<SIG> >::Args Args;
enum { ARG_CNT = count<typename Args::List>::value };
typedef Tuple<Args> 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<Types<T1...> >)
/** 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<Types<T1...> >)
* @param BASE the base class for inheritance chaining
*/
template<typename SIG, class TAR, class BASE>
class ArgumentTupleAccept
: bind_arg::AcceptArgs<TAR,BASE, typename _Type<SIG>::Args>
: public bind_arg::AcceptArgs<TAR,BASE, typename bind_arg::_Type<SIG>::Args>
{
};
} // namespace control

View file

@ -46,6 +46,7 @@
//#include "pre.hpp"
//#include "lib/error.hpp"
#include "proc/control/command-closure.hpp"
#include "proc/control/memento-tie.hpp"
//#include <tr1/memory>
//#include <boost/scoped_ptr.hpp>
@ -89,7 +90,7 @@ namespace control {
typedef typename CommandSignature<SIG,MEM>::UndoOp_Sig SIG_undo;
UntiedMemento()
: MementoTie<SIG,MEM> (function<SIG_undo>, function<SIG_cap>)
: MementoTie<SIG,MEM> (function<SIG_undo>(), function<SIG_cap>() )
{ }
};
@ -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<typename SIG, typename MEM>
class ArgumentHolder
@ -148,16 +154,13 @@ namespace control {
* whereas the undo functions will be wired by #tie
*/
ArgumentHolder ()
: arguments_(MissingArguments<SIG>)
, memento_(UntiedMemento<SIG,MEM>)
: arguments_(MissingArguments<SIG>() )
, memento_(UntiedMemento<SIG,MEM>() )
{ }
/** 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,

View file

@ -19,6 +19,14 @@ out: saved state: 11
END
TEST "build argument accepting function" ArgumentTupleAccept_test <<END
out: sizeof\( .+control.+TestClass.+ \) = 1
out: sizeof\( .+control.+TestClass.+lumiera.Time.+ \) = ( 8)|(16)
out: 00:..:..\.000
return: 0
END
TEST "Memento binding" MementoTie_test <<END
return: 0
END

View file

@ -50,6 +50,7 @@ test_components_SOURCES = \
$(testcomponents_srcdir)/proc/control/command-basic-test.cpp \
$(testcomponents_srcdir)/proc/control/command-argument-test.cpp \
$(testcomponents_srcdir)/proc/control/command-mutation-test.cpp \
$(testcomponents_srcdir)/proc/control/argument-tuple-accept-test.cpp \
$(testcomponents_srcdir)/proc/control/memento-tie-test.cpp \
$(testcomponents_srcdir)/proc/engine/bufftabletest.cpp \
$(testcomponents_srcdir)/proc/engine/sourcenodetest.cpp \