add equality comparison and identity handling

This commit is contained in:
Fischlurch 2010-01-08 03:59:01 +01:00
parent 8c7894943c
commit 836f533a2f
9 changed files with 52 additions and 24 deletions

View file

@ -124,6 +124,37 @@ namespace mobject {
else return *this;
}
/* == equality comparisons == */
template<class MOX>
bool
operator== (MORef<MOX> const& oRef)
{
return pRef_ == oRef.pRef_;
}
template<class MOX>
bool
operator== (PlacementRef<MOX> const& pRef)
{
return pRef_ == pRef;
}
template<class MOX>
bool
operator== (typename Placement<MOX>::ID const& pID)
{
return pRef_ == pID;
}
template<class XX>
bool
operator!= (XX const& xx)
{
return !((*this) == xx);
}
};
////////////////TODO currently just fleshing out the API....

View file

@ -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 <i>distinct identity.</i>
** 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<Clip> to be able to use the more specific methods of the
** e.g. we rather use a Placement<Clip> to be able to use the more specific methods of the
** session::Clip interface. But <i>please note the following detail:</i> this type
** labelling and downcasting is the <i>only</i> difference between these subclasses,
** besides that, they can be replaced literally by one another (slicing is accepted).

View file

@ -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");
}

View file

@ -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)
{

View file

@ -70,7 +70,7 @@ namespace session {
try
{
edls.clear();
edls.resize(1);
edls.resize(1); //////////////////////////////////////////////////////////////////////////TICKET #513
focusEDL_ = 0;
}
catch (...)

View file

@ -81,7 +81,7 @@ namespace session {
PlacementIndex pIdx_;
uint focusEDL_;
vector<EDL> edls; /////////////////////TICKET #500
vector<EDL> edls; /////////////////////TICKET #500 #513 #514
PFix fixture;

View file

@ -72,7 +72,9 @@ namespace session {
public:
/** Child tracks in a tree structure */
vector<Placement<Track> > subTracks; ////TODO: it should really work with Placements! this here is just a decoy!!!!!!!
vector<Placement<Track> > subTracks; ///////////TODO: it should really work with PlacementRefs! this here is just a decoy!!!!!!!
/////////////////////////////////////////////////////////TICKET #513
virtual bool isValid() const;
};

View file

@ -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));

View file

@ -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) );