nrEngine::ResourceFactory Class Reference
[Resource managment]

Factory class to built instances of resources. More...


Public Member Functions

virtual ~ResourceFactory ()
SharedPtr< IResourcecreateResource (const std::string &resourceType, PropertyList *params=NULL)
SharedPtr< IResourcecreateResource (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 unload (SharedPtr< IResource > resource)
Result remove (SharedPtr< IResource > resource)
Result reload (SharedPtr< IResource > resource)

Protected Member Functions

virtual Result unloadResourceImpl (IResource *res)
virtual Result reloadResourceImpl (IResource *res)
virtual Result loadResourceImpl (IResource *res, const std::string &fileName, PropertyList *param=NULL)=0
virtual IResourcecreateResourceImpl (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)
virtual std::string getSuffix (const std::string &resType)


Detailed Description

Factory class to built instances of resources.

Resource factory is used to create instances of resource objects. Each resource factory has a list of supported resources types. The resource manager can access the previously registered factories to create instances of resources.

Loading of resource itself is done in the resource class. Factories are only used to create instances. Factories should also be able to create instances of empty resources.

Resource factory should be registered by the resource manager to give him a possibility to create or to delete resource instances. system on compiling layer/level.

Factories have got 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 factory can create an instance of such a type and will force it to create an instance.

Factories are strongly associated within created resources. This means that if factory is removed from the memory, then also all created resource will be removed. This behaviour is needed, because otherwise we could get segmentation faults if you use resources from plugins ala dynamic libraries.

Resource factory can also let you know which file types are supported by the supported resource types. So you can find out if resource factory can handle resources

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

Definition at line 59 of file ResourceFactory.h.


Constructor & Destructor Documentation

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

Remove factory instance. Removing will cause created resources also to be removed


Member Function Documentation

SharedPtr<IResource> nrEngine::ResourceFactory::createResource ( const std::string &  resourceType,
PropertyList params = NULL 
)

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

Parameters:
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:
When creating there also will be a check if an empty resource of such a type already exists. If no, then empty resource will be created and registered in the database.

SharedPtr<IResource> nrEngine::ResourceFactory::createResource ( 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:
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:
When creating there also will be a check if an empty resource of such a type already exists. If no, then empty resource will be created and registered in the database.
Parameters:
name Unique name of the resource
group Unique group name of the resource

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

Returns:
A vector of strings containing all supported resource types

Definition at line 92 of file ResourceFactory.h.

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

Returns:
A vector of string cotntainign all supported file types

Definition at line 97 of file ResourceFactory.h.

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

Check if the factory does support creating of resource of the given resource type.

Parameters:
resourceType Unique name of the resource type
Returns:
true if resource type is supported, otherwise false

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

Check whenever the factory can handle given file types.

Parameters:
fileType File type name
Returns:
true if resource instances of this file type are supported

Result nrEngine::ResourceFactory::unload ( SharedPtr< IResource resource  ) 

Unload the given resource. Unloading of a resource does not mean that the resource is removed from the memory. It just release almost all used memory and an empty resource will be used instead. To remove it completly from the memory call remove() instead.

This method will be called by the manager or the resource, as soon as a resource must be unloaded.

Result nrEngine::ResourceFactory::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.

Result nrEngine::ResourceFactory::reload ( SharedPtr< IResource resource  ) 

Reload a certain resource again. A resource object has to be created before. If the resource object is loaded, so it will be unloaded and loaded again. Also the resource object will be notified about this event, so it can react on this. No new instancies will be created.

virtual Result nrEngine::ResourceFactory::unloadResourceImpl ( IResource res  )  [protected, virtual]

Unload a certain resource from the memory. To unload a resource the IResource::unloadRes() method will be called. Herefor each resource should know how to release it's data. However you can overwrite this method in derived classes to change this default behaviour.

Parameters:
res Pointer to the resource which should be unloaded

virtual Result nrEngine::ResourceFactory::reloadResourceImpl ( IResource res  )  [protected, virtual]

Each derived class has to implement a bahaviour of reloading of a resource. This method will be called to reload a given resource object from the file again. All according data is already stored in the resource only the data from the file must be reloaded.

The default behaviour of this method is to call loadImpl() again with the given resource object and a file name (as user parameters the NULL will be passed).

Parameters:
res Resource to be reloaded

virtual Result nrEngine::ResourceFactory::loadResourceImpl ( 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

virtual IResource* nrEngine::ResourceFactory::createResourceImpl ( 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.

virtual IResource* nrEngine::ResourceFactory::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::ResourceFactory::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::ResourceFactory::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 221 of file ResourceFactory.h.

NR_FORCEINLINE void nrEngine::ResourceFactory::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 232 of file ResourceFactory.h.

NR_FORCEINLINE void nrEngine::ResourceFactory::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 243 of file ResourceFactory.h.

NR_FORCEINLINE void nrEngine::ResourceFactory::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 252 of file ResourceFactory.h.

virtual std::string nrEngine::ResourceFactory::getSuffix ( const std::string &  resType  )  [protected, virtual]

This method will return back a proper suffix according to the resource type. Derived classes should overwrite this method, because they know which suffix are proper to use. The suffix does not contain dot. Empty suffixes are possible.

Parameters:
resType Resource type for which one suffix is generated

Definition at line 263 of file ResourceFactory.h.


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