1 #ifndef UGDK_RESOURCE_RESOURCECONTAINER_H_
2 #define UGDK_RESOURCE_RESOURCECONTAINER_H_
6 #include <unordered_map>
11 #define TOSTRING(X) typeid(X).name()
13 #define TOSTRING(X) "<UNKTYPE>"
16 #include <ugdk/system/config.h>
31 template<
class ...Args>
38 void Insert(
const std::string& tag, T* val);
39 void Replace(
const std::string& tag, T* val);
40 bool Exists(
const std::string& tag)
const;
41 T*
Find(
const std::string& tag);
42 T*
Load(
const std::string& filepath,
const std::string& tag);
45 static std::unique_ptr<ResourceContainer>&
Storage() {
46 static std::unique_ptr<ResourceContainer> ptr;
51 using DataMap = std::unordered_map < std::string, std::unique_ptr<T> >;
52 using Loader_T = T* (*)(
const std::string&);
58 ResourceContainer(Loader_T loader) : loader_(loader) {}
63 auto& pos = database_[tag];
65 "ResourceContainer<",
TOSTRING(T),
"> - Tag '", tag,
"' already exists.");
71 database_[tag].reset(val);
76 typename DataMap::const_iterator it = database_.find(tag);
77 return (it != database_.end() && it->second);
82 return database_[tag].get();
88 if (Exists(tag))
return Find(tag);
89 T* obj = loader_(filepath);
91 "GenericContainer<",
TOSTRING(T),
"> - loader_ for '", tag,
"' returned nullptr.");
97 inline T*
NullLoad(
const std::string& filepath) {
99 "NullLoad<",
TOSTRING(T),
"> called with path '", filepath,
"'");
106 #endif // UGDK_RESOURCE_RESOURCECONTAINER_H_
bool Exists(const std::string &tag) const
Definition: resourcecontainer.h:75
void DebugConditionalLog(bool assertion, LogLevel level, const std::string &owner, Ts &&...ts)
If assertion is false, run the DebugLog command.
Definition: log.h:72
~ResourceContainer()
Definition: resourcecontainer.h:36
void DebugLog(LogLevel level, const std::string &owner, Ts &&...ts)
Definition: log.h:60
T * Find(const std::string &tag)
Definition: resourcecontainer.h:81
static ResourceContainer * Get()
Definition: resourcecontainer.h:25
Definition: animation.h:11
static std::unique_ptr< ResourceContainer > & Storage()
Definition: resourcecontainer.h:45
void Insert(const std::string &tag, T *val)
Definition: resourcecontainer.h:62
#define TOSTRING(X)
Definition: resourcecontainer.h:13
void Replace(const std::string &tag, T *val)
Definition: resourcecontainer.h:70
T * Load(const std::string &filepath, const std::string &tag)
Uses T::Load(const std::string&) in order to Load a new object.
Definition: resourcecontainer.h:87
T * NullLoad(const std::string &filepath)
Definition: resourcecontainer.h:97
Definition: resourcecontainer.h:23
static void Create(Args...args)
Definition: resourcecontainer.h:32
static void Clear()
Definition: resourcecontainer.h:28