FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
FIFE::ImageManager Class Reference

#include <imagemanager.h>

Inheritance diagram for FIFE::ImageManager:
Inheritance graph
Collaboration diagram for FIFE::ImageManager:
Collaboration graph

Public Member Functions

 ImageManager ()
 
virtual ~ImageManager ()
 
virtual size_t getMemoryUsed () const
 
virtual size_t getTotalResourcesCreated () const
 
virtual size_t getTotalResourcesLoaded () const
 
virtual size_t getTotalResources () const
 
virtual ImagePtr create (IResourceLoader *loader=0)
 
virtual ImagePtr create (const std::string &name, IResourceLoader *loader=0)
 
virtual ImagePtr load (const std::string &name, IResourceLoader *loader=0)
 
virtual ImagePtr loadBlank (uint32_t width, uint32_t height)
 
virtual ImagePtr loadBlank (const std::string &name, uint32_t width, uint32_t height)
 
virtual ImagePtr add (Image *res)
 
virtual bool exists (const std::string &name)
 
virtual bool exists (ResourceHandle handle)
 
virtual void reload (const std::string &name)
 
virtual void reload (ResourceHandle handle)
 
virtual void reloadAll ()
 
virtual void loadUnreferenced ()
 
virtual void free (const std::string &name)
 
virtual void free (ResourceHandle handle)
 
virtual void freeAll ()
 
virtual void freeUnreferenced ()
 
virtual void remove (ImagePtr &resource)
 
virtual void remove (const std::string &name)
 
virtual void remove (ResourceHandle handle)
 
virtual void removeAll ()
 
virtual void removeUnreferenced ()
 
virtual ImagePtr get (const std::string &name)
 
virtual ImagePtr get (ResourceHandle handle)
 
virtual ResourceHandle getResourceHandle (const std::string &name)
 
- Public Member Functions inherited from FIFE::IResourceManager
 IResourceManager ()
 

Detailed Description

ImageManager

An interface for managing images.

See also
IResource
IResourceLoader
IResourceManager

Definition at line 54 of file imagemanager.h.

Constructor & Destructor Documentation

FIFE::ImageManager::ImageManager ( )
inline

Default constructor.

Definition at line 59 of file imagemanager.h.

FIFE::ImageManager::~ImageManager ( )
virtual

Destructor.

Definition at line 43 of file imagemanager.cpp.

Member Function Documentation

ImagePtr FIFE::ImageManager::add ( Image res)
virtual

Add an Image to the manager

This function will create a ImagePtr and add the Image to the manager. The manager assumes ownership of the Image so DO NOT delete it.

Parameters
resA pointer to the Image
Returns
A ImagePtr to the added resource
See also
Image

Definition at line 152 of file imagemanager.cpp.

References exists().

Referenced by create(), and loadBlank().

Here is the caller graph for this function:

ImagePtr FIFE::ImageManager::create ( IResourceLoader *  loader = 0)
virtual

Creates a blank Image but does not load it immediately

Parameters
loaderA pointer to the custom resource loader. The default is NULL. If this parameter is present the resource will use the loader to load instead of the default built in functions.
Returns
An ImagePtr to the newly created Image
See also
Image
ImageLoader
IResourceLoader

Definition at line 92 of file imagemanager.cpp.

References add().

Referenced by load().

Here is the caller graph for this function:

ImagePtr FIFE::ImageManager::create ( const std::string &  name,
IResourceLoader *  loader = 0 
)
virtual

Creates a blank Image but does not load it immediately

Parameters
nameThe resource name. Typically a filename.
loaderA pointer to the custom resource loader. The default is NULL. If this parameter is present the resource will use the loader to load instead of the default built in functions.
Returns
An ImagePtr to the newly created Image
See also
Image
ImageLoader
IResourceLoader

Definition at line 97 of file imagemanager.cpp.

References add(), and exists().

bool FIFE::ImageManager::exists ( const std::string &  name)
virtual

Checks to see if an Image exists

This function will search the manager for Images that match the parameter

Parameters
nameThe name of the Image
Returns
True if the Image exists. False otherwise.

