e2d::core::ResourceMap Class Reference

Inherits std::map< std::string, e2d::core::Resource * >.

List of all members.


Detailed Description

Memory usage is always an issue when making multimedia applications. If you wish to save memory by loading each resource only once, and sharing it with all objects that need them, then you may store these resources in an instance of this class.

Inside Easy2D, when you load any resource through the reading of an xml file, the resource will be automatically added to this map. If any subsequent load to the same resource through xml happens, Easy2D will check the map and get the resource from it, preventing double-loading of the same resource.

Note:
Easy2D will not remove any resource from this map until exitting the application. If you need to free memory during the execution of your game, you will have to remove the resources from the map by yourself.

Public Member Functions

void Clear (void)
 Removes all resources from the map.
ResourceGetResource (string name)
 Gets a resource contained in the map.
void PutResource (string name, Resource *resource)
 Inserts a resource into the map.
bool RemoveResource (string name)
 Removes a resource from the map.

Static Public Member Functions

static ResourceMapGetInstance (void)
 Gets an object for this class.

Member Function Documentation

ResourceMap * e2d::core::ResourceMap::GetInstance ( void   )  [static]

This class is a Singleton. If you want an instance of this class to work with, use this method to get it.

void e2d::core::ResourceMap::Clear ( void   ) 

Removes every resource stored inside the map.

Resource * e2d::core::ResourceMap::GetResource ( string  name  ) 

Gets a resource contained in the map

Parameters:
name Name of the resource you want.
Returns:
a pointer to the resource, or NULL if no resource was found by the provided name.

void e2d::core::ResourceMap::PutResource ( string  name,
Resource resource 
)

Inserts into the map the resource passed as parameter associated with the name provided.

Parameters:
name The name of the resource.
resource The resource you want to put in the map.
Exceptions:
Exception if a resource by that name already exists within the map.

bool e2d::core::ResourceMap::RemoveResource ( string  name  ) 

Removes a resource from the map, thus freeing the memory it uses. If a resource by this name does not exist, nothing happens.

Parameters:
name The name of the resource you want to remove.
Returns:
true if resource was successfuly removed, false if it didn't exist.


Generated on Tue Dec 8 10:32:44 2009 for Easy2D by  doxygen 1.5.6