merge basic Assetmanager (builder branch)

Merge branch 'builder'
This commit is contained in:
Fischlurch 2007-09-20 03:48:55 +02:00
commit 22b33a0d58
7 changed files with 197 additions and 27 deletions

View file

@ -34,26 +34,34 @@ namespace util
{
using std::string;
template <class NUM>
inline int
sgn (NUM n)
{
return (n==0)? 0 :((n<0)? -1:+1 );
}
/** a family of util functions providing a "no value whatsoever" test.
Works on strings and all STL containers, includes NULL test for pointers */
template <class CONT>
inline bool
isnil(const CONT& container)
isnil (const CONT& container)
{
return container.empty();
}
template <class CONT>
inline bool
isnil(const CONT* pContainer)
isnil (const CONT* pContainer)
{
return !pContainer || pContainer->empty();
}
template <>
inline bool
isnil(const char* pCStr)
isnil (const char* pCStr)
{
return !pCStr || 0 == std::strlen(pCStr);
}

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

@ -2,6 +2,15 @@ TESTING "Component Test Suite: Asset Manager" ./test-components --group=asset
TEST "AssetCategory_test" AssetCategory_test <<END
out: Category: AUDIO
out: Category: VIDEO/bin1
out: Category: VIDEO/bin1/subbin
out: Category: EFFECT/some_kind
return: 0
END
TEST "CreateAsset_test" CreateAsset_test <<END
return: 0
END
@ -20,5 +29,6 @@ return: 0
END
PLANNED "OrderingOfAssets_test" OrderingOfAssets_test <<END
TEST "OrderingOfAssets_test" OrderingOfAssets_test <<END
return: 0
END

View file

@ -0,0 +1,144 @@
/*
AssetCategory(Test) - verifying Asset category tuple functions
Copyright (C) CinelerraCV
2007, Christian Thaeter <ct@pipapo.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
#include "common/test/run.hpp"
#include "common/util.hpp"
#include "proc/asset/category.hpp"
#include <boost/format.hpp>
#include <iostream>
using boost::format;
using util::isnil;
using std::string;
using std::cout;
namespace asset
{
namespace test
{
/***********************************************************************
* @test checking the properties of Asset Category structs.
* They are included in the Asset::Ident identification tuple
* of Assets and can be used to organize Assets into a tree
* like structure
*/
class AssetCategory_test : public Test
{
virtual void run(Arg arg)
{
createCategory();
containmentQuery();
ordering();
}
void createCategory()
{
Category c1 (AUDIO);
Category c2 (VIDEO,"bin1");
Category c3 (VIDEO,"bin1/subbin");
Category c4 (EFFECT,"some_kind");
format fmt ("Category: %s");
cout << fmt % c1 << "\n";
cout << fmt % c2 << "\n";
cout << fmt % c3 << "\n";
cout << fmt % c4 << "\n";
}
void containmentQuery()
{
Category c1 (VIDEO);
Category c2 (VIDEO,"bin1");
Category c3 (VIDEO,"bin1/subbin");
Category c4 (EFFECT,"some_kind");
ASSERT ( c1.hasKind(VIDEO) );
ASSERT (!c1.hasKind(AUDIO) );
ASSERT ( c2.isWithin(c1) );
ASSERT ( c3.isWithin(c2) );
ASSERT ( c3.isWithin(c1) );
ASSERT (!c1.isWithin(c2) );
ASSERT (!c2.isWithin(c3) );
ASSERT (!c1.isWithin(c3) );
ASSERT (!c3.isWithin(c4) );
ASSERT (!c4.isWithin(c3) );
}
void ordering()
{
Category c1 (AUDIO);
Category c2 (VIDEO);
Category c3 (EFFECT);
Category c4 (CODEC);
Category c5 (STRUCT);
Category c6 (META);
ASSERT (0 > c1.compare(c2));
ASSERT (0 > c2.compare(c3));
ASSERT (0 > c3.compare(c4));
ASSERT (0 > c4.compare(c5));
ASSERT (0 > c5.compare(c6));
ASSERT (0 ==c1.compare(c1));
ASSERT (0 > c1.compare(c6));
Category c21 (VIDEO,"bin1");
Category c22 (VIDEO,"bin2");
Category c23 (VIDEO,"bin2/sub");
ASSERT (0 > c1.compare(c21));
ASSERT (0 > c2.compare(c21));
ASSERT (0 < c22.compare(c21));
ASSERT (0 < c23.compare(c22));
ASSERT (0 < c23.compare(c21));
ASSERT ( 0==c22.compare(c22));
ASSERT ( c2 == c2 );
ASSERT ( c2 != c22 );
ASSERT ( c2 != c3 );
}
};
/** Register this test class... */
LAUNCHER (AssetCategory_test, "unit asset");
} // namespace test
} // namespace asset

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
@ -76,17 +84,17 @@ namespace asset
ASSERT (key4 != key5);
ASSERT (key1 != key5);
ASSERT (-1 == key2.compare(key3));
ASSERT (+1 == key3.compare(key2));
ASSERT ( 0 > key2.compare(key3));
ASSERT ( 0 < key3.compare(key2));
ASSERT (-1 == key3.compare(key4));
ASSERT (-1 == key4.compare(key5));
ASSERT (-1 == key1.compare(key5));
ASSERT (-1 == key2.compare(key5));
ASSERT (-1 == key3.compare(key5));
ASSERT (-1 == key1.compare(key3));
ASSERT (-1 == key1.compare(key4));
ASSERT (-1 == key2.compare(key4));
ASSERT ( 0 > key3.compare(key4));
ASSERT ( 0 > key4.compare(key5));
ASSERT ( 0 > key1.compare(key5));
ASSERT ( 0 > key2.compare(key5));
ASSERT ( 0 > key3.compare(key5));
ASSERT ( 0 > key1.compare(key3));
ASSERT ( 0 > key1.compare(key4));
ASSERT ( 0 > key2.compare(key4));
// ordering of Asset smart ptrs
@ -111,7 +119,6 @@ namespace asset
ASSERT (mm2 < mm4);
}
};