PlacementIndex: possibly retaining type information on insert
This commit is contained in:
parent
26972376de
commit
9a6f9b2ba5
8 changed files with 90 additions and 10 deletions
|
|
@ -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) {}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@
|
|||
** (which in the mentioned example would mean it couldn't be
|
||||
** passed to a API function expecting a Placement<Meta>).
|
||||
** 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
|
||||
|
|
|
|||
|
|
@ -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<typename PLA>
|
||||
struct BuildID;
|
||||
|
||||
/// @note just ignoring the second (parent) type encoded into Placement
|
||||
template<typename MO, typename BMO>
|
||||
struct BuildID<Placement<MO,BMO> >
|
||||
{
|
||||
typedef PlacementMO::Id<MO> Type;
|
||||
typedef MO Target;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Structured compound of Placement instances
|
||||
|
|
@ -199,6 +215,9 @@ namespace session {
|
|||
bool remove (PlacementMO&);
|
||||
bool remove (ID);
|
||||
|
||||
template<class PLA>
|
||||
typename BuildID<PLA>::Type insert (PLA const&, ID);
|
||||
|
||||
|
||||
|
||||
PlacementIndex(PlacementMO const&);
|
||||
|
|
@ -251,7 +270,7 @@ namespace session {
|
|||
inline Placement<MO>&
|
||||
PlacementIndex::find (PlacementMO::Id<MO> id) const
|
||||
{
|
||||
PlacementMO& result (find (id));
|
||||
PlacementMO& result (find ((ID)id));
|
||||
|
||||
___check_compatibleType<MO> (result);
|
||||
return static_cast<Placement<MO>&> (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<class PLA>
|
||||
typename BuildID<PLA>::Type
|
||||
PlacementIndex::insert (PLA const& newObj, ID targetScope)
|
||||
{
|
||||
typedef typename BuildID<PLA>::Target TargetMO;
|
||||
PlacementMO const& genericPlacement(newObj);
|
||||
|
||||
return find (insert (genericPlacement, targetScope))
|
||||
.template recastID<TargetMO>();
|
||||
}
|
||||
|
||||
|
||||
inline bool
|
||||
PlacementIndex::remove (PlacementMO& p)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ END
|
|||
|
||||
TEST "PlacementIndex_test" PlacementIndex_test <<END
|
||||
out: ^::Placement<.+session.test.TestClip.+ use-cnt=2
|
||||
out: ^ ::Placement<.+session.test.TestClip.+ use-cnt=1
|
||||
out: ^ ...1 elements at Level 1
|
||||
out: ^::Placement<.+session.test.TestClip.+ use-cnt=6
|
||||
out: ^ ::Placement<.+session.test.TestClip.+ use-cnt=6
|
||||
out: ^ ::Placement<.+session.test.TestClip.+ use-cnt=6
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace backend_interface
|
|||
typedef MediaAccessFacade::ChanHandle ChanHandle;
|
||||
|
||||
|
||||
namespace // implementation deatils
|
||||
namespace // implementation details
|
||||
{
|
||||
typedef vector<ChanDesc> Response;
|
||||
const ChanDesc NULLResponse;
|
||||
|
|
|
|||
|
|
@ -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<Clip> PClip;
|
||||
PClip anotherTestClip = TestClip::create();
|
||||
|
||||
typedef PlacementMO::Id<Clip> 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
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ namespace mobject {
|
|||
namespace session {
|
||||
namespace test {
|
||||
|
||||
using lumiera::Time;
|
||||
typedef shared_ptr<asset::Media> 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
|
||||
|
|
|
|||
|
|
@ -26,13 +26,11 @@
|
|||
|
||||
|
||||
#include "proc/mobject/session/clip.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
#include "lib/lumitime.hpp"
|
||||
|
||||
|
||||
//#include <boost/format.hpp>
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue