Lugdunum  0.1.0
Public Member Functions | Private Attributes | List of all members
lug::Graphics::ResourceManager Class Reference

Class for resource manager. The ResourceManager allows the user to load resources and store them. There should be at most one resource manager at any time, it is usually created by the Graphics instance, and retrievable by #Graphics::getResourceManager() More...

#include <ResourceManager.hpp>

Collaboration diagram for lug::Graphics::ResourceManager:
[legend]

Public Member Functions

 ResourceManager (Renderer &renderer)
 Constructs a ResourceManager, from a Renderer instance. More...
 
 ResourceManager (const ResourceManager &)=delete
 
 ResourceManager (ResourceManager &&)=delete
 
ResourceManageroperator= (const ResourceManager &)=delete
 
ResourceManageroperator= (ResourceManager &&)=delete
 
 ~ResourceManager ()=default
 
template<typename T = Resource>
Resource::SharedPtr< T > get (Resource::Handle handle)
 Retrieve a resource from the ResourceManager. More...
 
template<typename T = Resource>
Resource::SharedPtr< T > add (std::unique_ptr< Resource > resource)
 Add a resource to the ResourceManager. More...
 
Resource::SharedPtr< ResourceloadFile (const std::string &filename)
 Loads a resource from a file. More...
 
template<typename T >
Resource::SharedPtr< T > get (Resource::Handle handle)
 
template<typename T >
Resource::SharedPtr< T > add (std::unique_ptr< Resource > resource)
 

Private Attributes

Renderer_renderer
 
std::vector< std::unique_ptr< Resource > > _resources
 
std::unordered_map< std::string, std::unique_ptr< Loader > > _loaders
 
std::mutex _mutex
 

Detailed Description

Class for resource manager. The ResourceManager allows the user to load resources and store them. There should be at most one resource manager at any time, it is usually created by the Graphics instance, and retrievable by #Graphics::getResourceManager()

Definition at line 23 of file ResourceManager.hpp.

Constructor & Destructor Documentation

◆ ResourceManager() [1/3]

lug::Graphics::ResourceManager::ResourceManager ( Renderer renderer)

Constructs a ResourceManager, from a Renderer instance.

Parameters
rendererThe renderer.

Definition at line 10 of file ResourceManager.cpp.

◆ ResourceManager() [2/3]

lug::Graphics::ResourceManager::ResourceManager ( const ResourceManager )
delete

◆ ResourceManager() [3/3]

lug::Graphics::ResourceManager::ResourceManager ( ResourceManager &&  )
delete

◆ ~ResourceManager()

lug::Graphics::ResourceManager::~ResourceManager ( )
default

Member Function Documentation

◆ operator=() [1/2]

ResourceManager& lug::Graphics::ResourceManager::operator= ( const ResourceManager )
delete

◆ operator=() [2/2]

ResourceManager& lug::Graphics::ResourceManager::operator= ( ResourceManager &&  )
delete

◆ get() [1/2]

template<typename T = Resource>
Resource::SharedPtr<T> lug::Graphics::ResourceManager::get ( Resource::Handle  handle)

Retrieve a resource from the ResourceManager.

Parameters
[in]handleThe handle of the resource.
Template Parameters
TThe type of the resource.
Returns
The resource, as a custom SharedPtr<T>, which will allow us to do reference counting later.

◆ add() [1/2]

template<typename T = Resource>
Resource::SharedPtr<T> lug::Graphics::ResourceManager::add ( std::unique_ptr< Resource resource)

Add a resource to the ResourceManager.

Parameters
[in]resourceThe resource to add resource.
Template Parameters
TThe type of the resource.
Returns
The resource, as a custom SharedPtr<T>, which will allow us to do reference counting later.

◆ loadFile()

Resource::SharedPtr< Resource > lug::Graphics::ResourceManager::loadFile ( const std::string &  filename)

Loads a resource from a file.

Parameters
[in]filenameThe filename of the file to load the resource from. The used Loader is determined by the extension of the file, so it must be present!
Returns
A pointer to the resulting resource.

Definition at line 17 of file ResourceManager.cpp.

◆ get() [2/2]

template<typename T >
Resource::SharedPtr<T> lug::Graphics::ResourceManager::get ( Resource::Handle  handle)

Definition at line 2 of file ResourceManager.inl.

◆ add() [2/2]

template<typename T >
Resource::SharedPtr<T> lug::Graphics::ResourceManager::add ( std::unique_ptr< Resource resource)

Definition at line 22 of file ResourceManager.inl.

Member Data Documentation

◆ _renderer

Renderer& lug::Graphics::ResourceManager::_renderer
private

Definition at line 70 of file ResourceManager.hpp.

◆ _resources

std::vector<std::unique_ptr<Resource> > lug::Graphics::ResourceManager::_resources
private

Definition at line 71 of file ResourceManager.hpp.

◆ _loaders

std::unordered_map<std::string, std::unique_ptr<Loader> > lug::Graphics::ResourceManager::_loaders
private

The list of the available loaders. The string is the extension of the file, and the pointer is the corresponding loader. The implementation will determine which loader to call in loadFile thanks to this map.

Definition at line 78 of file ResourceManager.hpp.

◆ _mutex

std::mutex lug::Graphics::ResourceManager::_mutex
private

Definition at line 80 of file ResourceManager.hpp.


The documentation for this class was generated from the following files: