comparisons and state detection now working as expected
This commit is contained in:
parent
33757bbac3
commit
63bad834c1
4 changed files with 49 additions and 43 deletions
|
|
@ -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 <tr1/memory>
|
||||
//#include <boost/scoped_ptr.hpp>
|
||||
//#include <tr1/functional>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#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 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<SIG,MEM>::CaptureSig SIG_cap;
|
||||
typedef typename CommandSignature<SIG,MEM>::UndoOp_Sig SIG_undo;
|
||||
|
||||
|
||||
UntiedMemento()
|
||||
: MementoTie<SIG,MEM> (function<SIG_undo>(), function<SIG_cap>() )
|
||||
{ }
|
||||
|
|
@ -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 ()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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_));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -136,6 +136,9 @@ namespace test {
|
|||
protocol << "undoIt(time="<<time<<")---state-was-:"<< *memento;
|
||||
}
|
||||
|
||||
void dummyU (int,int,int) { }
|
||||
int dummyC (int u,int o) { return u + rand() % (o-u+1); }
|
||||
|
||||
|
||||
|
||||
void
|
||||
|
|
@ -256,33 +259,42 @@ namespace test {
|
|||
void
|
||||
checkArgumentComparison ()
|
||||
{
|
||||
ArgumentHolder<void(), int> one, two;
|
||||
ASSERT (one == two);
|
||||
ArgumentHolder<void(int,int), int> 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<void(int,int), int> 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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue