Engine::ResourceHandler< Content, Key, ContentConstructionInformation > Class Template Reference

Handle a large quantity of data that may be shared and used in multiple places, but we only want it loaded once. More...

#include <ResourceHandler.h>

List of all members.

Public Member Functions

virtual ~ResourceHandler ()
void check_load (const Key &key, ContentConstructionInformation construction_information)
 If a key is not paired with a Content object, create one using the information provided.
Content * get (const Key &key)
 Get a pointer to the data stored for the given key, or 0 if the key is unused.

Static Public Member Functions

static ResourceHandler< Content,
Key, ContentConstructionInformation > & 
get_instance ()
 Get an instance to the resource handler.

Private Member Functions

 ResourceHandler ()
 ResourceHandler (const ResourceHandler &source)
ResourceHandleroperator= (const ResourceHandler &source)

Private Attributes

std::map< Key, Content * > data


Detailed Description

template<class Content, class Key, class ContentConstructionInformation>
class Engine::ResourceHandler< Content, Key, ContentConstructionInformation >

Handle a large quantity of data that may be shared and used in multiple places, but we only want it loaded once.

For example textures and meshes.

Content the class for the objects we wish to store. Key the class for the identifier used to distinguish the objects. It must be orderable, i.e. it has an well-behaved

 operator<(Key lvalue, Key rvalue). 
. The Key should be much smaller than the Content. ContentConstructionInformation A class that can be passed to the constuctor of the Content class. It should also be much smaller than the Content object it will create.

Definition at line 32 of file ResourceHandler.h.


Constructor & Destructor Documentation

template<class Content, class Key, class ContentConstructionInformation>
Engine::ResourceHandler< Content, Key, ContentConstructionInformation >::ResourceHandler (  )  [private]

Definition at line 72 of file ResourceHandler.h.

template<class Content, class Key, class ContentConstructionInformation>
Engine::ResourceHandler< Content, Key, ContentConstructionInformation >::ResourceHandler ( const ResourceHandler< Content, Key, ContentConstructionInformation > &  source  )  [private]

template<class Content, class Key, class ContentConstructionInformation>
Engine::ResourceHandler< Content, Key, ContentConstructionInformation >::~ResourceHandler (  )  [virtual]

Definition at line 77 of file ResourceHandler.h.


Member Function Documentation

template<class Content, class Key, class ContentConstructionInformation>
void Engine::ResourceHandler< Content, Key, ContentConstructionInformation >::check_load ( const Key &  key,
ContentConstructionInformation  construction_information 
)

If a key is not paired with a Content object, create one using the information provided.

If the key is already present, nothing happens.

Parameters:
key The key that should be attached.
construction_information The argument to pass to the constructor of Content to create the object, if the key is not found.

Definition at line 95 of file ResourceHandler.h.

template<class Content, class Key, class ConstructionInfo>
Content * Engine::ResourceHandler< Content, Key, ConstructionInfo >::get ( const Key &  key  ) 

Get a pointer to the data stored for the given key, or 0 if the key is unused.

Parameters:
key The key to look up.
Returns:
A pointer to the Content object created by the first call to check_load() with this key. If no such call was made, returns 0.

Definition at line 108 of file ResourceHandler.h.

template<class Content, class Key, class ConstructionInfo>
ResourceHandler< Content, Key, ConstructionInfo > & Engine::ResourceHandler< Content, Key, ConstructionInfo >::get_instance (  )  [static]

Get an instance to the resource handler.

As the class is templatised, there will be exactly one object per combination of Content, Key and ConstructionInfo types: be careful not to mix Key types when you don't want to. For constructors that take multiple parameters, you'll have to make another class for the paramters. If you want to store objects with a different constructor argument signature in the same ResourceHandler, you'll need to make an abstract class like that and redesign the class.

Definition at line 88 of file ResourceHandler.h.

template<class Content, class Key, class ContentConstructionInformation>
ResourceHandler& Engine::ResourceHandler< Content, Key, ContentConstructionInformation >::operator= ( const ResourceHandler< Content, Key, ContentConstructionInformation > &  source  )  [private]


Member Data Documentation

template<class Content, class Key, class ContentConstructionInformation>
std::map<Key, Content *> Engine::ResourceHandler< Content, Key, ContentConstructionInformation >::data [private]

Definition at line 68 of file ResourceHandler.h.


The documentation for this class was generated from the following file:
Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:17 2010 by Doxygen version 1.4.7 for Racer version svn335.