Lugdunum  0.1.0
ResourceManager.inl
Go to the documentation of this file.
1 template <typename T>
2 Resource::SharedPtr<T> ResourceManager::get(Resource::Handle handle) {
3  std::lock_guard<std::mutex> resourcesGuard(_mutex);
4 
5  static_assert(
6  std::is_base_of<Resource, T>::value,
7  "T must inherit from Resource"
8  );
9 
10  if (_resources.size() <= handle.index) {
11  return nullptr;
12  }
13 
14  if (_resources[handle.index]->getHandle() == handle) {
15  return _resources[handle.index].get();
16  }
17 
18  return nullptr;
19 }
20 
21 template <typename T>
22 Resource::SharedPtr<T> ResourceManager::add(std::unique_ptr<Resource> resource) {
23  std::lock_guard<std::mutex> resourcesGuard(_mutex);
24 
25  static_assert(
26  std::is_base_of<Resource, T>::value,
27  "T must inherit from Resource"
28  );
29 
30  resource->_handle.index = _resources.size();
31  _resources.push_back(std::move(resource));
32 
33  return dynamic_cast<T*>(_resources.back().get());
34 }
Dummy class for a shared pointer.
Definition: Resource.hpp:66
Handle of the resource. It contains informations such as the type and the index in the ResourceManage...
Definition: Resource.hpp:41
uint32_t index
Index of the Resource in the ResourceManager&#39;s internal storage.
Definition: Resource.hpp:45