Definition at line 171 of file imagemanager.cpp.

Referenced by add(), and create().

Here is the caller graph for this function:

bool FIFE::ImageManager::exists ( ResourceHandle  handle)
virtual

Checks to see if an Image exists

This function will search the manager for Images that match the parameter

Parameters
handleThe handle of the Image
Returns
True if the Image exists. False otherwise.

Definition at line 180 of file imagemanager.cpp.

void FIFE::ImageManager::free ( const std::string &  name)
virtual

Frees an Image from memory

The Image is not deleted but it's data is freed. This calls the Image::free() function and it is up to the resource to properly free it's memory. The manager keeps a reference to the Image in case its required in the future.

Parameters
nameThe name of the Image
See also
Image

Definition at line 244 of file imagemanager.cpp.

void FIFE::ImageManager::free ( ResourceHandle  handle)
virtual

Frees an Image from memory

The Image is not deleted but it's data is freed. This calls the Image::free() function and it is up to the resource to properly free it's memory. The manager keeps a reference to the Image in case its required in the future.

Parameters
handleThe handle of the Image
See also
Image

Definition at line 257 of file imagemanager.cpp.

void FIFE::ImageManager::freeAll ( )
virtual

Frees all Images

This calls the Image::free() function for every Image the manager is managing. It does not remove them from the manager.

See also
Image

Definition at line 269 of file imagemanager.cpp.

void FIFE::ImageManager::freeUnreferenced ( )
virtual

Frees all unreferenced Image

This calls the IResource::free() function for Images that have no external references to them. It does not remove them from the manager.

See also
IResource

Definition at line 285 of file imagemanager.cpp.

ImagePtr FIFE::ImageManager::get ( const std::string &  name)
virtual

Gets a shared pointer to the Image

If the Image is not defined it will attempt to create and load the Image based on the name (it assumes the name is a filename)

Parameters
nameThe name of the Image
Returns
An ImagePtr to the Image

Definition at line 395 of file imagemanager.cpp.

References load().

ImagePtr FIFE::ImageManager::get ( ResourceHandle  handle)
virtual

Gets a shared pointer to the Image

If the resource is not defined it returns an empty (or invalid) ImagePtr and makes an entry in the log.

Parameters
handleThe handle of the resource
Returns
A ImagePtr to the resource
Todo:
This should throw an exception instead of an empty ImagePtr

Definition at line 411 of file imagemanager.cpp.

size_t FIFE::ImageManager::getMemoryUsed ( ) const
virtual

Gets the total amount of memory used by resources

This function uses the IResource's getSize() function to calculate the total memory used. It does not include memory used by the internal resource manager book keeping structures. This value is only accurate if the resources getSize() function returns an accurate result.

Returns
Total memory used

Implements FIFE::IResourceManager.

Definition at line 47 of file imagemanager.cpp.

ResourceHandle FIFE::ImageManager::getResourceHandle ( const std::string &  name)
virtual

Gets an Image handle by name

Returns the Image handle associated with the name

Parameters
nameThe name of the Image
Returns
0 if the resource name is invalid

Definition at line 449 of file imagemanager.cpp.

size_t FIFE::ImageManager::getTotalResources ( ) const
virtual

Returns the number of defined resources

Gets the total number of resources managed by the manager.

Returns
Total resources managed

Implements FIFE::IResourceManager.

Definition at line 88 of file imagemanager.cpp.

size_t FIFE::ImageManager::getTotalResourcesCreated ( ) const
virtual

Returns the number of unloaded resources

Gets the total number of resources created but not loaded. These resources have been defined in the resource manager but have yet to be loaded from disk.

Returns
Total resources created

Implements FIFE::IResourceManager.

Definition at line 60 of file imagemanager.cpp.

size_t FIFE::ImageManager::getTotalResourcesLoaded ( ) const
virtual

Returns the number of loaded resources

Gets the total number of resources created and loaded. These resources have been defined in the resource manager have been loaded from disk.

Returns
Total resources loaded

Implements FIFE::IResourceManager.

Definition at line 74 of file imagemanager.cpp.

