From f73c9388504f52d4914e1e91046ef849b78daf4f Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 19 Jul 2009 08:32:49 +0200 Subject: [PATCH] ArgumentHolder reworked to use InPlaceBuffer; now passes basic tests --- src/lib/meta/function-closure.hpp | 1 + src/proc/control/command-argument-holder.hpp | 15 +---- src/proc/control/memento-tie.hpp | 17 ++++++ .../proc/control/command-argument-test.cpp | 60 +++++++++++-------- 4 files changed, 56 insertions(+), 37 deletions(-) diff --git a/src/lib/meta/function-closure.hpp b/src/lib/meta/function-closure.hpp index 80173ad74..936534af9 100644 --- a/src/lib/meta/function-closure.hpp +++ b/src/lib/meta/function-closure.hpp @@ -587,6 +587,7 @@ namespace func { namespace _composed { // repetitive impl.code for function composition using std::tr1::bind; + using std::tr1::function; using std::tr1::placeholders::_1; using std::tr1::placeholders::_2; using std::tr1::placeholders::_3; diff --git a/src/proc/control/command-argument-holder.hpp b/src/proc/control/command-argument-holder.hpp index 7f3fb056a..d148223bb 100644 --- a/src/proc/control/command-argument-holder.hpp +++ b/src/proc/control/command-argument-holder.hpp @@ -163,7 +163,7 @@ namespace control { { return "Command-State{ arguments=" + (*arguments_? string(*arguments_) : "unbound") - + (*memento_ ? ", }" : "·noUNDO·}") + + ", "+string(*memento_)+"}" ; } @@ -200,21 +200,12 @@ namespace control { * @note any bound undo/capture functions based on the previously held MementoTie * are silently invalidated; using them will likely cause memory corruption! */ MementoTie& - tiesi (function const& undoFunc, + tie (function const& undoFunc, function const& captureFunc) { return memento_.template create (undoFunc,captureFunc); } - - /** @may be called directly referencing an function */ - MementoTie& - tie (SIG_undo& undoFunc, SIG_cap& captureFunc) - { - return tiesi ( function(undoFunc) - , function(captureFunc) - ); - } - + /** direct "backdoor" access to stored memento value. diff --git a/src/proc/control/memento-tie.hpp b/src/proc/control/memento-tie.hpp index ed4a44380..530c45054 100644 --- a/src/proc/control/memento-tie.hpp +++ b/src/proc/control/memento-tie.hpp @@ -43,9 +43,11 @@ #include "lib/bool-checkable.hpp" #include "lib/meta/function-closure.hpp" #include "proc/control/command-signature.hpp" +#include "lib/format.hpp" #include "lib/util.hpp" #include +#include namespace control { @@ -165,6 +167,21 @@ namespace control { { return undo_ && capture_ && isCaptured_; } + + + operator std::string() const + { + if (!undo_ || !capture_) + return "·noUNDO·"; + + if (!isCaptured_) + return ""; + + return "<" + + util::str(memento_, "mem: ", "·memento·") + + ">"; + } + }; diff --git a/tests/components/proc/control/command-argument-test.cpp b/tests/components/proc/control/command-argument-test.cpp index e796d9646..10f54923e 100644 --- a/tests/components/proc/control/command-argument-test.cpp +++ b/tests/components/proc/control/command-argument-test.cpp @@ -43,7 +43,7 @@ #include #include #include -//#include +#include #include //using std::tr1::bind; @@ -57,7 +57,7 @@ using boost::format; using lumiera::Time; //using util::contains; using std::string; -//using std::rand; +using std::rand; using std::ostream; using std::ostringstream; using std::cout; @@ -93,16 +93,9 @@ namespace test { TY element_; static int instanceCnt; - Tracker (TY init = TY()) - : element_(init) - { - ++instanceCnt; - } - - ~Tracker() - { - --instanceCnt; - } + Tracker (TY init = TY()) : element_(init) { ++instanceCnt; } + Tracker (Tracker const& otr) : element_(otr.element_) { ++instanceCnt; } + ~Tracker() { --instanceCnt; } TY& operator* () @@ -115,6 +108,8 @@ namespace test { { return out << tra.element_; } + + operator string() const { return element_; } }; template @@ -130,9 +125,9 @@ namespace test { } Tracker - captureState (Tracker