diff --git a/src/proc/control/command-argument-holder.hpp b/src/proc/control/command-argument-holder.hpp index ba61c0314..72ce6a013 100644 --- a/src/proc/control/command-argument-holder.hpp +++ b/src/proc/control/command-argument-holder.hpp @@ -44,31 +44,21 @@ #define CONTROL_COMMAND_ARGUMENT_HOLDER_H //#include "pre.hpp" -//#include "lib/error.hpp" #include "proc/control/argument-tuple-accept.hpp" #include "proc/control/command-closure.hpp" #include "proc/control/memento-tie.hpp" #include "lib/opaque-holder.hpp" -//#include -//#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 boost::noncopyable; - using std::string; using lib::InPlaceBuffer; + using std::string; namespace { // empty state marker objects for ArgumentHolder @@ -94,7 +84,7 @@ namespace control { { typedef typename CommandSignature::CaptureSig SIG_cap; typedef typename CommandSignature::UndoOp_Sig SIG_undo; - + UntiedMemento() : MementoTie (function(), function() ) { } @@ -209,7 +199,8 @@ namespace control { /** direct "backdoor" access to stored memento value. - * @note you might access a placeholder when called prior to \c tie(..) */ + * @throw LUMIERA_ERROR_MISSING_MEMENTO when invoked + * prior to \c tie(..) and capturing any state */ MEM& memento () { diff --git a/src/proc/control/memento-tie.hpp b/src/proc/control/memento-tie.hpp index 3ad17c0fc..dff7467f3 100644 --- a/src/proc/control/memento-tie.hpp +++ b/src/proc/control/memento-tie.hpp @@ -192,10 +192,13 @@ namespace control { friend bool operator== (MementoTie const& m1, MementoTie const& m2) { - return util::rawComparison(m1.undo_, m2.undo_ ) - && util::rawComparison(m1.capture_,m2.capture_ ) - && (m1.isCaptured_ == m2.isCaptured_) - && (!m1.isCaptured_ + return ((!m1.undo_ && !m2.undo_ && !m1.capture_ && !m2.capture_) // either no valid functions + || ( util::rawComparison(m1.undo_, m2.undo_ ) // or identical functions + && util::rawComparison(m1.capture_,m2.capture_ ) + ) + ) + && (m1.isCaptured_ == m2.isCaptured_) // either both not captured or identical state + && (!m1.isCaptured_ || (m1.memento_ == m2.memento_)); } }; diff --git a/tests/components/proc/control/command-argument-test.cpp b/tests/components/proc/control/command-argument-test.cpp index 4b62380e6..f5e3f3bde 100644 --- a/tests/components/proc/control/command-argument-test.cpp +++ b/tests/components/proc/control/command-argument-test.cpp @@ -136,6 +136,9 @@ namespace test { protocol << "undoIt(time="< one, two; - ASSERT (one == two); + ArgumentHolder one, two; + ASSERT (one == two); // empty, identically typed argument holders -->equal - one.memento() = 5; + one.tie(dummyU,dummyC) + .tieCaptureFunc()(1,9); + ASSERT (one != two); // now one contains captured UNDO state + + two.tie(dummyU,dummyC) + .tieCaptureFunc()(1,9); + two.memento() = one.memento(); // put the same UNDO state in both + ASSERT (one == two); // ...makes them equal again + + one.bind (1,2); // verify argument tuple comparison ASSERT (one != two); + ASSERT (two != one); + ASSERT (!isnil (one)); + ASSERT ( isnil (two)); - ArgumentHolder three, four; - ASSERT (three == four); - three.bind (1,2); - ASSERT (three != four); - ASSERT (four != three); - ASSERT (!isnil (three)); - ASSERT ( isnil (four)); - - four.bind (3,4); - ASSERT (!isnil (four)); - ASSERT (three != four); - ASSERT (four != three); + two.bind (3,4); + ASSERT (!isnil (two)); + ASSERT (one != two); + ASSERT (two != one); - three.bind (3,4); - ASSERT (!isnil (three)); - ASSERT (three == four); - ASSERT (four == three); - four.memento() = 12345; - ASSERT (!isnil (four)); - ASSERT (three != four); - ASSERT (four != three); + one.bind (1,4); + ASSERT (!isnil (one)); + ASSERT (one != two); + ASSERT (two != one); + + one.bind (3,4); + ASSERT (!isnil (one)); + ASSERT (one == two); + ASSERT (two == one); + two.memento() = 12345; + ASSERT (!isnil (two)); + ASSERT (one != two); + ASSERT (two != one); } diff --git a/tests/components/proc/control/memento-tie-test.cpp b/tests/components/proc/control/memento-tie-test.cpp index 0785e8ba5..20a40e1fa 100644 --- a/tests/components/proc/control/memento-tie-test.cpp +++ b/tests/components/proc/control/memento-tie-test.cpp @@ -163,14 +163,14 @@ namespace test { MemHolder m22x (m22); // clone copy ASSERT (!m22x); - ASSERT (m22 == m22x); + ASSERT (m22 == m22x); // same functions, no state --> equal testVal = 0; - m22x.tieCaptureFunc() (1 + (rand() % 9)); // produce a random memento value != 0 + m22x.tieCaptureFunc() (1 + (rand() % 9)); // produce a random memento value != 0 ASSERT (0 < m22x.getState()); ASSERT (m22 != m22x); - m22.tieCaptureFunc() (0); // now get the same value into the memento within m22 + m22.tieCaptureFunc() (m22x.getState()); // get the same value into the memento within m22 ASSERT (m22 == m22x); } };