Util::AbstractPool< T > Class Template Reference

Generic pool base class which avoids loading twice ressources (like sounds) from disk. More...

#include <Pool.h>

List of all members.

Public Member Functions

 AbstractPool ()
virtual ~AbstractPool ()
T * load (const boost::filesystem::path &path)
 Loads a resource if it doesn't exist yet, and return a pointer to it.
void remove (const boost::filesystem::path &path)
 Removes a resource by deallocating the internal copy.
void removeAll ()
 Removes all resources.

Protected Member Functions

virtual T * loadFromDisk (const boost::filesystem::path &path)=0
 Loads a ressource from disk.

Private Types

typedef std::pair
< boost::filesystem::path,
osg::ref_ptr< T > > 
TPair
 Type used to store a resource pair.
typedef std::map
< boost::filesystem::path,
osg::ref_ptr< T > > 
TMap

Private Attributes

TMap map
 Pool storage.


Detailed Description

template<class T>
class Util::AbstractPool< T >

Generic pool base class which avoids loading twice ressources (like sounds) from disk.

Resources are identified by their path. Please note that OSG can already cache vertex arrays, nodes and images, so this pool is not useful if the OSG's cache is set for them.

How it works
The pool keeps ressources loaded from disk (the pool own the copy) and returns a pointer to the ressource. The pool is responsible for destruction of the ressource, and the user is responsible for eventually cloning the ressource (for example if modifications are to be made to it). Note that the more convinient way to use a pool is to set it to be a singleton.
Memory overhead
As the ressource is not cloned int the pool, ther is no memory overhead (except for the pool itself). However, if you clone a ressource, the memory overhead will depend on the cloning type. For instance, OSG nodes are usually not fully duplicated (vertex arrays and textures are often not duplicated). Of course, be sure not to modify directly the pool ressource unless you want to. When you do not need what is in the pool anymore, you can simply call remove() or removeAll() to empty the pool (typically when the level ends, if your game is designed with levels).
Author:
Sukender
Version:
0.2.1 - Redesigned with osg::ref_ptr<>, std::map<> and boost::filesystem::path
Todo:
This class may need to be thread-safe

Definition at line 51 of file Pool.h.


Member Typedef Documentation

template<class T >
typedef std::map<boost::filesystem::path, osg::ref_ptr<T> > Util::AbstractPool< T >::TMap [private]

Definition at line 72 of file Pool.h.

template<class T >
typedef std::pair<boost::filesystem::path, osg::ref_ptr<T> > Util::AbstractPool< T >::TPair [private]

Type used to store a resource pair.

Definition at line 71 of file Pool.h.


Constructor & Destructor Documentation

template<class T >
Util::AbstractPool< T >::AbstractPool (  )  [inline]

Definition at line 53 of file Pool.h.

template<class T >
virtual Util::AbstractPool< T >::~AbstractPool (  )  [inline, virtual]

Definition at line 54 of file Pool.h.


Member Function Documentation

template<class T >
T* Util::AbstractPool< T >::load ( const boost::filesystem::path &  path  ) 

Loads a resource if it doesn't exist yet, and return a pointer to it.

template<class T >
virtual T* Util::AbstractPool< T >::loadFromDisk ( const boost::filesystem::path &  path  )  [protected, pure virtual]

Loads a ressource from disk.

template<class T >
void Util::AbstractPool< T >::remove ( const boost::filesystem::path &  path  )  [inline]

Removes a resource by deallocating the internal copy.

Definition at line 59 of file Pool.h.

References Util::AbstractPool< T >::map.

template<class T >
void Util::AbstractPool< T >::removeAll (  )  [inline]

Removes all resources.

Definition at line 61 of file Pool.h.

References Util::AbstractPool< T >::map.


Member Data Documentation

template<class T >
TMap Util::AbstractPool< T >::map [private]

Pool storage.

Definition at line 74 of file Pool.h.

Referenced by Util::AbstractPool< T >::remove(), and Util::AbstractPool< T >::removeAll().


The documentation for this class was generated from the following file:

Generated on Sun Jan 17 11:39:37 2010 for PVLE (Pro-Vocation Light Engine) by  doxygen 1.5.9