nrEngine::IResourceLoader Class Reference
[Resource managment]

Interface for loading/creating resources. More...

Inheritance diagram for nrEngine::IResourceLoader:

nrEngine::FileStreamLoader nrEngine::PluginLoader nrEngine::ScriptLoader

Public Member Functions

virtual ~IResourceLoader ()
SharedPtr< IResourceload (const std::string &name, const std::string &group, const std::string &fileName, const std::string &resourceType=std::string(), PropertyList *param=NULL)
SharedPtr< IResourcecreate (const std::string &name, const std::string &group, const std::string &resourceType, PropertyList *params=NULL)
NR_FORCEINLINE const std::vector<
std::string > & 
getSupportedResourceTypes ()
NR_FORCEINLINE const std::vector<
std::string > & 
getSupportedFileTypes ()
bool supportResourceType (const std::string &resourceType) const
bool supportFileType (const std::string &fileType) const
Result remove (SharedPtr< IResource > resource)

Protected Member Functions

virtual Result loadResource (IResource *res, const std::string &fileName, PropertyList *param=NULL)=0
virtual IResourcecreateResource (const std::string &resourceType, PropertyList *params=NULL)=0
virtual IResourcecreateEmptyResource (const std::string &resourceType)=0
virtual Result initializeResourceLoader ()=0
 IResourceLoader (const std::string &name)
NR_FORCEINLINE std::string mapFileTypeToResourceType (const std::string &fileType)
NR_FORCEINLINE void declareTypeMap (const std::string &fileType, const std::string &resourceType)
NR_FORCEINLINE void declareSupportedResourceType (const std::string &name)
NR_FORCEINLINE void declareSupportedFileType (const std::string &name)
void notifyRemoveResource (SharedPtr< IResource >)

Friends

class ResourceManager
 Resource manager can access the methods here.

Detailed Description

Interface for loading/creating resources.

This is an interface which has to be implemented by each resource loader. A resource loader is an object which can load different kind of resources from different kind of files. For example there can be a image loader which can load PNG, DDS, TGA, .. images and this one can be used to load texture resources. In this case you can derive resource loader classes for different filetypes from your texture resource loader class or just use image loading functions for different types.

Resource loader should be registered by the resource manager. After it is registered it will be automaticly used to load files of different types. If there is no loader registered for that type, so file will not be loaded, error will occurs and empty resource will be used.

Each loader has also to support creating/loading of empty resources. By creating of an empty resource it's holder will not hold any resource. After you loading the resource it will be initialized with the resource data and with the empty resource.

Each loader has a method which says to the manager what kind of resource types it supports. By creating of a resource, you should specify the type of to be created resource. Manager will look in the database, wich loader can create an instance of such a type and will force such a loader to create an instance.

Because only loader does know how to load/unload or create/delete resources in/from the memory so it has the full access on the resources. If you remove any loader, so all associated resources will be also removed from the memory. We need this behaviour also to prevent seg faults by using loaders from plugins, which does own own memory.

Note:
File types and resource types are case sensitive. So *.png and *.PNG are different file types.

Definition at line 63 of file ResourceLoader.h.


Constructor & Destructor Documentation

nrEngine::IResourceLoader::~IResourceLoader (  )  [virtual]

Removing resource loader from the memory, will also remove all loaded objects with this loader.

Definition at line 32 of file ResourceLoader.cpp.

References remove().

nrEngine::IResourceLoader::IResourceLoader ( const std::string &  name  )  [protected]

Create instance of the resource loader.

Parameters:
name Unique name of the loader

Definition at line 26 of file ResourceLoader.cpp.


Member Function Documentation

SharedPtr< IResource > nrEngine::IResourceLoader::load ( const std::string &  name,
const std::string &  group,
const std::string &  fileName,
const std::string &  resourceType = std::string(),
PropertyList param = NULL 
)

This method should create and load a resource from file. The resource does know its filename.

Parameters:
name Unique name for the resource
group Unique group name for this resource
fileName Name of the file containing the resource
resourceType Unique type name of the resource [optional]
param Define load specific name value pairs. Derived classes should know how to handle them. [optional]
Returns:
either OK or an error code

Definition at line 45 of file ResourceLoader.cpp.

References create(), nrEngine::Log::LL_DEBUG, nrEngine::Log::LL_ERROR, loadResource(), nrEngine::Log::LOG_ENGINE, mapFileTypeToResourceType(), nrEngine::ResourceManager::notifyLoaded(), nrEngine::OK, remove(), nrEngine::Engine::sResourceManager(), and supportFileType().

SharedPtr< IResource > nrEngine::IResourceLoader::create ( const std::string &  name,
const std::string &  group,
const std::string &  resourceType,
PropertyList params = NULL 
)

Create an instance of appropriate resource object. Like new ResourceType()

Parameters:
name Unique name of the resource
group Unique group name for the resource
resourceType Unique name of the resource type to be created
params Default is NULL, so no parameters. Specify here pairs of string that represents the parameters for the creating functions. The derived resource loader should know how to handle with them.
Returns:
Instance of such a resource
NOTE: If a new type of resource will be created, so also a new empty resource object will be created of this type. This will be automaticaly registered by the manager.

Definition at line 180 of file ResourceLoader.cpp.

