#include <xrb_resourcelibrary.hpp>
Classes | |
class | ResourceInstance |
class | ResourceInstanceBase |
struct | ResourceInstanceKey |
Public Types | |
enum | { UNSPECIFIED_LOAD_PARAMETER = static_cast<Sint32>(SINT32_LOWER_BOUND) } |
Public Member Functions | |
ResourceLibrary () | |
Constructor. | |
~ResourceLibrary () | |
Destructor. | |
template<typename T > | |
Resource< T > | LoadPath (T *(*LoadFunction)(std::string const &), std::string const &path) |
Loads a resource from the given path, using the supplied LoadFunction. | |
template<typename T > | |
Resource< T > | LoadPath (T *(*LoadFunction)(std::string const &, Sint32), std::string const &path, Sint32 load_parameter) |
Loads a resource from the given path, using the supplied LoadFunction, with load_parameter as a single extra parameter to LoadFunction. | |
Friends | |
class | ResourceInstance |
class | Resource |
Data associated with a path which is too large to store many times should be managed by ResourceLibrary. When a piece of data is loaded, it is tracked by the ResourceLibrary, so that successive calls to load the same path are transparent and return the existing data. When all references to a loaded piece of data are deleted, that piece of data is deleted from memory.
Resourced data is controlled by the templatized Xrb::Resource object. It provides the mechanisms required for reference-counting so the library can unload unreferenced data.
This is done by loading it using the templatized method LoadPath. The template requires a static function which loads the data from the given path and returns a pointer to whatever the templatized type is. See the various classes which have a Create function (e.g. Xrb::GLTexture::Create and Xrb::Font::Create), as these are appropriate functions for the task.
There is a second version of the templatized LoadPath method which indicates that the load function also takes a Sint32 as an additional parameter. This value can be used to specify additional data necessary to load the resource in addition to the path (see Xrb::Font, where the additional parameter is used for the pixel height for the rendered font data).
When the same path is loaded multiple times, each using a different load parameter, each counts as a separate resource. Think about loading a Font with different pixel heights. The font data is actually an OpenGL texture, and so different pixel heights must be separate textures, even though the font face is the same. However, loading the same path and load parameter will use the same resourced data.
It should be noted that the value SINT32_LOWER_BOUND
( aka UNSPECIFIED_LOAD_PARAMETER
) is reserved and should not be used by the given load function.
ResourceLibrary is a singleton object provided by Xrb::Singleton. It can be accessed using Xrb::Singleton::ResourceLibrary.
Definition at line 65 of file xrb_resourcelibrary.hpp.
Xrb::ResourceLibrary::~ResourceLibrary | ( | ) |
Destructor.
Asserts if there are any remaining resources. This should not happen due to the scope-based life of Resource objects. If it does happen, it's likely that a dynamically-allocated object that contains a Resource object was not deleted.
Definition at line 24 of file xrb_resourcelibrary.cpp.
Resource< T > Xrb::ResourceLibrary::LoadPath | ( | T *(*)(std::string const &) | LoadFunction, | |
std::string const & | path | |||
) | [inline] |
Loads a resource from the given path, using the supplied LoadFunction.
The template argument T must be the type of data being loaded. The template argument LoadFunction must be a static (or global) function which takes a path, and returns a pointer to the newly allocated object of type T. ResourceLibrary depends on the return value of LoadFunction being a newly allocated object, so that it may handle deletion of the object itself.
T | Template argument giving the type of the resource to load. | |
LoadFunction | Template argument giving the static or global function to use to load the resource data. | |
path | The path of the data to load using LoadFunction. |
Definition at line 449 of file xrb_resourcelibrary.hpp.
Referenced by Xrb::WidgetSkin::SetFontFacePath(), Xrb::WidgetSkin::SetFontHeight(), Xrb::WidgetSkin::SetFontHeightRatio(), Xrb::WidgetSkin::SetTexturePath(), Xrb::WidgetBackgroundStylized::WidgetBackgroundStylized(), and Xrb::WidgetBackgroundTextured::WidgetBackgroundTextured().
Resource< T > Xrb::ResourceLibrary::LoadPath | ( | T *(*)(std::string const &, Sint32) | LoadFunction, | |
std::string const & | path, | |||
Sint32 | load_parameter | |||
) | [inline] |
Loads a resource from the given path, using the supplied LoadFunction, with load_parameter as a single extra parameter to LoadFunction.
The template argument T must be the type of data being loaded. The template argument LoadFunction must be a static (or global) function which takes a path, and returns a pointer to the newly allocated object of type T. ResourceLibrary depends on the return value of LoadFunction being a newly allocated object, so that it may handle deletion of the object itself.
T | Template argument giving the type of the resource to load. | |
LoadFunction | Template argument giving the static or global function to use to load the resource data, which also takes a Sint32 as the additional load parameter. | |
path | The path of the data to load using LoadFunction. | |
load_parameter | The extra parameter to pass to LoadFunction. |
Definition at line 509 of file xrb_resourcelibrary.hpp.