allow to clear the global Asset registration (#154)

This commit is contained in:
Fischlurch 2012-12-27 01:45:52 +01:00
parent 384ee68129
commit 41f2820781
4 changed files with 58 additions and 29 deletions

View file

@ -93,18 +93,19 @@ namespace asset {
{
IdHashtable table;
DB () : table() { }
~DB () {clear();}
DB()
: table()
{ }
~DB()
{
clear();
}
friend class lib::singleton::StaticCreate<DB>;
public:
template<class KIND>
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>
P<KIND>
get (ID<KIND> hash) const
@ -112,6 +113,25 @@ namespace asset {
return dynamic_pointer_cast<KIND,Asset> (find (hash));
}
template<class KIND>
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);
}
/** removes all registered assets and does something similar
* to Asset::unlink() on each to break cyclic dependencies
* (we can't use the real unlink()-function, because this
@ -120,28 +140,21 @@ namespace asset {
* could result in segfaults. This doesn't seem to be
* a problem, though, because we register and process
* \e all assets and the net effect is just breaking
* any cyclic dependencies)
* any cyclic dependencies)
* @note EX_FREE
*/
void
clear () throw()
{
try
{
IdHashtable::iterator i = table.begin();
IdHashtable::iterator e = table.end();
for ( ; i!=e ; ++i )
i->second->dependants.clear();
table.clear();
}
catch (lumiera::Error& EX)
{
WARN (progress, "Problems while clearing Asset registry: %s", EX.what());
}
catch (...)
{
ERROR (progress, "Serious trouble while clearing Asset registry.");
} }
clear ()
try
{
IdHashtable::iterator i = table.begin();
IdHashtable::iterator e = table.end();
for ( ; i!=e ; ++i )
i->second->dependants.clear();
table.clear();
}
ERROR_LOG_AND_IGNORE (progress, "cleaning the Asset registry")
/** intended for diagnostics */
@ -154,6 +167,7 @@ namespace asset {
output.push_back (i->second);
}
private:
const PAsset &
find (size_t hash) const

View file

@ -210,6 +210,13 @@ namespace asset {
}
void
AssetManager::clear()
{
INFO (progress, "Clearing the Asset registry...");
registry.clear();
}
list<PcAsset>
AssetManager::listContent() const

View file

@ -94,10 +94,18 @@ namespace asset {
/** @return true if the given id is registered with the given Category */
bool known (IDA id, const Category& cat) ;
/**remove the given asset from the internal DB.
/** remove the given asset from the internal DB.
* <i>together with all its dependents</i> */
void remove (IDA id) ;
/** deregister and evict all known Assets.
* @note the actual object instances are managed by reference count,
* i.e. typically the Assets will be kept alive by MObjects from the sesison
* @warning unsure if this design is sane. Asset subsystem needs a rework ////////////////////////////TICKET #691
* @todo verify this actually works, especially with session shutdown ////////////////////////////TICKET #154
*/
void clear() ;
/** extract a sorted list of all registered Assets */
list<PcAsset> listContent() const;

View file

@ -175,7 +175,7 @@ namespace session {
void
deconfigure()
{
TODO ("reset the assets registered with AssetManager");
AssetManager::instance().clear();
/////////////////////////////////////////////////////////////////// TICKET #154
}