ork::ResourceManager Class Reference
[resource]

A resource manager, loads, unloads and updates a set of resources. More...

#include <ResourceManager.h>

Inheritance diagram for ork::ResourceManager:
ork::Object

List of all members.

Public Member Functions

 ResourceManager (ptr< ResourceLoader > loader, unsigned int cacheSize=0)
 Creates a new ResourceManager.
virtual ~ResourceManager ()
 Deletes this resource manager.
ptr< ResourceLoadergetLoader ()
 Returns the object used to load the ResourceDescriptor.
ptr< ObjectloadResource (const string &name)
 Loads the given resource.
ptr< ObjectloadResource (ptr< ResourceDescriptor > desc, const TiXmlElement *f)
 Loads the given resource.
bool updateResources ()
 Updates the already loaded resources if their descriptors have changed.
void close ()
 Closes this manager.

Protected Member Functions

void releaseResource (Resource *resource)
 Releases an unused resource.
void removeResource (Resource *resource)
 Removes a resource from this manager.

Detailed Description

A resource manager, loads, unloads and updates a set of resources.

A manager uses a ResourceLoader to load ResourceDescriptor, then uses a ResourceFactory to create actual Resource. A manager keeps track of the resources it has loaded: it can update (i.e. reload) them when their descriptors change, and it automatically deletes them when they are unused (i.e. unreferenced). Alternatively a manager can cache unused resources so that they can be loaded quickly if they are needed again.


Constructor & Destructor Documentation

ork::ResourceManager::ResourceManager ( ptr< ResourceLoader loader,
unsigned int  cacheSize = 0 
)

Creates a new ResourceManager.

Parameters:
loader the object used to load the ResourceDescriptor.
cacheSize the size of the cache of unused resources.
virtual ork::ResourceManager::~ResourceManager (  )  [virtual]

Deletes this resource manager.

This deletes the cached unused resources, if any.


Member Function Documentation

void ork::ResourceManager::close (  ) 

Closes this manager.

This method disables the cache of unused resources.

ptr<ResourceLoader> ork::ResourceManager::getLoader (  ) 

Returns the object used to load the ResourceDescriptor.

ptr<Object> ork::ResourceManager::loadResource ( ptr< ResourceDescriptor desc,
const TiXmlElement *  f 
)

Loads the given resource.

This method first loads its descriptor with getLoader, then creates the resource with ResourceFactory, and finally returns the result. Unless the resource has already been loaded, in which case it is returned directly.

Parameters:
desc descriptor of the resource to load.
f the XML part of a ResourceDescriptor.
Returns:
the resource corresponding to the given name, or NULL if the resource is not found.
ptr<Object> ork::ResourceManager::loadResource ( const string &  name  ) 

Loads the given resource.

This method first loads its descriptor with getLoader, then creates the resource with ResourceFactory, and finally returns the result. Unless the resource has already been loaded, in which case it is returned directly.

Parameters:
name the name of the resource to be loaded.
Returns:
the resource corresponding to the given name, or NULL if the resource is not found.
void ork::ResourceManager::releaseResource ( Resource resource  )  [protected]

Releases an unused resource.

If there is a cache of unused resources then this resource is put in this cache (the oldest resource in the cache is evicted if the cache is full). Otherwise if there is no cache, the resource is deleted directly.

Parameters:
resource an unused resource, i.e. an unreferenced resource.
void ork::ResourceManager::removeResource ( Resource resource  )  [protected]

Removes a resource from this manager.

This method is called from the Resource destructor when a resource gets deleted (for example when a resource is deleted in the releaseResource method).

Parameters:
resource a resource which is currently being deleted.
bool ork::ResourceManager::updateResources (  ) 

Updates the already loaded resources if their descriptors have changed.

This update is atomic, i.e. either all resources are updated, or none are updated.

Returns:
true if the resources have been updated successfully.

Generated on Mon Oct 18 09:36:11 2010 for ork by  doxygen 1.6.1