Mountain  1.0.0
Simple C++ 2D Game Framework
Mountain::ResourceManager Class Referencefinal

Static class used to add, load, get, or unload Resources. More...

#include <resource_manager.hpp>

Static Public Member Functions

template<Concepts::LoadableResourceT T>
static Pointer< TAdd (const std::string &name)
 Creates the Resource corresponding to the given name without loading it.
 
template<Concepts::LoadableResourceT T>
static Pointer< TAdd (const Pointer< File > &file)
 Creates the Resource corresponding to the given file without loading it.
 
template<Concepts::LoadableResourceT T>
static Pointer< TLoad (const Pointer< File > &file, bool_t loadInInterface=true)
 Creates the Resource corresponding to the given file and loads it.
 
static MOUNTAIN_API Pointer< FontLoadFont (const Pointer< File > &file, uint32_t size)
 Creates the Font corresponding to the given file and loads it with the given size.
 
static MOUNTAIN_API Pointer< FontLoadFont (const std::string &name, uint32_t size)
 Creates the Font corresponding to the given name and loads it with the given size.
 
static MOUNTAIN_API void LoadAll ()
 Creates one Resource for each FileManager entry.
 
static MOUNTAIN_API void LoadAllBinaries ()
 Loads all embedded binary Resources created using std::embed. More...
 
static MOUNTAIN_API bool_t Contains (const std::string &name)
 Checks whether the ResourceManager contains the specified Resource name.
 
static MOUNTAIN_API bool_t Contains (const Pointer< File > &file)
 Checks whether the ResourceManager contains the specified Resource file name.
 
static MOUNTAIN_API bool_t IsBinary (const std::string &name)
 Checks whether the given Resource name is an embedded binary Resource. More...
 
template<Concepts::ResourceT T = Resource>
static Pointer< TGet (const std::string &name)
 Returns the Resource that was either added or loaded using the given name.
 
template<Concepts::ResourceT T = Resource>
static Pointer< TGet (const Pointer< File > &file)
 Returns the Resource that was either added or loaded using the given file name.
 
static MOUNTAIN_API Pointer< FontGetFont (const std::string &name, uint32_t size)
 Returns the Font that was loaded using the given name and size.
 
static MOUNTAIN_API Pointer< FontGetFont (const Pointer< File > &file, uint32_t size)
 Returns the Font that was loaded using the given file and size.
 
template<Concepts::ResourceT T = Resource>
static Pointer< TGet (const Guid &guid)
 Returns the Resource that was either added or loaded using the given file name.
 
static MOUNTAIN_API void Rename (const std::string &name, const std::string &newName)
 Renames the Resource with the given name to newName. More...
 
static MOUNTAIN_API void Rename (const Pointer< Resource > &resource, const std::string &newName)
 Renames the given resource to newName. More...
 
template<Concepts::ResourceT T>
static List< Pointer< T > > FindAll ()
 Finds all Resource of type T. More...
 
template<Concepts::ResourceT T>
static void FindAll (List< Pointer< T >> *result)
 
template<Concepts::ResourceT T = Resource>
static Pointer< TFind (const std::function< bool_t(Pointer< T >)> &predicate)
 Finds a specific Resource based on a predicate. More...
 
template<Concepts::ResourceT T = Resource>
static List< Pointer< T > > FindAll (const std::function< bool_t(Pointer< T >)> &predicate)
 Finds a list of Resource based on a predicate. More...
 
template<Concepts::ResourceT T>
static void FindAll (const std::function< bool_t(Pointer< T >)> &predicate, List< Pointer< T >> *result)
 
template<Concepts::ResourceT T>
static bool_t IsResourceOfType (const std::string &name)
 Checks whether the given name corresponds to a Resource of type T.
 
static MOUNTAIN_API void Unload (const std::string &name)
 Unloads the Resource with the given name.
 
template<Concepts::ResourceT T>
static void Unload (const Pointer< T > &resource)
 Unloads the given resource.
 
static MOUNTAIN_API void UnloadAll ()
 Unloads all stored Resources.
 

Detailed Description

Static class used to add, load, get, or unload Resources.

It contains all wrapper instances of the Resource class. These are either added or loaded using the corresponding function: ResourceManager::Add and ResourceManager::Preload.

Definition at line 20 of file resource_manager.hpp.

Member Function Documentation

◆ Find()

template<Concepts::ResourceT T = Resource>
static Pointer<T> Mountain::ResourceManager::Find ( const std::function< bool_t(Pointer< T >)> &  predicate)
static

Finds a specific Resource based on a predicate.

Template Parameters
TThe type of Resource to find.
Parameters
predicateThe predicate used to find the correct Resource. This function will be called for each stored Resource.
Returns
The first Resource for which the predicate returned true. If every Resource returned false, instead return a null Pointer.

◆ FindAll() [1/4]

template<Concepts::ResourceT T>
static List<Pointer<T> > Mountain::ResourceManager::FindAll ( )
static

Finds all Resource of type T.

Template Parameters
TThe type of Resource to find.
Returns
All stored Resource of type T.

◆ FindAll() [2/4]

template<Concepts::ResourceT T>
static void Mountain::ResourceManager::FindAll ( List< Pointer< T >> *  result)
static

◆ FindAll() [3/4]

template<Concepts::ResourceT T = Resource>
static List<Pointer<T> > Mountain::ResourceManager::FindAll ( const std::function< bool_t(Pointer< T >)> &  predicate)
static

Finds a list of Resource based on a predicate.

Template Parameters
TThe type of Resource to find.
Parameters
predicateThe predicate used to find the correct Resource. This function will be called for each stored Resource.
Returns
The first Resource for which the predicate returned true. If every Resource returned false, instead return a null Pointer.

◆ FindAll() [4/4]

template<Concepts::ResourceT T>
static void Mountain::ResourceManager::FindAll ( const std::function< bool_t(Pointer< T >)> &  predicate,
List< Pointer< T >> *  result 
)
static

◆ IsBinary()

static MOUNTAIN_API bool_t Mountain::ResourceManager::IsBinary ( const std::string &  name)
static

Checks whether the given Resource name is an embedded binary Resource.

See also
LoadAllBinaries()

◆ LoadAllBinaries()

static MOUNTAIN_API void Mountain::ResourceManager::LoadAllBinaries ( )
static

Loads all embedded binary Resources created using std::embed.

See also
std::embed

◆ Rename() [1/2]

static MOUNTAIN_API void Mountain::ResourceManager::Rename ( const std::string &  name,
const std::string &  newName 
)
static

Renames the Resource with the given name to newName.

Note
This function only renames the key used to store this Resource, and doesn't in any case rename the Resource itself. For this exact reason, using Resource::SetName instead is the preferred way or renaming a Resource.

◆ Rename() [2/2]

static MOUNTAIN_API void Mountain::ResourceManager::Rename ( const Pointer< Resource > &  resource,
const std::string &  newName 
)
static

Renames the given resource to newName.

Note
This function only renames the key used to store this Resource, and doesn't in any case rename the Resource itself. For this exact reason, using Resource::SetName instead is the preferred way or renaming a Resource.

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