WIP: ordering of Assets, dump AssetManager, bugfix (partially...)
This commit is contained in:
parent
3a416f9e41
commit
3927f7d5d8
10 changed files with 168 additions and 42 deletions
|
|
@ -81,7 +81,7 @@ namespace util
|
|||
*/
|
||||
template <typename Container, typename Oper>
|
||||
inline Oper
|
||||
for_each (Container& c, Oper& doIt)
|
||||
for_each (Container& c, Oper doIt)
|
||||
{
|
||||
return std::for_each (c.begin(),c.end(), doIt);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,24 +46,25 @@ namespace asset
|
|||
*/
|
||||
Asset::Asset (const Ident& idi)
|
||||
: ident(idi), id(AssetManager::reg (this, idi))
|
||||
{ }
|
||||
{ TRACE (assetmem, "ctor Asset(id=%d) : %s p=%x", size_t(id), cStr(this->ident), this );
|
||||
}
|
||||
|
||||
Asset::~Asset ()
|
||||
{
|
||||
TRACE (assetmem, "dtor Asset(id=%d) : %s", size_t(id), cStr(this->ident) );
|
||||
TRACE (assetmem, "dtor Asset(id=%d) : %s p=%x", size_t(id), cStr(this->ident), this );
|
||||
}
|
||||
|
||||
|
||||
Asset::Ident::operator string () const
|
||||
{
|
||||
static format id_tuple("(%2%:%3%.%1% v%4%)"); // ignoring threadsafety
|
||||
format id_tuple("(%2%:%3%.%1% v%4%)");
|
||||
return str (id_tuple % name % category % org % version);
|
||||
}
|
||||
|
||||
|
||||
Asset::operator string () const
|
||||
{
|
||||
static format id_tuple("Asset(%2%:%3%.%1% v%4%)"); // ignoring threadsafety
|
||||
format id_tuple("Asset(%2%:%3%.%1% v%4%)");
|
||||
return str (id_tuple % ident.name % ident.category % ident.org % ident.version);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -175,6 +175,7 @@ namespace asset
|
|||
&& name == other.name
|
||||
&& category == other.category;
|
||||
}
|
||||
int compare (const Ident& other) const;
|
||||
|
||||
operator string () const;
|
||||
};
|
||||
|
|
@ -261,14 +262,31 @@ namespace asset
|
|||
/** shorthand for refcounting Asset pointers */
|
||||
typedef shared_ptr<Asset> PAsset;
|
||||
|
||||
/** ordering of Assets based on Ident tuple */
|
||||
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); }
|
||||
|
||||
/** 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;
|
||||
return name.compare (oi.name);
|
||||
}
|
||||
|
||||
|
||||
/** convienient for debugging */
|
||||
inline string str (const PAsset& a)
|
||||
{
|
||||
if (a)
|
||||
return string (*a.get());
|
||||
else
|
||||
return "Asset(NULL)";
|
||||
}
|
||||
{
|
||||
if (a)
|
||||
return string (*a.get());
|
||||
else
|
||||
return "Asset(NULL)";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -89,12 +89,22 @@ namespace asset
|
|||
boost::hash_combine(hash, cat.kind_);
|
||||
boost::hash_combine(hash, cat.path_);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
int compare (const Category& co) const
|
||||
{
|
||||
int res = int(kind_) - int(co.kind_);
|
||||
if (1 != res)
|
||||
return res;
|
||||
else
|
||||
return path_.compare (co.path_);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
inline ostream& operator<< (ostream& os, const Category& cago) { return os << string(cago); }
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace asset
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -99,6 +99,16 @@ namespace asset
|
|||
{
|
||||
return dynamic_pointer_cast<KIND,Asset> (table[hash]);
|
||||
}
|
||||
|
||||
/** intended for diagnostics */
|
||||
void
|
||||
asList (list<PAsset>& output) const
|
||||
{
|
||||
IdHashtable::const_iterator i = table.begin();
|
||||
IdHashtable::const_iterator e = table.end();
|
||||
for ( ; i!=e ; ++i )
|
||||
output.push_back (i->second);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
#include "common/multithread.hpp"
|
||||
#include "common/util.hpp"
|
||||
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
//#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
|
@ -191,6 +191,17 @@ namespace asset
|
|||
}
|
||||
|
||||
|
||||
|
||||
list<PAsset>
|
||||
AssetManager::listContent() const
|
||||
{
|
||||
list<PAsset> res;
|
||||
registry.asList (res);
|
||||
res.sort();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
} // namespace asset
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -43,9 +43,11 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
using std::string;
|
||||
using std::list;
|
||||
|
||||
|
||||
|
||||
|
|
@ -86,6 +88,10 @@ namespace asset
|
|||
void remove (IDA id) throw(cinelerra::error::Invalid,
|
||||
cinelerra::error::State);
|
||||
|
||||
/** extract a sorted list of all registered Assets */
|
||||
list<PAsset> listContent() const;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
/** registers an asset object in the internal DB, providing its unique key.
|
||||
|
|
@ -96,7 +102,8 @@ namespace asset
|
|||
throw(cinelerra::error::Invalid);
|
||||
|
||||
/** deleter function used by the Asset smart pointers to delet Asset objects */
|
||||
static void destroy (Asset* m) { delete m; }
|
||||
static void destroy (Asset* m) { TRACE (assetmem, "call destroy (Asset(id=%d)) p=%x", m? size_t(m->getID()):0, m );
|
||||
delete m; }
|
||||
|
||||
friend Asset::Asset (const Asset::Ident& idi);
|
||||
|
||||
|
|
|
|||
73
tests/components/proc/asset/assetdiagnostics.hpp
Normal file
73
tests/components/proc/asset/assetdiagnostics.hpp
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
ASSETDIAGNOSTICS.hpp - collection of test and debug helpers
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
/** @file assetdiagnostics.hpp
|
||||
** Small helper and diagnosic functions related to Asset and AssetManager
|
||||
**
|
||||
** @see assetmanager.hpp
|
||||
** @see CreateAsset_test
|
||||
** @see IdentityOfAssets_test
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ASSET_ASSETDIAGNOSTICS_H
|
||||
#define ASSET_ASSETDIAGNOSTICS_H
|
||||
|
||||
|
||||
#include "proc/assetmanager.hpp"
|
||||
#include "common/util.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using util::for_each;
|
||||
using boost::format;
|
||||
using boost::bind;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
||||
|
||||
namespace asset
|
||||
{
|
||||
|
||||
inline void dump (const PAsset& aa)
|
||||
{
|
||||
if (!aa)
|
||||
cout << "Asset(NULL)\n";
|
||||
else
|
||||
{
|
||||
format fmt("%s %|50T.| id=%d sP=%x ptr=%x use-count=%d");
|
||||
cout << fmt % str(aa) % aa->getID() % &aa % aa.get() % aa.use_count() << "\n";
|
||||
} }
|
||||
|
||||
inline void dumpAssetManager ()
|
||||
{
|
||||
list<PAsset> assets (AssetManager::instance().listContent());
|
||||
cout << "----all-registered-Assets----\n";
|
||||
for_each (assets, bind (&dump, _1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace asset
|
||||
#endif
|
||||
|
|
@ -28,13 +28,10 @@
|
|||
#include "proc/asset/media.hpp"
|
||||
#include "proc/asset/proc.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
#include <iostream>
|
||||
#include "proc/asset/assetdiagnostics.hpp"
|
||||
|
||||
using boost::format;
|
||||
using util::isnil;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
||||
|
||||
namespace asset
|
||||
|
|
@ -55,6 +52,7 @@ namespace asset
|
|||
{
|
||||
createMedia();
|
||||
factoryVariants();
|
||||
dumpAssetManager();
|
||||
}
|
||||
|
||||
typedef shared_ptr<asset::Media> PM;
|
||||
|
|
@ -81,6 +79,9 @@ namespace asset
|
|||
|
||||
ASSERT (aMang.getAsset (mm1->getID()) != mm2);
|
||||
|
||||
cout << "== 1 ==\n";
|
||||
dumpAssetManager();
|
||||
|
||||
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
|
||||
|
|
@ -91,6 +92,9 @@ namespace asset
|
|||
ASSERT (aMang.known (mm2->getID()));
|
||||
ASSERT (aMang.known (mm3->getID()));
|
||||
|
||||
cout << "== 2 ==\n";
|
||||
dumpAssetManager();
|
||||
|
||||
ASSERT ( !aMang.known (mm3->getID(), Category(AUDIO))); // not found within AUDIO-Category
|
||||
try
|
||||
{ // can't be found if specifying wrong Asset kind....
|
||||
|
|
@ -128,10 +132,12 @@ namespace asset
|
|||
ASSERT (mm2->getFilename() == "testfile1.mov");
|
||||
ASSERT (mm3->getFilename() == "testfile2.mov");
|
||||
|
||||
showPtr (mm1);
|
||||
showPtr (mm2);
|
||||
showPtr (mm3);
|
||||
showPtr (mX1);
|
||||
dump (mm1);
|
||||
dump (mm2);
|
||||
dump (mm3);
|
||||
dump (mX1);
|
||||
cout << "== 3 ==\n";
|
||||
dumpAssetManager();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -178,12 +184,6 @@ namespace asset
|
|||
return identity == object->ident
|
||||
&& filename == object->getFilename();
|
||||
}
|
||||
|
||||
void showPtr (PM m)
|
||||
{
|
||||
static format fmt("Asset(%s) .... ptr=%d use-count=%d");
|
||||
cout << fmt % str(m) % &m % m.use_count() << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,13 +28,10 @@
|
|||
#include "proc/asset/media.hpp"
|
||||
#include "proc/asset/proc.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
#include <iostream>
|
||||
#include "proc/asset/assetdiagnostics.hpp"
|
||||
|
||||
using boost::format;
|
||||
using util::isnil;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
||||
|
||||
namespace asset
|
||||
|
|
@ -56,6 +53,7 @@ namespace asset
|
|||
virtual void run(Arg arg)
|
||||
{
|
||||
createDuplicate();
|
||||
cout << "ausis\n";
|
||||
}
|
||||
|
||||
typedef shared_ptr<asset::Media> PM;
|
||||
|
|
@ -72,8 +70,9 @@ namespace asset
|
|||
Asset::Ident idi (mm1->ident); // duplicate Ident record
|
||||
PM mm1X = asset::Media::create (idi); // note: we actually don't call any ctor
|
||||
ASSERT (mm1 == mm1X); // instead, we got mm1 back.
|
||||
|
||||
cout << "usi-v " << mm1.use_count() <<"\n";
|
||||
PM mm2 = asset::Media::create (idi,"testfile2.mov");
|
||||
cout << "usi-n " << mm1.use_count() <<"\n";
|
||||
ASSERT (mm1->getID() == mm2->getID()); // different object, same hash
|
||||
|
||||
AssetManager& aMang = AssetManager::instance();
|
||||
|
|
@ -87,16 +86,13 @@ namespace asset
|
|||
ASSERT (mm1->getFilename() == "testfile1.mov");
|
||||
ASSERT (mm2->getFilename() == "testfile2.mov");
|
||||
|
||||
showPtr (mm1);
|
||||
showPtr (mm1X);
|
||||
showPtr (mm2);
|
||||
cout << "use-cnt at end " << mm1.use_count() <<"\n";
|
||||
dump (mm1);
|
||||
dump (mm1X);
|
||||
dump (mm2);
|
||||
dumpAssetManager();
|
||||
}
|
||||
|
||||
void showPtr (PM m)
|
||||
{
|
||||
static format fmt("Asset(%s) .... ptr=%d use-count=%d");
|
||||
cout << fmt % str(m) % &m % m.use_count() << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue