Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ONE::util::ResourceManager< T, Key, Handle< T > > Class Template Reference

Inheritance diagram for ONE::util::ResourceManager< T, Key, Handle< T > >:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<typename T, typename Key>
class ONE::util::ResourceManager< T, Key, Handle< T > >

ResourceManager partial specialization for handle based managers

This manager defines the additional purge function which removes all unused entries from the cache. Entries are unused if no handle to them exist. This does not account for simple pointers to the actual resource objects.

Author:
Daniel Seibert


Public Types

typedef Handle< T > Handle

Public Member Functions

void clear ()
 clears the cache
Handle< T > get (const Key &k)
 retrieves the object identified by k
unsigned int getCount () const
bool isCached (const Key &k) const
 checks if the object identified by k is cached
void purge ()
 removes all unused entries from the cache
void remove (const Key &k)
 removes an object from the cache
T * trade (const Handle &h)
 retrieves the actual object for the given handle

Protected Member Functions

Handle create (const Key &)
void dispose (Handle &)
virtual T * doCreate (const Key &)=0
virtual std::string toString (const Key &) const =0
 converts the given key to an identifier string


Member Typedef Documentation

template<typename T, typename Key>
typedef Handle<T> ONE::util::ResourceManager< T, Key, Handle< T > >::Handle
 


Member Function Documentation

void ONE::util::ResourceManagerBase< T , Key , Handle< T > >::clear  )  [inherited]
 

clears the cache

All cached resources are destroyed. Note that calling this function will invalidate any pointer to a cached resource that may be held elsewhere.

template<typename T, typename Key>
ResourceManager< T, Key, Handle< T > >::Handle ONE::util::ResourceManager< T, Key, Handle< T > >::create const Key  )  [protected, virtual]
 

Implements ONE::util::ResourceManagerBase< T, Key, Handle< T > >.

template<typename T, typename Key>
void ONE::util::ResourceManager< T, Key, Handle< T > >::dispose Handle  )  [protected, virtual]
 

Implements ONE::util::ResourceManagerBase< T, Key, Handle< T > >.

template<typename T, typename Key>
virtual T* ONE::util::ResourceManager< T, Key, Handle< T > >::doCreate const Key  )  [protected, pure virtual]
 

Handle< T > ONE::util::ResourceManagerBase< T , Key , Handle< T > >::get const Key k  )  [inherited]
 

retrieves the object identified by k

If k is found in the cache, the cached object is returned. Otherwise, a new object is created through the create function, cached via insert and returned.

Parameters:
k the key identifying the desired object
Returns:
an object as specified above

unsigned int ONE::util::ResourceManagerBase< T , Key , Handle< T > >::getCount  )  const [inherited]
 

Returns:
the number of cached objects

bool ONE::util::ResourceManagerBase< T , Key , Handle< T > >::isCached const Key k  )  const [inherited]
 

checks if the object identified by k is cached

The resource will not be loaded if k is not found. Note that this function runs in O(log n) time.

Parameters:
k the desired key

template<typename T, typename Key>
void ONE::util::ResourceManager< T, Key, Handle< T > >::purge  ) 
 

removes all unused entries from the cache

The removed objects are destroyed. The decision to keep or remove an object is based on the handle's reference count, so this function will dispose resources that are only referenced by naked pointers.

void ONE::util::ResourceManagerBase< T , Key , Handle< T > >::remove const Key k  )  [inherited]
 

removes an object from the cache

The removed object is destroyed. Note that this will invalidate any pointer to the resource that may be held elsewhere. If k is unknown, this function will fail silently.

Parameters:
k a key

virtual std::string ONE::util::ResourceManagerBase< T , Key , Handle< T > >::toString const Key  )  const [protected, pure virtual, inherited]
 

converts the given key to an identifier string

The return value is stored in the resource map and must serve as a unique identifier for the key.

template<typename T, typename Key>
T * ONE::util::ResourceManager< T, Key, Handle< T > >::trade const Handle h  )  [inline]
 

retrieves the actual object for the given handle

Returns:
the stored object for h
Exceptions:
InvalidArgumentException if h is invalid


Generated on Wed Sep 7 19:03:33 2005 for ONEngine by  doxygen 1.4.3