21 #ifndef GF_RESOURCE_MANAGER_H    22 #define GF_RESOURCE_MANAGER_H    29 #include "AssetManager.h"    31 #include "Portability.h"    35 #ifndef DOXYGEN_SHOULD_SKIP_THIS    54     using Loader = std::function<std::unique_ptr<T>(
const Path&)>;
    62     : m_loader(
std::move(loader))
    90       std::size_t h = boost::filesystem::hash_value(filename);
    92       auto it = m_cache.find(h);
    94       if (it != m_cache.end()) {
   100       if (absolutePath.empty()) {
   101         throw std::runtime_error(
"Path not found");
   104       auto ptr = m_loader(absolutePath);
   107         throw std::runtime_error(
"Resource not loaded");
   110       auto inserted = m_cache.emplace(h, std::move(ptr));
   112       if (inserted.second) {
   113         return *inserted.first->second;
   116       throw std::runtime_error(
"Resource not inserted in the cache");
   121     std::map<std::size_t, std::unique_ptr<T>> m_cache;
   146       return m_textures.getResource(*
this, path);
   157       return m_fonts.getResource(*
this, path);
   165 #ifndef DOXYGEN_SHOULD_SKIP_THIS   170 #endif // GF_RESOURCE_MANAGER_H Texture & getTexture(const Path &path)
Get a texture. 
Definition: ResourceManager.h:145
 
Font & getFont(const Path &path)
Get a font. 
Definition: ResourceManager.h:156
 
ResourceCache(Loader loader)
Constructor. 
Definition: ResourceManager.h:61
 
An asset manager. 
Definition: AssetManager.h:44
 
A texture for colored images. 
Definition: Texture.h:339
 
T & getResource(AssetManager &assetManager, const Path &filename)
Get a resource. 
Definition: ResourceManager.h:89
 
The namespace for gf classes. 
Definition: Action.h:34
 
A character font. 
Definition: Font.h:130
 
A resource manager. 
Definition: ResourceManager.h:131
 
A generic cache for resources. 
Definition: ResourceManager.h:49
 
boost::filesystem::path Path
A path in the filesystem. 
Definition: Path.h:41
 
std::function< std::unique_ptr< gf::Texture >(const Path &)> Loader
A resource loader. 
Definition: ResourceManager.h:54
 
Path getAbsolutePath(const Path &relativePath) const
Search a file in the search directories.