Lugdunum  0.1.0
ResourceManager.cpp
Go to the documentation of this file.
2 
6 
7 namespace lug {
8 namespace Graphics {
9 
10 ResourceManager::ResourceManager(Renderer& renderer) : _renderer(renderer) {
12  _loaders["gltf"] = std::make_unique<GltfLoader>(_renderer);
13  _loaders["glb"] = std::make_unique<GltfLoader>(_renderer);
14  }
15 }
16 
18  std::string::size_type extensionPos = filename.find_last_of(".");
19  if (extensionPos == std::string::npos) {
20  LUG_LOG.error("ResourceManager: Can't find extension of the filename {}", filename);
21  return nullptr;
22  }
23 
24  std::string extension = filename.substr(extensionPos + 1);
25 
26  auto loader = _loaders.find(extension);
27  if (loader == _loaders.end()) {
28  LUG_LOG.error("ResourceManager: Can't find loader for extension {}", extension);
29  return nullptr;
30  }
31 
32  return loader->second->loadFile(filename);
33 }
34 
35 } // Graphics
36 } // lug
std::unordered_map< std::string, std::unique_ptr< Loader > > _loaders
Dummy class for a shared pointer.
Definition: Resource.hpp:66
Resource::SharedPtr< Resource > loadFile(const std::string &filename)
Loads a resource from a file.
#define LUG_LOG
Definition: Logger.hpp:73
Type getType() const
Definition: Renderer.inl:5
ResourceManager(Renderer &renderer)
Constructs a ResourceManager, from a Renderer instance.