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

Load resources from the disk into the program. More...

#include <ResourceLoader.h>

Public Types

using FileNameList = std::initializer_list< std::string >
 List of filenames to be loaded. More...
 
using Callback = std::function< void(const std::string &)>
 Resource load completion callback. More...
 

Static Public Member Functions

static void setPath (ResourceType type, const std::string &path)
 Set the path where the engine looks when loading a resource type from disk. More...
 
static std::string getPath (ResourceType type)
 Get the path of a resource type. More...
 
static bool loadFromFile (ResourceType type, const std::string &filename)
 Load a resource from the disk. More...
 
static void loadFromFile (ResourceType type, const FileNameList &filenames, const Callback &callback=nullptr)
 load multiple resources of the same type from the disk More...
 
static bool unload (ResourceType type, const std::string &filename)
 Unload a resource from the program. More...
 
static void unloadAll (ResourceType type)
 Unload all resources of a given type from the program. More...
 
static void unloadAll ()
 Remove all resources from the resource holder. More...
 

Detailed Description

Load resources from the disk into the program.

Definition at line 37 of file ResourceLoader.h.

Member Typedef Documentation

◆ Callback

using ime::ResourceLoader::Callback = std::function<void(const std::string&)>

Resource load completion callback.

Definition at line 40 of file ResourceLoader.h.

◆ FileNameList

using ime::ResourceLoader::FileNameList = std::initializer_list<std::string>

List of filenames to be loaded.

Definition at line 39 of file ResourceLoader.h.

Member Function Documentation

◆ getPath()

static std::string ime::ResourceLoader::getPath ( ResourceType  type)
static

Get the path of a resource type.

Parameters
typeThe type to get the path for
Returns
The path for the specified resource type type

The path is where the engine looks when loading a resource of the specified type from the disk

See also
setPath

◆ loadFromFile() [1/2]

static void ime::ResourceLoader::loadFromFile ( ResourceType  type,
const FileNameList filenames,
const Callback callback = nullptr 
)
static

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
FileNotFoundExceptionIf 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]

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

Load a resource from the disk.

Parameters
typeType of the resource to be loaded
filenameFilename of the resource to be loaded
Exceptions
FileNotFoundExceptionIf 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

◆ setPath()

static void ime::ResourceLoader::setPath ( ResourceType  type,
const std::string &  path 
)
static

Set the path where the engine looks when loading a resource type from disk.

Parameters
typeThe type to set the path for
pathThe new path for the resource type

Note that changing the path of either ime::ResourceType::Image or ime::ResourceType::Texture changes the other

See also
getPath

◆ unload()

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

Unload a resource from the program.

Parameters
typeThe type of the resource to be unloaded
filenameFilename of the resource to be removed
Returns
True if the resource was successfully removed, or false if the resource with the given filename does not exist
Note
The resource will only be removed from the program once its not being used. In other words, if the resource is currently being used, this function only flags it for removal at a later time

◆ unloadAll() [1/2]

static void ime::ResourceLoader::unloadAll ( )
static

Remove all resources from the resource holder.

Note
The resources will only be removed from the program once they are no longer being used. In other words, if the resource is currently being used, this function only flags it for removal at a later time

◆ unloadAll() [2/2]

static void ime::ResourceLoader::unloadAll ( ResourceType  type)
static

Unload all resources of a given type from the program.

Parameters
typeThe type of the resources to be unloaded
Note
The resources will only be removed from the program once they are no longer being used. In other words, if the resource is currently being used, this function only flags it for removal at a later time

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