From a19892ac6a6412496f892e4e0864b68759ef4ef7 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 29 Jun 2009 06:33:42 +0200 Subject: [PATCH] WIP some steps towards a solution of the memento binding problem --- src/lumiera/main.cpp | 2 +- tests/40components.tests | 17 ++- .../proc/control/command-argument-test.cpp | 9 +- tests/lib/Makefile.am | 1 + tests/lib/meta/function-closure-test.cpp | 1 - tests/lib/meta/function-composition-test.cpp | 143 +++++++++++------- 6 files changed, 108 insertions(+), 65 deletions(-) diff --git a/src/lumiera/main.cpp b/src/lumiera/main.cpp index 002961de4..f5555e927 100644 --- a/src/lumiera/main.cpp +++ b/src/lumiera/main.cpp @@ -2,7 +2,7 @@ main.cpp - start the Lumiera Application Copyright (C) Lumiera.org - 2007-2008, Joel Holdsworth + 2007-2009, Joel Holdsworth Christian Thaeter Hermann Vosseler diff --git a/tests/40components.tests b/tests/40components.tests index 3a4c87f80..74592e8ab 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -234,7 +234,7 @@ out: dtor ~TargetObj\(12\) successful END -TEST "FunctionClosure_test" FunctionClosure_test <-<2>-<3>- out: List2 :-<5>-<6>-<7>- out: Args :-<5>-<9>- @@ -251,7 +251,12 @@ return: 0 END -TEST "FunctionErasure_test" FunctionErasure_test <-<1>-<2>- out: Overl11 :-<1>-<2>-<3>- out: Overl12 :-<1>-<2>-<3>- out: Overl13 :-<1>-<2>-<3>- +out: Front1 :- +out: Front2 :-<1>- +out: Front3 :-<1>-<2>-<3>- +out: Back1 :-<2>-<3>- +out: Back2 :-<3>- +out: Back3 :- +out: Front4 :-<1>- +out: Back4 :-<2>-<3>- out: FilterEven :-<2>-<6>- out: Prefix1 : out: \+---<11>-<22>-\+- diff --git a/tests/components/proc/control/command-argument-test.cpp b/tests/components/proc/control/command-argument-test.cpp index 4d6020e87..578376671 100644 --- a/tests/components/proc/control/command-argument-test.cpp +++ b/tests/components/proc/control/command-argument-test.cpp @@ -82,14 +82,9 @@ namespace test { /*************************************************************************** - * Verify the behaviour of the type erased closure, which is used - * by Proc-Layer commands to implement the capturing and later - * re-invocation of a function. + * @test storing and retrieving command arguments of various types. * - * @see control::Command - * @see control::CommandDef - * @see control::Mutation - * @see control::UndoMutation + * @see control::CommandArgumentHolder * @see command-basic-test.hpp */ class CommandArgument_test : public Test diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 335d2d351..9277521de 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -50,6 +50,7 @@ test_lib_SOURCES = \ $(testlib_srcdir)/meta/typelist-test.cpp \ $(testlib_srcdir)/meta/typelist-manip-test.cpp \ $(testlib_srcdir)/meta/type-tuple-test.cpp \ + $(testlib_srcdir)/meta/function-composition-test.cpp \ $(testlib_srcdir)/meta/function-closure-test.cpp \ $(testlib_srcdir)/meta/function-erasure-test.cpp \ $(testlib_srcdir)/meta/generator-test.cpp \ diff --git a/tests/lib/meta/function-closure-test.cpp b/tests/lib/meta/function-closure-test.cpp index 72b458cf8..0a0cce750 100644 --- a/tests/lib/meta/function-closure-test.cpp +++ b/tests/lib/meta/function-closure-test.cpp @@ -41,7 +41,6 @@ #include "lib/meta/typelistutil.hpp" #include "lib/meta/function.hpp" #include "lib/meta/function-closure.hpp" -#include "meta/dummy-functions.hpp" #include "meta/typelist-diagnostics.hpp" #include "meta/tuple-diagnostics.hpp" diff --git a/tests/lib/meta/function-composition-test.cpp b/tests/lib/meta/function-composition-test.cpp index 72b458cf8..85701bace 100644 --- a/tests/lib/meta/function-composition-test.cpp +++ b/tests/lib/meta/function-composition-test.cpp @@ -1,5 +1,5 @@ /* - FunctionClosure(Test) - appending, mixing and filtering typelists + FunctionComposition(Test) - functional composition and partial application Copyright (C) Lumiera.org 2009, Hermann Vosseler @@ -21,29 +21,12 @@ * *****************************************************/ -/** @file function-closure-test.cpp - ** Testing a combination of tr1::function objects and metaprogramming. - ** Argument types will be extracted and represented as typelist, so they - ** can be manipulated at compile time. This test uses some functions with - ** and systematically applies or binds them to corresponding data tuples. - ** Moreover, closure objects will be constructed in various flavours, - ** combining a function object and a set of parameters. - ** - ** @see function-closure.hpp - ** @see control::CmdClosure real world usage example - ** - */ - - #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" #include "lib/meta/typelist.hpp" -#include "lib/meta/typelistutil.hpp" #include "lib/meta/function.hpp" #include "lib/meta/function-closure.hpp" -#include "meta/dummy-functions.hpp" #include "meta/typelist-diagnostics.hpp" -#include "meta/tuple-diagnostics.hpp" #include @@ -56,13 +39,16 @@ using std::endl; namespace lumiera { namespace typelist{ namespace test { - - - namespace { // test data + + using func::applyFirst; + using func::applyLast; + + + namespace { // test functions - typedef Types< Num<1> + typedef Types< Num<1> ////////////////////////TODO kill kill kill , Num<2> , Num<3> >::List List1; @@ -71,51 +57,100 @@ namespace test { , Num<7> >::List List2; + Num<1> _1_; + Num<2> _2_; + Num<3> _3_; + Num<4> _4_; + Num<5> _5_; + Num<6> _6_; + Num<7> _7_; + Num<8> _8_; + Num<9> _9_; - /** special test fun - * accepting the terrific Num types */ - template - int - getNumberz (Num one, Num two, Num three) + /** "Function-1" will be used at the front side, accepting a tuple of values */ + template + Num + fun1 ( Num val1 + ) { - return one.o_ + two.o_ + three.o_; + return val1; + } + + template + Num + fun1 ( Num val1 + , Num val2 + ) + { + val1.o_ += val2.o_; + return val1; + } + + template + Num + fun1 ( Num val1 + , Num val2 + , Num val3 + ) + { + val1.o_ += val2.o_ + val3.o_; + return val1; + } + + template + Num + fun1 ( Num val1 + , Num val2 + , Num val3 + , Num val4 + ) + { + val1.o_ += val2.o_ + val3.o_ + val4.o_; + return val1; + } + + template + Num + fun1 ( Num val1 + , Num val2 + , Num val3 + , Num val4 + , Num val5 + ) + { + val1.o_ += val2.o_ + val3.o_ + val4.o_ + val5.o_; + return val1; } - int fun0 () { return -1; } - int fun1 (int i1) { return i1; } - int fun2 (int i1, int i2) { return i1+i2; } - int fun3 (int i1, int i2, int i3) { return i1+i2+i3; } + /** "Function-2" can be chained behind fun1 */ + template + int + fun2 (II val) + { + return val.o_; + } } // (End) test data - - - - - - - /************************************************************************* - * @test building a function closure for a given function or functor, - * while arguments are passed in as tuple - * - accessing signatures as typelists - * - apply free function to tuple - * - apply functor to tuple - * - bind free function to tuple - * - bind functor to tuple - * - build a simple "tuple closure" + + + + + + + /****************************************************************************** + * @test this test covers some extensions and variations on function closures: + * - partial application of a function, returning a binder + * - chaining of two functions with suitable arguemnts ("composition") */ - class FunctionClosure_test : public Test + class FunctionComposition_test : public Test { virtual void run (Arg) { check_diagnostics (); - check_signatureTypeManip (); - check_applyFree (); - check_applyFunc (); - check_bindFree (); - check_bindFunc (); - build_closure (); + check_partialApplication (); + check_functionalComposition (); }