From 836f533a2fcc352a10f0c463320ae711b2a5f01b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 8 Jan 2010 03:59:01 +0100 Subject: [PATCH] add equality comparison and identity handling --- src/proc/mobject/mobject-ref.hpp | 31 +++++++++++++++++++ src/proc/mobject/placement.hpp | 13 ++++---- src/proc/mobject/session/placement-index.cpp | 4 +-- src/proc/mobject/session/scope.cpp | 4 ++- src/proc/mobject/session/session-impl.cpp | 2 +- src/proc/mobject/session/session-impl.hpp | 2 +- src/proc/mobject/session/track.hpp | 4 ++- .../proc/mobject/placement-basic-test.cpp | 2 +- .../mobject/session/placement-index-test.cpp | 14 +++------ 9 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/proc/mobject/mobject-ref.hpp b/src/proc/mobject/mobject-ref.hpp index 2312c16db..abdd03481 100644 --- a/src/proc/mobject/mobject-ref.hpp +++ b/src/proc/mobject/mobject-ref.hpp @@ -124,6 +124,37 @@ namespace mobject { else return *this; } + + /* == equality comparisons == */ + + template + bool + operator== (MORef const& oRef) + { + return pRef_ == oRef.pRef_; + } + + template + bool + operator== (PlacementRef const& pRef) + { + return pRef_ == pRef; + } + + template + bool + operator== (typename Placement::ID const& pID) + { + return pRef_ == pID; + } + + template + bool + operator!= (XX const& xx) + { + return !((*this) == xx); + } + }; ////////////////TODO currently just fleshing out the API.... diff --git a/src/proc/mobject/placement.hpp b/src/proc/mobject/placement.hpp index cbd4677d8..dc1c1a0c7 100644 --- a/src/proc/mobject/placement.hpp +++ b/src/proc/mobject/placement.hpp @@ -42,18 +42,17 @@ ** absolute position (time, track). ** ** Together, this yields semantics somewhere in between value semantics and reference semantics. - ** As any smart-ptr, placements are copyable, any such copies being considered equivalent. \em But, - ** when added to the Session, a placement acts as if it was an \em instance of the object it - ** points at, with the purpose to bind this instance into the Session with specific placement + ** As any smart-ptr, placements are copyable, but each such copy takes on a distinct identity. + ** Moreover, when added to the Session, a placement acts as if it was an \em instance of the object + ** it points at, with the purpose to bind this instance into the Session with specific placement ** properties. Thus, such a placement-within-session \em is an distinguishable entity, because ** the settings on the contained LocatingPin chain \em do constitute the relation properties ** of the MObject "placed" by this placement. To support this rather ref-like semantics, any - ** placement has an embedded ID (identity), and the Session won't allow to add a clone copy - ** of an placement with the same identity. Moreover, it is possible to create a smart-ptr - ** like PlacementRef to denote a specific placement found within the current Session. + ** placement has an embedded ID (identity). Building on this ID, it is possible to create a + ** smart-ptr like PlacementRef to denote a specific placement found within the Session. ** ** Placements are templated on the type of the actual MObject they refer to, so, sometimes - ** we rather use a Placement to be able to use the more specific methods of the + ** e.g. we rather use a Placement to be able to use the more specific methods of the ** session::Clip interface. But please note the following detail: this type ** labelling and downcasting is the only difference between these subclasses, ** besides that, they can be replaced literally by one another (slicing is accepted). diff --git a/src/proc/mobject/session/placement-index.cpp b/src/proc/mobject/session/placement-index.cpp index df9c7c883..44f329da8 100644 --- a/src/proc/mobject/session/placement-index.cpp +++ b/src/proc/mobject/session/placement-index.cpp @@ -577,9 +577,7 @@ namespace session { ID theScope (sco(id)->getID()); iterator elementsInScope = tab.queryScopeContents(theScope); - bool properlyRegistered = - true; ////////////////////////////////////////////////////////////////////////////////////////////TICKET #119 need equality on Placements - ///has_any (elementsInScope, _1_ == *theElement ); + bool properlyRegistered = has_any (elementsInScope, _1_ == *theElement ); VERIFY ( properlyRegistered, "(1.8) Elements", "Element isn't registered as member of the enclosing scope"); } diff --git a/src/proc/mobject/session/scope.cpp b/src/proc/mobject/session/scope.cpp index cf61747f4..9dbf81365 100644 --- a/src/proc/mobject/session/scope.cpp +++ b/src/proc/mobject/session/scope.cpp @@ -39,7 +39,9 @@ namespace session { - /** TODO??? */ + /** conversion of a scope top (placement) into a Scope. + * only allowed if the given Placement is actually attached + * to the session, which will be checked by index access */ Scope::Scope (PlacementMO const& constitutingPlacement) : anchor_(constitutingPlacement) { diff --git a/src/proc/mobject/session/session-impl.cpp b/src/proc/mobject/session/session-impl.cpp index 1b17e019e..526698ea9 100644 --- a/src/proc/mobject/session/session-impl.cpp +++ b/src/proc/mobject/session/session-impl.cpp @@ -70,7 +70,7 @@ namespace session { try { edls.clear(); - edls.resize(1); + edls.resize(1); //////////////////////////////////////////////////////////////////////////TICKET #513 focusEDL_ = 0; } catch (...) diff --git a/src/proc/mobject/session/session-impl.hpp b/src/proc/mobject/session/session-impl.hpp index 15c49118a..2c9bb572a 100644 --- a/src/proc/mobject/session/session-impl.hpp +++ b/src/proc/mobject/session/session-impl.hpp @@ -81,7 +81,7 @@ namespace session { PlacementIndex pIdx_; uint focusEDL_; - vector edls; /////////////////////TICKET #500 + vector edls; /////////////////////TICKET #500 #513 #514 PFix fixture; diff --git a/src/proc/mobject/session/track.hpp b/src/proc/mobject/session/track.hpp index 5a9166a31..7b3222bdb 100644 --- a/src/proc/mobject/session/track.hpp +++ b/src/proc/mobject/session/track.hpp @@ -72,7 +72,9 @@ namespace session { public: /** Child tracks in a tree structure */ - vector > subTracks; ////TODO: it should really work with Placements! this here is just a decoy!!!!!!! + vector > subTracks; ///////////TODO: it should really work with PlacementRefs! this here is just a decoy!!!!!!! +/////////////////////////////////////////////////////////TICKET #513 + virtual bool isValid() const; }; diff --git a/tests/components/proc/mobject/placement-basic-test.cpp b/tests/components/proc/mobject/placement-basic-test.cpp index 9725c4bee..21c663b74 100644 --- a/tests/components/proc/mobject/placement-basic-test.cpp +++ b/tests/components/proc/mobject/placement-basic-test.cpp @@ -79,7 +79,7 @@ namespace mobject { ExplicitPlacement expla = pc.resolve(); ASSERT (expla.time == Time(1)); ASSERT (!expla.chain.isOverdetermined()); - //ASSERT (*expla == *pc); ////////////////////////TODO: define equality on placements (Trac #119) +// ASSERT (*expla == *pc); ////////////////////////////////////////////TICKET #511 define equivalence of locating chains and solutions // now overconstraining with another Placement pc.chain(Time(2)); diff --git a/tests/components/proc/mobject/session/placement-index-test.cpp b/tests/components/proc/mobject/session/placement-index-test.cpp index 569e4b208..e0c80da9d 100644 --- a/tests/components/proc/mobject/session/placement-index-test.cpp +++ b/tests/components/proc/mobject/session/placement-index-test.cpp @@ -127,14 +127,12 @@ namespace test { PMO& elm = index.find(elmID); ASSERT (elmID == elm.getID()); ASSERT (!isSameObject (elm,testObj)); // note: placements are registered as copy -// ///////////////////////////////////////////////////////////////////////////////TICKET #119 -// ASSERT (elm == testObj); // they are semantically equivalent + ASSERT (elm == testObj); // they are semantically equivalent ASSERT (elmID != testObj.getID()); // but have a distinct identity PMO::ID elmID2 = index.insert(testObj, root); ASSERT (elmID != elmID); // ...and each insert creates a new instance -// ///////////////////////////////////////////////////////////////////////////////TICKET #119 -// ASSERT (testObj == index.find(elmID2)); + ASSERT (testObj == index.find(elmID2)); ASSERT (!isSameObject (elm, index.find(elmID2))); ASSERT ( isSameObject (elm, index.find(elmID ))); @@ -180,8 +178,7 @@ namespace test { ID e133 = index.insert (testObj, e13); ID e1331 = index.insert (testObj, e133); -// ///////////////////////////////////////////////////////////////////////////////TICKET #119 -// ASSERT (root == index.getScope(e1)); + ASSERT (root == index.getScope(e1)); ASSERT (e1 == index.getScope(e11).getID()); ASSERT (e1 == index.getScope(e12).getID()); ASSERT (e1 == index.getScope(e13).getID()); @@ -192,9 +189,8 @@ namespace test { ASSERT (e1 != e13); ASSERT (e13 != e133); -// ///////////////////////////////////////////////////////////////////////////////TICKET #119 -// ASSERT (index.getScope(e11) == index.getScope(index.find(e11))); -// ASSERT (index.getScope(e131) == index.getScope(index.find(e131))); + ASSERT (index.getScope(e11) == index.getScope(index.find(e11))); + ASSERT (index.getScope(e131) == index.getScope(index.find(e131))); VERIFY_ERROR(NONEMPTY_SCOPE, index.remove(e13) ); // can't remove a scope-constituting element VERIFY_ERROR(NONEMPTY_SCOPE, index.remove(e133) );