Generic Record: implement equivalence of Record and RecRef in comparison

...that is, we have "magic" in the access functions, which allows
a RecRef to "stand-in" for the Record it points to
This commit is contained in:
Fischlurch 2015-10-30 22:02:09 +01:00
parent bc072ab336
commit 614e1f81e5
3 changed files with 19 additions and 10 deletions

View file

@ -103,9 +103,16 @@ namespace diff{
DERIVE_EQUALITY (time::Duration)
DERIVE_EQUALITY (time::TimeSpan)
DERIVE_EQUALITY (hash::LuidH)
DERIVE_EQUALITY (RecRef)
DERIVE_EQUALITY (Rec)
/** special treatment to allow matching a RecRef
* with an Record or RecRef on the other side */
virtual bool
handle (RecRef const& val) override
{
return o_.matchRec(val);
}
public:
EqualityTest(DataCap const& o)
: o_(o)

View file

@ -286,7 +286,7 @@ namespace diff{
bool contains (X const& elm) const;
bool matches (GenNode const& o) const { return this->matches(o.idi); } ///< @note \em not comparing payload data. Use equality for that
bool matches (GenNode const& o) const { return this->matches(o.idi); } ///< @note \em not comparing payload data. Use equality for that
bool matches (ID const& id) const { return idi == id; }
bool matches (int number) const { return data.matchNum(number);}
bool matches (int64_t number) const { return data.matchNum(number);}

View file

@ -199,7 +199,7 @@ namespace test{
CHECK (!isnil(scope));
CHECK (GenNode("τ", Time(1,2,3,4)) == *scope);
++scope;
CHECK (GenNode(char('*')) == *scope);
CHECK (char('*') == scope->data.get<char>());
++scope;
CHECK ("" == scope->data.get<string>());
++scope;
@ -813,18 +813,20 @@ namespace test{
CHECK (nh2 != ref2); CHECK (ref2 != nh2);
CHECK (rec1 != rec2); CHECK (rec2 != rec1);
// CHECK (rec1 != ref1); CHECK (ref1 != rec1); /////////TODO need special handling for references
// CHECK (rec1 != ref2); CHECK (ref2 != rec1);
// CHECK (rec2 != ref1); CHECK (ref1 != rec2);
// CHECK (rec2 != ref2); CHECK (ref2 != rec2);
CHECK (ref1 != ref2); CHECK (ref2 != ref1);
// NOTE: special handling for record references…
CHECK (rec1 == ref1); CHECK (ref1 == rec1);
CHECK (rec1 != ref2); CHECK (ref2 != rec1);
CHECK (rec2 != ref1); CHECK (ref1 != rec2);
CHECK (rec2 == ref2); CHECK (ref2 == rec2);
/* ----- equivalence match ----- */
// equivalence on equality // equivalence on ID match // contained value equality
// equivalence as object // equivalence on ID match // contained value equality
CHECK (ni1 .matches(ni1 )); CHECK (ni1 .matches(ni1 .idi)); CHECK (ni1 .matches(i1 ));
CHECK (ni2 .matches(ni2 )); CHECK (ni2 .matches(ni2 .idi)); CHECK (ni2 .matches(i2 ));
CHECK (nl1 .matches(nl1 )); CHECK (nl1 .matches(nl1 .idi)); CHECK (nl1 .matches(l1 ));