Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members  

PLMResMgr Class Reference

Resource manager. More...

#include <PLMResMgr.hpp>

List of all members.

Public Types

enum  {
  TYPE_IMAGE, TYPE_PALETTE, TYPE_FONT, TYPE_TEXT,
  TYPE_SOUND, TYPE_MUSIC, TYPE_3DFONT
}

Public Methods

 PLMResMgr (const PLMResFinder &finder)
 ~PLMResMgr ()
PLMResourceLoad (u32 type, const char *name, int format=PLMResource::FORMAT_UNK, bool keep=true)
PLMResourceGet (const char *name)
bool Add (u32 type, const char *name, PLMResource *data)
bool Reload (const char *name)
bool ReloadType (u32 type)
bool Release (const char *name)
bool Release (PLMResource *res)
u32 RegisterLoader (PLMResLoader loader)
bool ChangeLoader (u32 type, PLMResLoader loader)
void PrintContent () const


Detailed Description

Resource manager.

This object handles all resources in an application. It is the data center, it helps to load and retrieve data easily. It can load data from standard files or from PLM archives.

Notes:

  • add new sources AddSource(), a source can be a directory or a PLM archive file name.
  • when a resource is loaded, the sources are tested in the order they have been added.
  • simply call Load() to load a new resource, or to get access to a previously loaded resource. Use the right file format to avoid any error. The resource is then stored in memory and can be accessed by Load() or Get().
  • a second version of Load() allows to read data from a file directly into an existing resource (created by the user and not by the manager). The first version has a limitation : it can only load standard PLM formats, but with this one, you can read any file (if the PLMResource you give as argument can read it).
  • call Get(), to get a pointer to a previously loaded resource this one will return NULL if the resource has not already been loaded.
  • call Add() to add a resource that is already in memory, but that you want to be handled by the manager.
  • call Remove() to unload a previously loaded resource.
  • all resources are deleted on destruction.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
TYPE_IMAGE  a PLMImage resource
TYPE_PALETTE  a PLMPal resource
TYPE_FONT  a PLMFont resource
TYPE_TEXT  a PLMText resource
TYPE_SOUND  a PLMSound resource
TYPE_MUSIC  a PLMMusic resource
TYPE_3DFONT  a P3DFont resource


Constructor & Destructor Documentation

PLMResMgr::PLMResMgr const PLMResFinder   finder
 

Create an empty resource manager.

PLMResMgr::~PLMResMgr  
 

All resources in the manager are deleted.


Member Function Documentation

PLMResource* PLMResMgr::Load u32    type,
const char *    name,
int    format = PLMResource::FORMAT_UNK,
bool    keep = true
 

Load a resource from current sources (see SetSource()).

Load() always check if the resource is already loaded. The reference counter is then updated.

Parameters:
type  the type of resource, one of TYPE_* or a custom type added with a call to RegisterLoader()
name  name of the resource (file name)
format  file format (ORES_*, see PLMResource for a list). Never use ORES_UNKNOWN since the format is needed to instanciate the right resource object.
keep  a flag to tell the manager to store this resource (true) for later use (Load() or Get() with the same name) or to ignore it (false). This version can only be used with standard PLM resource types.

PLMResource* PLMResMgr::Get const char *    name
 

Get access to a loaded resource.

Increase the reference counter. Unlike Load(), Get() will fail and return NULL if the resource has not been loaded yet.

bool PLMResMgr::Add u32    type,
const char *    name,
PLMResource   data
 

Add a resource (already in memory) to the manager.

The new resource data is associated with a name (name), to be accessed later by Load() or Get(). The reference counter is set to 1.

Parameters:
type  the type of resource, one of TYPE_* or a custom type added with a call to RegisterLoader()
name  name of the resource, it should be unique, it is used to find the resource with Get().
data  a pointer on a resource already in memory.
Returns:
true on success, false if the type is not valid or the name is already used.

bool PLMResMgr::Reload const char *    name
 

Try to reload an existing resource from a file.

The name of the resource is used as file name. Note that this method always closes the file at the end, so it must not be used with resources that need to keep their file open.

Returns:
true on success (file found and succesfully loaded), or false if the name is not an existing resource, or the file can not be found.

bool PLMResMgr::ReloadType u32    type
 

Update all entries of a given resource type, by trying to reload them from their file.

Their name is used as file name. Note that this method always closes the file at the end, so it must not be used with resources that need to keep their file open.

Returns:
true if all updates were successfull (or no update to do), and false if at least one of them has failed (source file not readable or resource added with Add()).

bool PLMResMgr::Release const char *    name
 

Decrease the reference counter and delete the resource if NULL.

This function should be prefered to Remove() and calls to Release() should match the calls to Load()/Get()/Add().

bool PLMResMgr::Release PLMResource   res
 

Decrease the reference counter and delete the resource if NULL.

This function should be prefered to Remove() and calls to Release() should match the calls to Load()/Get()/Add(). Note that only the first occurence of res is released.

u32 PLMResMgr::RegisterLoader PLMResLoader    loader
 

Register a new data type loader.

Register a new data type, and get the new id associated with it. The return id should be used to identify resources of this new type in Load() functions. Note that

Parameters:
loader  the loader that will be used to load all resources of this new type.
Returns:
the id of the new registered type on success (> 0) or PLM::INDEX_ERROR on failure (NULL argument).

bool PLMResMgr::ChangeLoader u32    type,
PLMResLoader    loader
 

Changes the loader associated to a resource type.

This allows the user to modify only registered types, if type has not been registered yet, false is returned. Note that built-in types can be redefined this way, simply use one of TYPE_*.

void PLMResMgr::PrintContent  
 

Print debug info about current state (list of resources).


The documentation for this class was generated from the following file:
  • PLMResMgr.hpp

Generated by Doxygen 1.2.18 on Tue Oct 26 12:07:39 2004.