equality and ordering of assets implemented

This commit is contained in:
Fischlurch 2007-09-19 03:55:45 +02:00
parent 14d1c5a34b
commit 7ef8372129
5 changed files with 23 additions and 14 deletions

View file

@ -27,8 +27,6 @@
#include <boost/format.hpp>
#include <iostream>
#include <string>
using boost::format;
using util::cStr;

View file

@ -273,19 +273,22 @@ namespace asset
/** shorthand for refcounting Asset pointers */
typedef shared_ptr<Asset> PAsset;
/** ordering of Assets based on Ident tuple */
/** ordering of Asset smart ptrs based on Ident tuple.
* @todo currently supporting only smart_ptr<Asset>. */
inline bool operator== (const PAsset& a1, const PAsset& a2) { return a1 && a2 && ( 0==a1->ident.compare(a2->ident));}
inline bool operator< (const PAsset& a1, const PAsset& a2) { return a1 && a2 && (-1==a1->ident.compare(a2->ident));}
inline bool operator> (const PAsset& a1, const PAsset& a2) { return a2 < a1; }
inline bool operator>= (const PAsset& a1, const PAsset& a2) { return !(a1 < a2); }
inline bool operator<= (const PAsset& a1, const PAsset& a2) { return !(a1 > a2); }
inline bool operator!= (const PAsset& a1, const PAsset& a2) { return !(a1== a2); }
/** ordering of Asset Ident tuples.
* @note version is irrelevant */
inline int Asset::Ident::compare (const Asset::Ident& oi) const
{
int res;
if (1 != (res=category.compare (oi.category))) return res;
if (1 != (res=org.compare (oi.org))) return res;
if (0 != (res=category.compare (oi.category))) return res;
if (0 != (res=org.compare (oi.org))) return res;
return name.compare (oi.name);
}

View file

@ -94,7 +94,7 @@ namespace asset
int compare (const Category& co) const
{
int res = int(kind_) - int(co.kind_);
if (1 != res)
if (0 != res)
return res;
else
return path_.compare (co.path_);

View file

@ -20,5 +20,6 @@ return: 0
END
PLANNED "OrderingOfAssets_test" OrderingOfAssets_test <<END
TEST "OrderingOfAssets_test" OrderingOfAssets_test <<END
return: 0
END

View file

@ -45,28 +45,36 @@ namespace asset
/******************************************************
* @test validate the equality and order relations of
* Asset::Ident and Asset objects.
* @note a known problem is that only Asset smart ptrs
* are supported for comparison, not smartptrs
* of Asset subclasses. To solve this, we would
* either have to repeat the operator definitions,
* or resort to template metaprogramming tricks.
* Just providing templated comparison operators
* would generally override the behaviour of
* boost::shared_ptr, which is not desirable.
* @see Asset::Ident#compare
*/
class OrderingOfAssets_test : public Test
{
virtual void run(Arg arg)
{
typedef shared_ptr<asset::Media> PM;
typedef shared_ptr<Asset> PA;
Asset::Ident key1("Au-1", Category(AUDIO), "ichthyo", 5);
PM mm1 = asset::Media::create(key1, "Name-1");
PA mm1 = asset::Media::create(key1, "Name-1");
Asset::Ident key2("Au-1", Category(AUDIO), "ichthyo", 7);
PM mm2 = asset::Media::create(key2, "Name-2");
PA mm2 = asset::Media::create(key2, "Name-2");
Asset::Ident key3("Au-2", Category(AUDIO), "ichthyo", 5);
PM mm3 = asset::Media::create(key3, "Name-3");
PA mm3 = asset::Media::create(key3, "Name-3");
Asset::Ident key4("Au-2", Category(AUDIO), "stega", 5);
PM mm4 = asset::Media::create(key4, "Name-4");
PA mm4 = asset::Media::create(key4, "Name-4");
Asset::Ident key5("Au-1", Category(VIDEO), "ichthyo", 5);
PM mm5 = asset::Media::create(key5, "Name-5");
PA mm5 = asset::Media::create(key5, "Name-5");
// ordering of keys
@ -111,7 +119,6 @@ namespace asset
ASSERT (mm2 < mm4);
}
};