PixelLightAPI  .
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
PLCore::ResourceManager< AType > Class Template Reference

Abstract resource manager template. More...

#include <ResourceManager.h>

List of all members.

Public Member Functions

String GetManagerName () const
 Returns the name of the manager.
bool SetManagerName (const String &sName="")
 Sets the name of the manager.
bool Clear (bool bProtectedToo=true)
 Clear the manager, delete all resources.
AType * Create (const String &sName="")
 Creates a new resource.
bool Unload (AType &cResource)
 Unload a resource.
uint32 UnloadUnused ()
 Unload unused resources.
bool GetUnloadUnused () const
 Returns whether unused resource are unloaded automatically or not.
void SetUnloadUnused (bool bUnloadUnused=false)
 Sets whether unused resource are unloaded automatically or not.
AType * GetStandard () const
 Get the standard resource.
bool SetStandard (AType *pResource=nullptr)
 Set the standard resource.
uint32 GetNumOfElements () const
 Returns the number of resources within the manager.
virtual AType * LoadResource (const String &sFilename)
 Loads a resource.
virtual bool Init ()
 Initializes the manager.
virtual bool DeInit ()
 De-initializes the manager.
virtual bool Update ()
 Updates the manager.
virtual ResourceManager< AType > & operator= (const ResourceManager< AType > &cSource)
 Copy operator.
virtual AType * GetByIndex (uint32 nIndex=0) const
 Returns the resource at the given index.
virtual AType * GetByName (const String &sName) const
 Returns the resource with the given name.

Public Attributes

PLCore::Event< AType & > EventResourceRemoved

Protected Member Functions

 ResourceManager ()
 Constructor.
virtual ~ResourceManager ()
 Destructor.
bool SetResourceName (AType &cResource, const String &sName)
 Sets the resource name.
virtual AType * CreateResource (const String &sName="")=0
 Creates a new resource.

Protected Attributes

String m_sManagerName
AType * m_pStandardResource
bool m_bUnloadUnused
Array< AType * > m_lstResources
HashMap< String, AType * > m_mapResources

Detailed Description

template<class AType>
class PLCore::ResourceManager< AType >

Abstract resource manager template.


Constructor & Destructor Documentation

template<class AType >
PLCore::ResourceManager< AType >::ResourceManager ( ) [protected]
template<class AType >
PLCore::ResourceManager< AType >::~ResourceManager ( ) [protected, virtual]

Destructor.


Member Function Documentation

template<class AType >
String PLCore::ResourceManager< AType >::GetManagerName ( ) const

Returns the name of the manager.

Returns:
Name of the manager
Note:
  • The manager name has no special usage, it's just for completeness
template<class AType >
bool PLCore::ResourceManager< AType >::SetManagerName ( const String sName = "")

Sets the name of the manager.

Parameters:
[in]sNameNew manager name
Returns:
'true' if all went fine else 'false'
See also:
template<class AType >
bool PLCore::ResourceManager< AType >::Clear ( bool  bProtectedToo = true)

Clear the manager, delete all resources.

Parameters:
[in]bProtectedTooDelete protected resources, too?
Returns:
'true' if all went fine, else 'false'
template<class AType >
AType * PLCore::ResourceManager< AType >::Create ( const String sName = "")

Creates a new resource.

Parameters:
[in]sNameResource name, if "" an unused name is set automatically
Returns:
Pointer to the created resource, a null pointer if there was an error
Note:
  • If there's already a resource with this name, this resource is returned
template<class AType>
bool PLCore::ResourceManager< AType >::Unload ( AType &  cResource)

Unload a resource.

Parameters:
[in]cResourceResource which should be unloaded
Returns:
'true' if all went fine, else 'false'
Note:
  • Protected resources are NOT unloaded!
template<class AType >
uint32 PLCore::ResourceManager< AType >::UnloadUnused ( )

Unload unused resources.

Returns:
Number of unloaded resources
See also:
template<class AType >
bool PLCore::ResourceManager< AType >::GetUnloadUnused ( ) const

Returns whether unused resource are unloaded automatically or not.

Returns:
'true' if unused resources are unloaded automatically, else 'false'
template<class AType >
void PLCore::ResourceManager< AType >::SetUnloadUnused ( bool  bUnloadUnused = false)

Sets whether unused resource are unloaded automatically or not.

Parameters:
[in]bUnloadUnusedUnload unused resources automatically?
template<class AType >
AType * PLCore::ResourceManager< AType >::GetStandard ( ) const

Get the standard resource.

Returns:
The standard resource, a null pointer if there's no such resource
Note:
  • There should always be a standard resource!
  • It is recommended that you protect your standard resource
template<class AType>
bool PLCore::ResourceManager< AType >::SetStandard ( AType *  pResource = nullptr)

Set the standard resource.

Parameters:
[in]pResourceResource which should be the standard resource, a null pointer to set no such resource
Returns:
'true' if all went fine, else 'false' (maybe invalid resource)
See also:
template<class AType >
uint32 PLCore::ResourceManager< AType >::GetNumOfElements ( ) const

Returns the number of resources within the manager.

Returns:
Number of resources within the manager
template<class AType >
AType * PLCore::ResourceManager< AType >::LoadResource ( const String sFilename) [virtual]

Loads a resource.

Parameters:
[in]sFilenameFilename of the resource to load
Returns:
Pointer to the loaded resource, a null pointer on error (maybe the resource can't be load)
Remarks:
The resource name is set to the given filename. If there's already a resource with this (file)name, this resource is returned instead creating a new one. This function is virtual to enable derived managers to add some more features like automatic resource creation instead of loading a resource. In this case, 'filenames' normally begin with 'Create ' to indicate automatic resource creation.
template<class AType >
bool PLCore::ResourceManager< AType >::Init ( ) [virtual]

Initializes the manager.

Returns:
'true' if all went fine, else 'false'
template<class AType >
bool PLCore::ResourceManager< AType >::DeInit ( ) [virtual]

De-initializes the manager.

Returns:
'true' if all went fine, else 'false'
template<class AType >
bool PLCore::ResourceManager< AType >::Update ( ) [virtual]

Updates the manager.

Returns:
'true' if all went fine, else 'false'
template<class AType>
ResourceManager< AType > & PLCore::ResourceManager< AType >::operator= ( const ResourceManager< AType > &  cSource) [virtual]

Copy operator.

Parameters:
[in]cSourceSource to copy from
Returns:
This instance
template<class AType >
AType * PLCore::ResourceManager< AType >::GetByIndex ( uint32  nIndex = 0) const [virtual]

Returns the resource at the given index.

Parameters:
[in]nIndexIndex of the resource
Returns:
The corresponding object, a null pointer if there's no match
template<class AType >
AType * PLCore::ResourceManager< AType >::GetByName ( const String sName) const [virtual]

Returns the resource with the given name.

Parameters:
[in]sNameResource name
Returns:
The corresponding resource, a null pointer if there's no match
Note:
  • You can overload this function to specialize the behavior. This is done for instance within SceneContainer to be able to use 'absolute names' like 'Root.MyScene.MyNode', too.
template<class AType>
bool PLCore::ResourceManager< AType >::SetResourceName ( AType &  cResource,
const String sName 
) [protected]

Sets the resource name.

Sets the unique resource name.

Parameters:
[in]cResourceResource to set the name
[in]sNameNew resource name
Returns:
'true' if all went fine, else 'false' (maybe the name is already used)
See also:
  • GetName()
Note:
  • You can overload this function if there are 'reserved' names which are NOT allowed to be used or if special characters are not allowed
template<class AType>
virtual AType* PLCore::ResourceManager< AType >::CreateResource ( const String sName = "") [protected, pure virtual]

Creates a new resource.

Parameters:
[in]sNameResource name
Returns:
Pointer to the created resource, a null pointer if there was an error
Note:
  • This function is used inside the function Create(). If AType is an abstract class you have to overwrite this function to create an instance of the class.

Member Data Documentation

template<class AType>
PLCore::Event<AType&> PLCore::ResourceManager< AType >::EventResourceRemoved

Resource removed event, removed resource as parameter

template<class AType>
String PLCore::ResourceManager< AType >::m_sManagerName [protected]

Manager name

template<class AType>
AType* PLCore::ResourceManager< AType >::m_pStandardResource [protected]

Standard resource, can be a null pointer

template<class AType>
bool PLCore::ResourceManager< AType >::m_bUnloadUnused [protected]

Unload unused resources?

template<class AType>
Array<AType*> PLCore::ResourceManager< AType >::m_lstResources [protected]

Resource list

Reimplemented in PLSound::SoundManager.

template<class AType>
HashMap<String, AType*> PLCore::ResourceManager< AType >::m_mapResources [protected]

Resource map


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


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:14
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported