21 #ifndef GF_RESOURCE_MANAGER_H
22 #define GF_RESOURCE_MANAGER_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;
165 #ifndef DOXYGEN_SHOULD_SKIP_THIS
Path getAbsolutePath(const Path &relativePath) const
Search a file in the search directories.
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
ResourceCache(const ResourceCache &)=delete
Deleted copy constructor.
A texture for colored images.
Definition: Texture.h:339
T & getResource(AssetManager &assetManager, const Path &filename)
Get a resource.
Definition: ResourceManager.h:89
ResourceManager()
Default constructor.
A character font.
Definition: Font.h:130
A resource manager.
Definition: ResourceManager.h:131
A generic cache for resources.
Definition: ResourceManager.h:49
ResourceCache & operator=(const ResourceCache &)=delete
Deleted copy assignment.
#define GF_API
Definition: Portability.h:35