-
Notifications
You must be signed in to change notification settings - Fork 9
/
ResourceManager.h
38 lines (37 loc) · 1.16 KB
/
ResourceManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef RESOURCEMANAGER_H
#define RESOURCEMANAGER_H
#include <memory>
#include <map>
#include <cassert>
template <typename Resource, typename Identifier>
class ResourceManager
{
public:
ResourceManager() = default;
bool load(Identifier id, const std::string& file)
{
std::unique_ptr<Resource> a(new Resource());
bool status = a->loadFromFile(file);
auto x = resMap.insert(std::make_pair(id,std::move(a)));
assert(x.second);
return status;
}
template<typename Parameter>
bool load(Identifier id, const std::string& file,Parameter secParam)
{
std::unique_ptr<Resource> a(new Resource());
bool status = a->loadFromFile(file,secParam);
resMap.insert(std::make_pair(id,std::move(a)));
return status;
}
Resource &get(Identifier id)
{
auto res = resMap.find(id);
assert(res != resMap.end());
return *(res->second);
}
private:
std::map<Identifier, std::unique_ptr<Resource> > resMap;
};
#include "ResourceIdentifiers.h"
#endif // RESOURCEMANAGER_H