summaryrefslogtreecommitdiff
path: root/src/resourceManager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/resourceManager.h')
-rw-r--r--src/resourceManager.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/resourceManager.h b/src/resourceManager.h
index be6e250..b69ce1e 100644
--- a/src/resourceManager.h
+++ b/src/resourceManager.h
@@ -7,12 +7,21 @@
#include <stdexcept>
#include <cassert>
+
+// TODO: I don't like the `load` function here as it forces the `Resource` to
+// have a loadFromFile function that they may not have (see TextureFont) or
+// they may need to call with several arguments (see SFML shaders). I think
+// it's better to load them by hand and capture them in the unique pointer
+// inside.
+// Maybe make a `manage` function that gets a pointer and captures.
+
template <typename Resource, typename Identifier>
class ResourceManager{
private:
std::map<Identifier,std::unique_ptr<Resource>> resourceMap;
public:
- void load(Identifier id, const std::string& path);
+ void load(Identifier id, const std::string &path);
+ void manage(Identifier id, Resource *resource);
Resource& get(Identifier id);
const Resource& get(Identifier id) const;
};
@@ -32,6 +41,17 @@ ResourceManager<Resource, Identifier>::load(Identifier id,
}
template <typename Resource, typename Identifier>
+void
+ResourceManager<Resource, Identifier>::manage(Identifier id,
+ Resource *resource){
+ std::unique_ptr<Resource> resource_ptr (resource);
+ auto inserted = resourceMap.insert(
+ std::make_pair(id, std::move(resource_ptr))
+ );
+ assert(inserted.second);
+}
+
+template <typename Resource, typename Identifier>
Resource&
ResourceManager<Resource, Identifier>::get(Identifier id)
{