From 9a6f9b2ba5724ff059d2249157064cb086b614f9 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 16 Jan 2010 08:51:22 +0100 Subject: [PATCH] PlacementIndex: possibly retaining type information on insert --- src/lib/hash-indexed.hpp | 2 +- src/proc/mobject/placement-ref.hpp | 1 + src/proc/mobject/session/placement-index.hpp | 40 +++++++++++++++++- tests/43session.tests | 2 + tests/components/backend/mediaaccessmock.cpp | 2 +- .../mobject/session/placement-index-test.cpp | 41 +++++++++++++++++-- .../proc/mobject/session/testclip.cpp | 5 +++ .../proc/mobject/session/testclip.hpp | 7 ++-- 8 files changed, 90 insertions(+), 10 deletions(-) diff --git a/src/lib/hash-indexed.hpp b/src/lib/hash-indexed.hpp index 4294f69fa..8dedfd33f 100644 --- a/src/lib/hash-indexed.hpp +++ b/src/lib/hash-indexed.hpp @@ -137,7 +137,7 @@ namespace lib { struct ID : IMP { ID () : IMP () {} - ID (BA const& ref) : IMP (ref.getID()) {} + ID (BA const& ref) : IMP (ref.getID()) {} // note: automatic conversion (e.g. from PlacementMO&) ID (IMP const& ir) : IMP (ir) {} }; diff --git a/src/proc/mobject/placement-ref.hpp b/src/proc/mobject/placement-ref.hpp index 0cce33c24..209f5080b 100644 --- a/src/proc/mobject/placement-ref.hpp +++ b/src/proc/mobject/placement-ref.hpp @@ -53,6 +53,7 @@ ** (which in the mentioned example would mean it couldn't be ** passed to a API function expecting a Placement). ** This is ugly, but doesn't seem to bear any danger. + ** @todo better solution for the ID to type connection ///////////////////////TICKET #523 ** ** @see Placement ** @see PlacementRef_test diff --git a/src/proc/mobject/session/placement-index.hpp b/src/proc/mobject/session/placement-index.hpp index 2da6540b0..8323b6cbb 100644 --- a/src/proc/mobject/session/placement-index.hpp +++ b/src/proc/mobject/session/placement-index.hpp @@ -132,6 +132,22 @@ namespace session { using boost::scoped_ptr; + /** + * Helper for building Placement-ID types + * @todo this is a rather half-baked solution //////////TICKET #523 + */ + template + struct BuildID; + + /// @note just ignoring the second (parent) type encoded into Placement + template + struct BuildID > + { + typedef PlacementMO::Id Type; + typedef MO Target; + }; + + /** * Structured compound of Placement instances @@ -199,6 +215,9 @@ namespace session { bool remove (PlacementMO&); bool remove (ID); + template + typename BuildID::Type insert (PLA const&, ID); + PlacementIndex(PlacementMO const&); @@ -251,7 +270,7 @@ namespace session { inline Placement& PlacementIndex::find (PlacementMO::Id id) const { - PlacementMO& result (find (id)); + PlacementMO& result (find ((ID)id)); ___check_compatibleType (result); return static_cast&> (result); @@ -273,12 +292,31 @@ namespace session { return getScope(p.getID()); } + inline bool PlacementIndex::contains (PlacementMO const& p) const { return contains (p.getID()); } + + /** convenience shortcut to insert a placement + * immediately followed by creating a typed-ID, + * allowing to retain the original typed context + * @todo this solution is half-baked ///////////////////////////////////TICKET #523 + */ + template + typename BuildID::Type + PlacementIndex::insert (PLA const& newObj, ID targetScope) + { + typedef typename BuildID::Target TargetMO; + PlacementMO const& genericPlacement(newObj); + + return find (insert (genericPlacement, targetScope)) + .template recastID(); + } + + inline bool PlacementIndex::remove (PlacementMO& p) { diff --git a/tests/43session.tests b/tests/43session.tests index c2a181650..c54f2a315 100644 --- a/tests/43session.tests +++ b/tests/43session.tests @@ -57,6 +57,8 @@ END TEST "PlacementIndex_test" PlacementIndex_test < Response; const ChanDesc NULLResponse; diff --git a/tests/components/proc/mobject/session/placement-index-test.cpp b/tests/components/proc/mobject/session/placement-index-test.cpp index ad117cdf8..749c32a70 100644 --- a/tests/components/proc/mobject/session/placement-index-test.cpp +++ b/tests/components/proc/mobject/session/placement-index-test.cpp @@ -26,6 +26,7 @@ #include "proc/mobject/session/placement-index.hpp" #include "proc/mobject/session/scope.hpp" #include "proc/mobject/placement.hpp" +#include "proc/asset/media.hpp" #include "lib/util.hpp" #include "proc/mobject/session/testclip.hpp" @@ -70,15 +71,19 @@ namespace test { checkSimpleInsertRemove (index); has_size (0, index); - checkSimpleAccess (index); + PMO::ID elmID = checkSimpleAccess (index); + ASSERT (index.isValid()); has_size (2, index); + checkTypedAccess (index, elmID); + has_size (3, index); + checkScopeHandling (index); - has_size (8, index); + has_size (9, index); checkContentsEnumeration (index); - has_size (8, index); + has_size (9, index); ASSERT (index.isValid()); index.clear(); @@ -115,7 +120,7 @@ namespace test { } - void + PMO::ID checkSimpleAccess (Idx index) { PMO testObj = TestClip::create(); @@ -143,6 +148,34 @@ namespace test { // can also re-access objects by previous ref ASSERT ( isSameObject (elm, index.find(elm))); + return elmID; + } + + + + void + checkTypedAccess (Idx index, PMO::ID elmID) + { + PMO& elm = index.find(elmID); + ASSERT (elmID == elm.getID()); + + typedef Placement PClip; + PClip anotherTestClip = TestClip::create(); + + typedef PlacementMO::Id IDClip; + IDClip clipID = index.insert(anotherTestClip, elmID); + // retaining the more specific type info + + // access as MObject... + PMO::ID mID = clipID; + PMO& asMO = index.find(mID); + + // access as Clip + PClip& asClip = index.find(clipID); + ASSERT (LENGTH_TestClip == asClip->getMedia()->getLength()); // using the Clip API + + ASSERT ( isSameObject(asMO,asClip)); + ASSERT (!isSameObject(asClip, anotherTestClip)); // always inserting a copy into the PlacementIndex } diff --git a/tests/components/proc/mobject/session/testclip.cpp b/tests/components/proc/mobject/session/testclip.cpp index a506d2849..a94e3b0ec 100644 --- a/tests/components/proc/mobject/session/testclip.cpp +++ b/tests/components/proc/mobject/session/testclip.cpp @@ -32,6 +32,7 @@ namespace mobject { namespace session { namespace test { + using lumiera::Time; typedef shared_ptr PM; typedef backend_interface::MediaAccessFacade MAF; using backend_interface::test::MediaAccessMock; @@ -82,5 +83,9 @@ namespace test { } + /* == define some data for verification in unit tests == */ + + const Time LENGTH_TestClip = Time(25); //////TODO hard wired as of (1/10). See MediaFactory::operator() in media.cpp + }}} // namespace mobject::session::test diff --git a/tests/components/proc/mobject/session/testclip.hpp b/tests/components/proc/mobject/session/testclip.hpp index 34fa5154f..7b4b66108 100644 --- a/tests/components/proc/mobject/session/testclip.hpp +++ b/tests/components/proc/mobject/session/testclip.hpp @@ -26,13 +26,11 @@ #include "proc/mobject/session/clip.hpp" -//#include "lib/util.hpp" +#include "lib/lumitime.hpp" -//#include using std::tr1::shared_ptr; -//using boost::format; using std::string; @@ -79,6 +77,9 @@ namespace test { } + /* == some test data to check == */ + extern const lumiera::Time LENGTH_TestClip; + }}} // namespace mobject::session::test #endif