wPlot2D version: 0.1.1
A lightweight C++ library for clear and customizable 2D scientific plots.
Loading...
Searching...
No Matches
wEngine::AssetManager Class Reference

Manages graphical assets such as fonts for reuse across the application. More...

#include <wAssetManager.hpp>

Public Member Functions

 AssetManager ()=default
 AssetManager (const AssetManager &)=delete
AssetManageroperator= (const AssetManager &)=delete
 ~AssetManager ()=default
void LoadFont (const std::string &name, const std::string &fileName)
 Loads a font from file and stores it under a given name.
void LoadFont (const std::string &name, const std::vector< std::string > &possiblePaths)
 Loads a font by trying multiple possible file paths until success.
sf::Font & getFont (const std::string &name)
 Retrieves a reference to a previously loaded font.
void RemoveFont (const std::string &name)
 Removes a previously loaded font from memory.
void debugPrintFonts () const
 Prints the list of loaded fonts to standard output.

Detailed Description

Manages graphical assets such as fonts for reuse across the application.

This class provides a centralized way to load, access, and manage graphical assets, currently supporting fonts via SFML. Assets are identified by string keys and stored internally to avoid reloading them multiple times.

Key features:

  • Load fonts from file and associate them with a name.
  • Access loaded fonts via their name.
  • Remove fonts from memory when no longer needed.
  • Debug printing of loaded assets.

This manager is non-copyable to ensure centralized ownership and avoid accidental duplication of resources.

Note
If an asset fails to load or is accessed without being loaded first, a std::runtime_error is thrown.
Author
Wilfried Koch

Constructor & Destructor Documentation

◆ AssetManager() [1/2]

wEngine::AssetManager::AssetManager ( )
default

◆ AssetManager() [2/2]

wEngine::AssetManager::AssetManager ( const AssetManager & )
delete

◆ ~AssetManager()

wEngine::AssetManager::~AssetManager ( )
default

Member Function Documentation

◆ operator=()

AssetManager & wEngine::AssetManager::operator= ( const AssetManager & )
delete

◆ LoadFont() [1/2]

void wEngine::AssetManager::LoadFont ( const std::string & name,
const std::string & fileName )

Loads a font from file and stores it under a given name.

If successful, the font is stored under the given name and can later be retrieved with getFont( name ). If loading fails, an exception is thrown.

Parameters
nameThe unique name used to identify the font.
fileNameThe path to the font file on disk.
Exceptions
std::runtime_errorif the font cannot be loaded from file.

◆ LoadFont() [2/2]

void wEngine::AssetManager::LoadFont ( const std::string & name,
const std::vector< std::string > & possiblePaths )

Loads a font by trying multiple possible file paths until success.

This function attempts to load the specified font (name) by iterating through several possible paths provided in possiblePaths.
It silences SFML's internal error messages during the process to avoid clutter.

  • The function stops at the first successful load.
  • If none of the paths work, it throws a std::runtime_error with the list of paths tested.
  • The successfully loaded font is stored in the internal font map.
Parameters
nameLogical name of the font (used as key in the font map).
possiblePathsList of file paths to try (in order of priority).
Exceptions
std::runtime_errorif all paths fail to load the font.
Note
This approach makes font loading robust across different directory structures, such as development (../Resources/Fonts/...) and distribution (../wPlot2D/Resources/Fonts/...).

◆ getFont()

sf::Font & wEngine::AssetManager::getFont ( const std::string & name)

Retrieves a reference to a previously loaded font.

Parameters
nameThe name of the font previously loaded.
Returns
Reference to the corresponding sf::Font object.
Exceptions
std::runtime_errorif the font does not exist.

◆ RemoveFont()

void wEngine::AssetManager::RemoveFont ( const std::string & name)

Removes a previously loaded font from memory.

Parameters
nameThe name of the font to remove.
Exceptions
std::runtime_errorif the font does not exist.

◆ debugPrintFonts()

void wEngine::AssetManager::debugPrintFonts ( ) const

Prints the list of loaded fonts to standard output.


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