ImagePtr FIFE::ImageManager::load ( const std::string &  name,
IResourceLoader *  loader = 0 
)
virtual

Creates a blank resource and loads it from disk

This function will create the Image if necessary and load the Image from disk. If the Image is not defined it will call ImageManager::create() before loading.

Parameters
nameThe resource name. Typically a filename.
loaderA pointer to the custom resource loader. The default is NULL. If this parameter is present the resource will use the loader to load instead of the default built in functions.
Returns
A ImagePtr to the loaded Image
See also
Image
ImageLoader
IResourceLoader

Definition at line 107 of file imagemanager.cpp.

References create().

Referenced by get().

Here is the caller graph for this function:

ImagePtr FIFE::ImageManager::loadBlank ( uint32_t  width,
uint32_t  height 
)
virtual

Loads a blank resource

Parameters
width
height
Returns
An ImagePtr to the blank image (ready to be modified)

Definition at line 130 of file imagemanager.cpp.

References add().

ImagePtr FIFE::ImageManager::loadBlank ( const std::string &  name,
uint32_t  width,
uint32_t  height 
)
virtual

Loads a blank resource

Parameters
name
width
height
Returns
An ImagePtr to the blank image (ready to be modified)

Definition at line 139 of file imagemanager.cpp.

References add().

void FIFE::ImageManager::loadUnreferenced ( )
virtual

Loads all unreferenced Images

All Images that have no external references will be loaded into memory.

Definition at line 230 of file imagemanager.cpp.

void FIFE::ImageManager::reload ( const std::string &  name)
virtual

Reloads an Image

This function will reload an Image if it is managed by the manager. If not it creates an entry in the log specifying that the Image could not be found. It will load the Image if it is not already loaded.

Parameters
nameThe name of the resource

Definition at line 189 of file imagemanager.cpp.

void FIFE::ImageManager::reload ( ResourceHandle  handle)
virtual

Reloads a resource

This function will reload an Image if it is managed by the manager. If not it creates an entry in the log specifying that the Image could not be found. It will load the Image if it is not already loaded.

Parameters
handleThe handle of the resource

Definition at line 203 of file imagemanager.cpp.

void FIFE::ImageManager::reloadAll ( )
virtual

Reloads all Images

This function will reload all Images managed by the manager. It will load an Image if it is not already loaded.

Todo:
It might be beneficial to supply a parameter to only reload resources that are already loaded

Definition at line 218 of file imagemanager.cpp.

void FIFE::ImageManager::remove ( ImagePtr resource)
virtual

Removes an Image from the manager

This removes all references to the Image from the manager. It does not however guarantee that the resources destructor is called. If the client has any left over references to the resource it will not be freed.

Parameters
resourceA ImagePtr to the image to be removed from the manager
Note
This is useful if you want to remove ownership of a resource from the manager
See also
Image

Definition at line 300 of file imagemanager.cpp.

void FIFE::ImageManager::remove ( const std::string &  name)
virtual

Removes an Image from the manager

This removes all references to the Image from the manager. It does not however guarantee that the resources destructor is called. If the client has any left over references to the resource it will not be freed.

Parameters
nameThe name of the Image
See also
Image

Definition at line 317 of file imagemanager.cpp.

void FIFE::ImageManager::remove ( ResourceHandle  handle)
virtual

Removes an Image from the manager

This removes all references to the Image from the manager. It does not however guarantee that the resources destructor is called. If the client has any left over references to the resource it will not be freed.

Parameters
handleThe handle of the Image
See also
Image

Definition at line 339 of file imagemanager.cpp.

void FIFE::ImageManager::removeAll ( )
virtual

Removes all Images from the manager

This effectively removes all references to all Images from the manager. If there are left over shared pointers to any resources they will not be deleted.

See also
Image

Definition at line 362 of file imagemanager.cpp.

void FIFE::ImageManager::removeUnreferenced ( )
virtual

Removes all unreferenced Images

This effectively removes all Images that dont have an external reference. The resources will be deleted.

See also
Image

Definition at line 374 of file imagemanager.cpp.


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