References nrEngine::ResourceManager::getByName(), nrEngine::Log::LL_ERROR, nrEngine::Log::LL_WARNING, nrEngine::ResourceManager::notifyCreated(), nrEngine::Engine::sResourceManager(), and supportResourceType().

Referenced by load().

NR_FORCEINLINE const std::vector<std::string>& nrEngine::IResourceLoader::getSupportedResourceTypes (  ) 

This method should return a vector of strings containing information about which kind of resource instances can this loader create. Each resource has it's unique resource type name. So this vector contains such names.

Definition at line 108 of file ResourceLoader.h.

NR_FORCEINLINE const std::vector<std::string>& nrEngine::IResourceLoader::getSupportedFileTypes (  ) 

This function will return a vector containing information about supported filetypes. It means that this loader can load each file of such a filetype.

Definition at line 114 of file ResourceLoader.h.

bool nrEngine::IResourceLoader::supportResourceType ( const std::string &  resourceType  )  const

This method will say if this loader does support creating of resource of the given resource type.

Parameters:
resourceType Unique name of the resource type
Returns:
true if this loader can create instances of such a type, false otherwise

Definition at line 340 of file ResourceLoader.cpp.

Referenced by create().

bool nrEngine::IResourceLoader::supportFileType ( const std::string &  fileType  )  const

This method will say if this loader does support loading of resource of the given file type.

Parameters:
fileType File type name
Returns:
true if this loader can load such files, false otherwise

Definition at line 349 of file ResourceLoader.cpp.

Referenced by load().

Result nrEngine::IResourceLoader::remove ( SharedPtr< IResource resource  ) 

Remove the resource from the memory. This method will be called by the resource manager, so the loader can do the stuff needed to remove the resource.

Definition at line 262 of file ResourceLoader.cpp.

References nrEngine::Log::LL_WARNING, and notifyRemoveResource().

Referenced by load(), and ~IResourceLoader().

virtual Result nrEngine::IResourceLoader::loadResource ( IResource res,
const std::string &  fileName,
PropertyList param = NULL 
) [protected, pure virtual]

Derived classes must overload this function. This method should load a resource for a given file name

Parameters:
res Resource instance created before with create()
fileName Name of the file containing the resource
param Specific parameters specified by the user

Referenced by load().

virtual IResource* nrEngine::IResourceLoader::createResource ( const std::string &  resourceType,
PropertyList params = NULL 
) [protected, pure virtual]

Implement this function to provide functionaliy of creating resources of certain types. In this function you do not have to check whenever the given resourceType string is valid. This method can only be called from the base class, which does already have checked this.

Parameters:
resourceType Type of the resource
params Parameter list which can be passed for creating

virtual IResource* nrEngine::IResourceLoader::createEmptyResource ( const std::string &  resourceType  )  [protected, pure virtual]

Creating of an empty resource object. An empty resource object can be used in normal way but contains no data.

Parameters:
resourceType Unique name of the resource type to be created
Returns:
Instance of empty resource

virtual Result nrEngine::IResourceLoader::initializeResourceLoader (  )  [protected, pure virtual]

Call this function to initilize the loader. Usually initialization of the loader does declare supported file and resource types. So because this function is pure virtual it must overloaded by derived classes.

This method should be called from the constructor, to declare supported types.

NR_FORCEINLINE std::string nrEngine::IResourceLoader::mapFileTypeToResourceType ( const std::string &  fileType  )  [protected]

Map a certain file type to the resource type. Call this method if you want to find out resources of which types will be created if you use this filetype.

Parameters:
fileType Type of the file (ending *.so, *.bmp, ...)
Returns:
resource type name which will be create for this file type. If the given file type is not supported empty string will be given back

Definition at line 241 of file ResourceLoader.h.

Referenced by load().

NR_FORCEINLINE void nrEngine::IResourceLoader::declareTypeMap ( const std::string &  fileType,
const std::string &  resourceType 
) [protected]

Declare the mapping of file types to resource types. NOTE: You have to specify supported types before

Definition at line 252 of file ResourceLoader.h.

NR_FORCEINLINE void nrEngine::IResourceLoader::declareSupportedResourceType ( const std::string &  name  )  [protected]

Internal function which must be called by all derived classes to setup all supported resource types.

Parameters:
name Unique name of supported resource type

Definition at line 263 of file ResourceLoader.h.

NR_FORCEINLINE void nrEngine::IResourceLoader::declareSupportedFileType ( const std::string &  name  )  [protected]

Internal function which must be called by all derived classes to setup all supported file types.

Parameters:
name Unique name of file type which is supported by the derived loader

Definition at line 272 of file ResourceLoader.h.

void nrEngine::IResourceLoader::notifyRemoveResource ( SharedPtr< IResource  )  [protected]

Notify the resource loader that a certain resource object will be now removed from the memory. The method should be called, by the resource manager, to notify the loader.

Definition at line 287 of file ResourceLoader.cpp.

References nrEngine::ResourceManager::notifyRemove(), and nrEngine::Engine::sResourceManager().

Referenced by remove().


The documentation for this class was generated from the following files:
Generated on Wed Sep 12 23:19:43 2007 for nrEngine by  doxygen 1.5.1