switch asset ordering impl to utilize the new custom smart-ptr
passes compiler and test suite, finally! TODO: also switch the derived asset kinds to use P<Media>, P<Struct>,.... maybe do the same with MObject?
This commit is contained in:
parent
2b529e3fac
commit
dffd635482
16 changed files with 70 additions and 135 deletions
|
|
@ -50,7 +50,6 @@
|
|||
|
||||
namespace lumiera
|
||||
{
|
||||
//using std::string;
|
||||
|
||||
|
||||
namespace query
|
||||
|
|
@ -114,8 +113,7 @@ namespace lumiera
|
|||
{
|
||||
const Ret& candidate (any_cast<const Ret&> (entry));
|
||||
if (! solution
|
||||
// ||(solution && *solution == *candidate) // simulates a real unification
|
||||
//////////////TODO: not only Assets (i.e. define comparison Operators on Assets!)
|
||||
||(solution && solution == candidate) // simulates a real unification
|
||||
)
|
||||
return solution = candidate;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Suite - helper class for running collections of tests
|
||||
Suite - handle cmdline for invoking Testsuite
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
|
@ -45,6 +45,7 @@ namespace test
|
|||
* \code
|
||||
* --help
|
||||
* --group <groupID>
|
||||
* --describe
|
||||
* \endcode
|
||||
*/
|
||||
TestOption::TestOption (util::Cmdline& cmdline)
|
||||
|
|
|
|||
|
|
@ -59,14 +59,16 @@
|
|||
|
||||
#include "proc/asset/category.hpp"
|
||||
#include "common/error.hpp"
|
||||
#include "common/p.hpp"
|
||||
|
||||
#include <boost/type_traits/is_base_of.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <tr1/memory>
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
|
||||
using std::string;
|
||||
|
|
@ -81,6 +83,8 @@ namespace asset
|
|||
using std::size_t;
|
||||
using std::tr1::shared_ptr;
|
||||
using std::tr1::static_pointer_cast;
|
||||
|
||||
using lumiera::P;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -109,8 +113,8 @@ namespace asset
|
|||
class Asset;
|
||||
class AssetManager;
|
||||
typedef const ID<Asset>& IDA;
|
||||
typedef shared_ptr<Asset> PAsset;
|
||||
typedef shared_ptr<const Asset> PcAsset;
|
||||
typedef P<Asset> PAsset;
|
||||
typedef P<const Asset> PcAsset;
|
||||
|
||||
|
||||
|
||||
|
|
@ -135,7 +139,7 @@ namespace asset
|
|||
* @author Ichthyo
|
||||
*/
|
||||
class Asset
|
||||
: boost::totally_ordered< Asset,
|
||||
: boost::totally_ordered1< Asset,
|
||||
boost::noncopyable>
|
||||
{
|
||||
public:
|
||||
|
|
@ -299,6 +303,9 @@ namespace asset
|
|||
|
||||
/** ordering of Assets is based on the ordering
|
||||
* of Ident tuples, which are supposed to be unique.
|
||||
* By using our customized lumiera::P as smart ptr,
|
||||
* comparison on P<Asset> ptrs will be automatically
|
||||
* forwarded to the Asset comparison operators.
|
||||
* @note version info is irrelevant */
|
||||
inline int
|
||||
Asset::Ident::compare (const Asset::Ident& oi) const
|
||||
|
|
@ -309,6 +316,7 @@ namespace asset
|
|||
return name.compare (oi.name);
|
||||
}
|
||||
|
||||
|
||||
/** promote subtype-ptr to PAsset, e.g. for comparing */
|
||||
template<class A>
|
||||
inline const PcAsset
|
||||
|
|
@ -316,31 +324,15 @@ namespace asset
|
|||
{
|
||||
return static_pointer_cast<const Asset,A> (subPtr);
|
||||
}
|
||||
|
||||
/** ordering of Asset smart ptrs based on Ident tuple.
|
||||
* @todo currently supporting only smart_ptr<Asset>.
|
||||
* @todo should better be done using boost::operator */
|
||||
inline bool operator== (PcAsset const& a1, PcAsset const& a2) { return a1 && a2 && ( (*a1) == (*a2));}
|
||||
inline bool operator< (PcAsset const& a1, PcAsset const& a2) { return a1 && a2 && ( (*a1) < (*a2));}
|
||||
|
||||
template<class PA1, class PA2>
|
||||
inline bool operator== (PA1 const& a1, PA2 const& a2) { return pAsset(a1) == pAsset(a2); }
|
||||
|
||||
template<class PA1, class PA2>
|
||||
inline bool operator< (PA1 const& a1, PA2 const& a2) { return pAsset(a1) < pAsset(a2); }
|
||||
|
||||
|
||||
/** build ordering of Asset shared pointers on the ordering of the pointed to assets.
|
||||
* Because we can't define member operators for shared-ptrs, we explicitly instantiate
|
||||
* the boost ordering concept template for all Asset kinds we want to use...
|
||||
*/
|
||||
template<class PTR>
|
||||
struct asset_total_ordering : public boost::totally_ordered<PTR>
|
||||
{ };
|
||||
|
||||
template struct asset_total_ordering<PAsset>;
|
||||
template struct asset_total_ordering<PcAsset>;
|
||||
/** type trait for detecting a shared-ptr-to-asset */
|
||||
template <class X>
|
||||
struct is_pAsset : boost::false_type {};
|
||||
|
||||
template <class A>
|
||||
struct is_pAsset<shared_ptr<A> >
|
||||
: boost::is_base_of<Asset, A> {};
|
||||
|
||||
|
||||
/** convienient for debugging */
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include "proc/asset.hpp"
|
||||
#include "common/error.hpp"
|
||||
|
||||
#include <tr1/memory>
|
||||
#include <tr1/unordered_map>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
|
|
@ -92,9 +93,9 @@ namespace asset
|
|||
|
||||
public:
|
||||
template<class KIND>
|
||||
void put (ID<KIND> hash, shared_ptr<KIND>& ptr) { table[hash] = static_pointer_cast (ptr); }
|
||||
void put (ID<Asset> hash, PAsset& ptr) { table[hash] = ptr; }
|
||||
bool del (ID<Asset> hash) { return table.erase (hash); }
|
||||
void put (ID<KIND> hash, P<KIND>& ptr) { table[hash] = static_pointer_cast (ptr); }
|
||||
void put (ID<Asset> hash, PAsset& ptr) { table[hash] = ptr; }
|
||||
bool del (ID<Asset> hash) { return table.erase (hash); }
|
||||
|
||||
template<class KIND>
|
||||
shared_ptr<KIND>
|
||||
|
|
|
|||
|
|
@ -112,14 +112,13 @@ namespace asset
|
|||
AssetManager::reg (KIND* obj, const Asset::Ident& idi)
|
||||
throw(lumiera::error::Invalid)
|
||||
{
|
||||
typedef shared_ptr<KIND> PType;
|
||||
AssetManager& _aMang (AssetManager::instance());
|
||||
TODO ("check validity of Ident Category");
|
||||
ID<KIND> asset_id (getID (idi));
|
||||
|
||||
Thread::Lock<DB> guard SIDEEFFECT;
|
||||
TODO ("handle duplicate Registrations");
|
||||
PType smart_ptr (obj, &destroy);
|
||||
P<KIND> smart_ptr (obj, &destroy);
|
||||
|
||||
_aMang.registry.put (asset_id, smart_ptr);
|
||||
return asset_id;
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ namespace mobject
|
|||
operator() (const Record& rec)
|
||||
{
|
||||
shared_ptr<TAR> storedObj (rec.objRef.lock());
|
||||
return storedObj && pAsset(storedObj)==pAsset(obj_); //////////////TODO: not only Assets (i.e. define comparison Operators on Assets!)
|
||||
return storedObj && (storedObj == obj_);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -261,7 +261,7 @@ namespace mobject
|
|||
{
|
||||
shared_ptr<TAR> storedObj (pos->objRef.lock());
|
||||
if (storedObj)
|
||||
return (pAsset(storedObj) == pAsset(obj)); //////////////TODO: not only Assets (i.e. define comparison Operators on Assets!)
|
||||
return (storedObj == obj);
|
||||
else
|
||||
// use the opportunity and purge the expired entry
|
||||
registry.erase(pos);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@ Import('env','artifacts','core')
|
|||
|
||||
# build the ubiquitous Hello World application (note: C source)
|
||||
artifacts['tools'] = [ env.Program('#$BINDIR/hello-world','hello.c')
|
||||
+ env.Program('#$BINDIR/try', ['try.cpp'] + core) #### to try out some feature:
|
||||
+ env.Program('#$BINDIR/try', 'try.cpp') #### to try out some feature...
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -14,83 +14,12 @@
|
|||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "proc/asset/media.hpp"
|
||||
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
||||
|
||||
namespace lumiera
|
||||
{
|
||||
using std::tr1::shared_ptr;
|
||||
using std::tr1::weak_ptr;
|
||||
|
||||
template<class TAR, class BASE=std::tr1::shared_ptr<TAR> >
|
||||
class P
|
||||
: public BASE
|
||||
{
|
||||
public:
|
||||
P() : BASE() {}
|
||||
template<class Y> explicit P (Y* p) : BASE(p) {}
|
||||
template<class Y, class D> P (Y* p, D d) : BASE(p,d) {}
|
||||
|
||||
P (P const& r) : BASE(r) {}
|
||||
template<class Y> P (shared_ptr<Y> const& r) : BASE(r) {}
|
||||
template<class Y> explicit P (weak_ptr<Y> const& wr) : BASE(wr) {}
|
||||
template<class Y> explicit P (std::auto_ptr<Y> & ar) : BASE(ar) {}
|
||||
|
||||
private:
|
||||
// friend operators injected into enclosing namespace and found by ADL:
|
||||
template<typename _O_>
|
||||
friend inline bool
|
||||
operator== (P const& p, P<_O_> const& q) { return (p && q)? (*p == *q) : (!p && !q); }
|
||||
|
||||
template<typename _O_>
|
||||
friend inline bool
|
||||
operator!= (P const& p, P<_O_> const& q) { return (p && q)? (*p != *q) : !(!p && !q); }
|
||||
|
||||
template<typename _O_>
|
||||
friend inline bool
|
||||
operator< (P const& p, P<_O_> const& q) { return (p && q) && (*p < *q); }
|
||||
|
||||
template<typename _O_>
|
||||
friend inline bool
|
||||
operator> (P const& p, P<_O_> const& q) { return (p && q) && (*q < *p); }
|
||||
|
||||
template<typename _O_>
|
||||
friend inline bool
|
||||
operator<= (P const& p, P<_O_> const& q) { return (p && q)? (*p <= *q) : (!p && !q); }
|
||||
|
||||
template<typename _O_>
|
||||
friend inline bool
|
||||
operator>= (P const& p, P<_O_> const& q) { return (p && q)? (*p >= *q) : (!p && !q); }
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
namespace asset
|
||||
{
|
||||
using lumiera::P;
|
||||
|
||||
|
||||
void
|
||||
doIt()
|
||||
{
|
||||
Asset::Ident key2("Try-1", Category(VIDEO));
|
||||
P<Asset> a1 = asset::Media::create(key2, "Name-1");
|
||||
|
||||
Asset::Ident key3("Try-2", Category(VIDEO));
|
||||
P<Media> a2 = asset::Media::create(key3, "Name-2");
|
||||
|
||||
cout << "a1 = " << str(a1);
|
||||
|
||||
bool yes = (a1 >= a2);
|
||||
enable_if<is_pAsset<PAsset>, string>::type yup;
|
||||
|
||||
cout << "\n yes=" << yes << " yup=" << typeid(*a1).name();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
|
|
@ -98,8 +27,6 @@ int main (int argc, char* argv[])
|
|||
|
||||
NOBUG_INIT;
|
||||
|
||||
asset::doIt();
|
||||
|
||||
cout << "\ngulp\n";
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -71,14 +71,14 @@ namespace asset
|
|||
}
|
||||
|
||||
|
||||
template<class C, class P>
|
||||
template<class CHI, class PAR>
|
||||
inline bool
|
||||
dependencyCheck (C child, P parent)
|
||||
dependencyCheck (P<CHI> child, P<PAR> parent)
|
||||
{
|
||||
return (pAsset(child) == pAsset(parent))
|
||||
return (child == parent)
|
||||
|| (0 < child->getParents().size()
|
||||
&& (parent == child->getParents()[0])
|
||||
&& (contains (parent->getDependant(), child)));
|
||||
&& (contains (parent->getDependant(), child)))
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -154,6 +154,9 @@ namespace asset
|
|||
|
||||
void dependProcPatt(string pID)
|
||||
{
|
||||
typedef P<Pipe> PPipe; /////TODO: transition to P<>
|
||||
typedef P<const ProcPatt> PProcPatt;
|
||||
|
||||
PPipe thePipe = Pipe::query ("pipe("+pID+")");
|
||||
ASSERT (thePipe);
|
||||
PProcPatt thePatt = thePipe->getProcPatt();
|
||||
|
|
@ -186,11 +189,13 @@ namespace asset
|
|||
ASSERT (!aMang.known (thePipe->getID())); // has been unlinked too, because dependant on pattern2
|
||||
|
||||
ASSERT (thePipe);
|
||||
PProcPatt pattern3 = thePipe->getProcPatt(); /////TODO: transition to P<>
|
||||
ASSERT (thePipe->getProcPatt());
|
||||
ASSERT (thePipe->getProcPatt() == pattern2); // but is still valid, as long as the ref is alive....
|
||||
ASSERT ( pattern3 == pattern2); // but is still valid, as long as the ref is alive....
|
||||
|
||||
PPipe pipe3x = Pipe::query ("pattern(another)");
|
||||
ASSERT (pipe3x->getProcPatt() != pattern2); // because pattern2 is already unlinked...
|
||||
pattern3 = pipe3x->getProcPatt(); /////TODO: transition to P<>
|
||||
ASSERT (pattern3 != pattern2); // because pattern2 is already unlinked...
|
||||
ASSERT (pipe3x == Session::current->defaults (Query<Pipe>("pattern(another)")));
|
||||
ASSERT (pipe3x != pipe2x); // ..we got a new default pipe for "pattern(another)" too!
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace asset
|
|||
|
||||
|
||||
|
||||
typedef shared_ptr<asset::Media> PM;
|
||||
typedef P<Media> PM; /////TODO: transition to P<>
|
||||
|
||||
/** @test Creating and automatically registering Asset instances.
|
||||
* Re-Retrieving the newly created objects from AssetManager.
|
||||
|
|
@ -78,12 +78,26 @@ namespace asset
|
|||
|
||||
// Assets have been registered and can be retrieved by ID
|
||||
AssetManager& aMang = AssetManager::instance();
|
||||
PM registered; /////TODO: transition to P<>
|
||||
registered = aMang.getAsset (mm1->getID());
|
||||
ASSERT (registered == mm1);
|
||||
registered = aMang.getAsset (mm2->getID());
|
||||
ASSERT (registered == mm2);
|
||||
registered = aMang.getAsset (mm3->getID());
|
||||
ASSERT (registered == mm3);
|
||||
|
||||
registered = aMang.getAsset (mm1->getID());
|
||||
ASSERT (registered != mm2);
|
||||
/*
|
||||
* TODO: switch back to original version
|
||||
* once the transition to P<XX> ist done...
|
||||
*
|
||||
ASSERT (aMang.getAsset (mm1->getID()) == mm1);
|
||||
ASSERT (aMang.getAsset (mm2->getID()) == mm2);
|
||||
ASSERT (aMang.getAsset (mm3->getID()) == mm3);
|
||||
|
||||
ASSERT (aMang.getAsset (mm1->getID()) != mm2);
|
||||
|
||||
*/
|
||||
PAsset aa1 = aMang.getAsset (ID<Asset>(mm1->getID())); // note we get an Asset ref
|
||||
ASSERT (aa1 == mm1);
|
||||
PM mX1 = aMang.getAsset (mm1->getID()); // ..and now we get a Media ref
|
||||
|
|
|
|||
|
|
@ -194,8 +194,8 @@ namespace asset
|
|||
void checkRealAssetDependencyRegistration ()
|
||||
{
|
||||
// -----Media and Clip--------------------------------
|
||||
typedef Media::PMedia PM;
|
||||
typedef Media::PClip PC;
|
||||
typedef P<Media> PM;
|
||||
typedef P<Clip> PC;
|
||||
PM mm = asset::Media::create("test-1", VIDEO);
|
||||
PC cc = mm->createClip()->findClipAsset();
|
||||
ASSERT (dependencyCheck (cc,mm));
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace asset
|
|||
*/
|
||||
class MakeClip_test : public Test
|
||||
{
|
||||
typedef shared_ptr<asset::Media> PM;
|
||||
typedef P<asset::Media> PM;
|
||||
typedef asset::Media::PClipMO PC;
|
||||
|
||||
virtual void run (Arg arg)
|
||||
|
|
|
|||
|
|
@ -59,22 +59,20 @@ namespace asset
|
|||
{
|
||||
virtual void run(Arg arg)
|
||||
{
|
||||
typedef shared_ptr<Asset> PA;
|
||||
|
||||
Asset::Ident key1("Au-1", Category(AUDIO), "ichthyo", 5);
|
||||
PA mm1 = asset::Media::create(key1, "Name-1");
|
||||
PAsset mm1 = asset::Media::create(key1, "Name-1");
|
||||
|
||||
Asset::Ident key2("Au-1", Category(AUDIO), "ichthyo", 7);
|
||||
PA mm2 = asset::Media::create(key2, "Name-2");
|
||||
PAsset mm2 = asset::Media::create(key2, "Name-2");
|
||||
|
||||
Asset::Ident key3("Au-2", Category(AUDIO), "ichthyo", 5);
|
||||
PA mm3 = asset::Media::create(key3, "Name-3");
|
||||
PAsset mm3 = asset::Media::create(key3, "Name-3");
|
||||
|
||||
Asset::Ident key4("Au-2", Category(AUDIO), "stega", 5);
|
||||
PA mm4 = asset::Media::create(key4, "Name-4");
|
||||
PAsset mm4 = asset::Media::create(key4, "Name-4");
|
||||
|
||||
Asset::Ident key5("Au-1", Category(VIDEO), "ichthyo", 5);
|
||||
PA mm5 = asset::Media::create(key5, "Name-5");
|
||||
PAsset mm5 = asset::Media::create(key5, "Name-5");
|
||||
|
||||
|
||||
// ordering of keys
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ namespace asset
|
|||
* within AssetManager by the Asset base class ctor
|
||||
*/
|
||||
template<class A>
|
||||
shared_ptr<TestAsset<A> >
|
||||
P<TestAsset<A> >
|
||||
TestAsset<A>::ptrFromThis ()
|
||||
{
|
||||
return static_pointer_cast<TestAsset<A>,Asset>
|
||||
|
|
@ -113,8 +113,8 @@ namespace asset
|
|||
template TestAsset<Asset>::TestAsset (PAsset& pRef);
|
||||
template TestAsset<Unknown>::TestAsset (PAsset& pRef);
|
||||
|
||||
template shared_ptr<TestAsset<Asset> > TestAsset<Asset>::ptrFromThis ();
|
||||
template shared_ptr<TestAsset<Unknown> > TestAsset<Unknown>::ptrFromThis ();
|
||||
template P<TestAsset<Asset> > TestAsset<Asset>::ptrFromThis ();
|
||||
template P<TestAsset<Unknown> > TestAsset<Unknown>::ptrFromThis ();
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ namespace asset
|
|||
static void deleter (TestAsset<A>* aa) { delete aa; }
|
||||
|
||||
public:
|
||||
typedef shared_ptr<TestAsset<A> > PA;
|
||||
typedef P<TestAsset<A> > PA;
|
||||
|
||||
static PA create () { return (new TestAsset<A> )->ptrFromThis(); }
|
||||
static PA create (PAsset& pRef) { return (new TestAsset<A> (pRef))->ptrFromThis(); }
|
||||
|
|
|
|||
Loading…
Reference in a new issue