Public Types | Public Member Functions | Static Public Member Functions | List of all members
ime::ResourceManager Class Referencefinal

Class for loading and storing resources (textures, fonts, sound buffers, images and music) More...

#include <ResourceManager.h>

Public Types

using Ptr = std::shared_ptr< ResourceManager >
 Shared ResourceManager pointer. More...
 
template<typename... Args>
using Callback = std::function< void(Args...)>
 Event listener. More...
 

Public Member Functions

 ResourceManager (const ResourceManager &)=delete
 Copy constructor. More...
 
ResourceManageroperator= (const ResourceManager &)=delete
 Assignment operator. More...
 
bool loadFromFile (ResourceType type, const std::string &filename)
 Load a resource from the disk. More...
 
void loadFromFile (ResourceType type, const std::initializer_list< std::string > &filenames, Callback< const std::string & > callback=nullptr)
 load multiple resources of the same type from the disk More...
 
bool unload (ResourceType type, const std::string &filename)
 Unload a resource from the resource manager. More...
 
void setPathFor (ResourceType type, const std::string &path)
 Set the path where resources are located on the disk. More...
 
std::string getPathFor (ResourceType type) const
 Get the path where resources are located on the disk. More...
 
const sf::Font & getFont (const std::string &fileName)
 Get a font. More...
 
const TexturegetTexture (const std::string &fileName)
 Get a texture. More...
 
const sf::SoundBuffer & getSoundBuffer (const std::string &fileName)
 Get a sound buffer. More...
 
const sf::Image & getImage (const std::string &fileName)
 Get an image. More...
 
std::shared_ptr< sf::Music > getMusic (const std::string &fileName)
 Get music. More...
 
 ~ResourceManager ()=default
 Destructor. More...
 

Static Public Member Functions

static ResourceManager::Ptr getInstance ()
 Get class instance. More...
 

Detailed Description

Class for loading and storing resources (textures, fonts, sound buffers, images and music)

Definition at line 60 of file ResourceManager.h.

Member Typedef Documentation

◆ Callback

template<typename... Args>
using ime::ResourceManager::Callback = std::function<void(Args...)>

Event listener.

Definition at line 65 of file ResourceManager.h.

◆ Ptr

using ime::ResourceManager::Ptr = std::shared_ptr<ResourceManager>

Shared ResourceManager pointer.

Definition at line 62 of file ResourceManager.h.

Constructor & Destructor Documentation

◆ ResourceManager()

ime::ResourceManager::ResourceManager ( const ResourceManager )
delete

Copy constructor.

◆ ~ResourceManager()

ime::ResourceManager::~ResourceManager ( )
default

Destructor.

Member Function Documentation

◆ getFont()

const sf::Font& ime::ResourceManager::getFont ( const std::string &  fileName)

Get a font.

Parameters
fileNameFilename of the font
Exceptions
FileNotFoundIf the font cannot be found on the disk
Returns
Requested font

◆ getImage()

const sf::Image& ime::ResourceManager::getImage ( const std::string &  fileName)

Get an image.

Parameters
fileNameFile name of the image
Exceptions
FileNotFoundIf the image cannot be found on the disk
Returns
The requested image

◆ getInstance()

static ResourceManager::Ptr ime::ResourceManager::getInstance ( )
static

Get class instance.

Returns
Shared pointer to class instance

◆ getMusic()

std::shared_ptr<sf::Music> ime::ResourceManager::getMusic ( const std::string &  fileName)

Get music.

Parameters
fileNameFilename of the music
Exceptions
FileNotFoundIf the music cannot be found on the disk
Returns
Pointer to the requested music

◆ getPathFor()

std::string ime::ResourceManager::getPathFor ( ResourceType  type) const

Get the path where resources are located on the disk.

Parameters
typeType of the resource to get path for
Returns
The path where resources are located on the disk for the specified resource type

◆ getSoundBuffer()

const sf::SoundBuffer& ime::ResourceManager::getSoundBuffer ( const std::string &  fileName)

Get a sound buffer.

Parameters
fileNameFile name of the sound buffer
Exceptions
FileNotFoundIf the sound buffer cannot be found on the disk
Returns
The requested sound buffer

◆ getTexture()

const Texture& ime::ResourceManager::getTexture ( const std::string &  fileName)

Get a texture.

Parameters
fileNameFilename of the texture
Exceptions
FileNotFoundIf the texture cannot be found on the disk
Returns
The requested texture

◆ loadFromFile() [1/2]

void ime::ResourceManager::loadFromFile ( ResourceType  type,
const std::initializer_list< std::string > &  filenames,
Callback< const std::string & >  callback = nullptr 
)

load multiple resources of the same type from the disk

Parameters
typeType of the resources to be loaded
filenamesFilenames of the resources to be loaded
callbackFunction to execute after successful load of each resource
Exceptions
FileNotFoundIf one of the files cannot be found on the disk

The callback is passed the name of the resource that was loaded

◆ loadFromFile() [2/2]

bool ime::ResourceManager::loadFromFile ( ResourceType  type,
const std::string &  filename 
)

Load a resource from the disk.

Parameters
typeType of the resource to be loaded
filenameFilename of the resource to be loaded
Exceptions
FileNotFoundIf the resource cannot be found on the disk
Returns
Returns true when the resource was loaded successfully

This function will cache any resource that is successfully loaded from the disk into the program such that is is not reloaded the next time it is required

◆ operator=()

ResourceManager& ime::ResourceManager::operator= ( const ResourceManager )
delete

Assignment operator.

◆ setPathFor()

void ime::ResourceManager::setPathFor ( ResourceType  type,
const std::string &  path 
)

Set the path where resources are located on the disk.

Parameters
typeType of the resource to set path for
pathNew path to resources on th disk

The class will look for resources of the specified type in the new path when loading them

◆ unload()

bool ime::ResourceManager::unload ( ResourceType  type,
const std::string &  filename 
)

Unload a resource from the resource manager.

Parameters
typeType of the resource to unload
filenameFilename of the resource to remove
Returns
True if the resource was unloaded or false if the specified resource does not exist

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