Loading...
Searching...
No Matches
ml::Manifest Class Reference

Base class for all Malena manifests. More...

#include <Manifest.h>

Inheritance diagram for ml::Manifest:

Static Public Member Functions

template<typename ConfigType, typename ValueType>
static const ValueType & getConfig (ConfigType config)
 Retrieve a typed configuration value by enum key.
template<typename Asset>
static const std::string & getFilepath (const Asset &asset)
 Retrieve the file path registered for an asset enum value.

Static Protected Member Functions

template<typename E, typename V, typename... Args>
static void set (E key, V &&value, Args &&... args)
 Register multiple key-value pairs in one call.
template<typename EnumType>
static void set (EnumType key, const char *filepath)
 Register an asset file path.
template<typename EnumType>
static void set (EnumType key, std::string value)
 Register a string configuration value.
template<typename EnumType, typename ValueType>
static std::enable_if_t< !std::is_same_v< std::decay_t< ValueType >, const char * > &&!std::is_same_v< std::decay_t< ValueType >, std::string > > set (EnumType key, ValueType &&value)
 Register a typed configuration value (int, float, bool, etc.).

Detailed Description

Base class for all Malena manifests.

A manifest is a static registry that maps enum keys to file paths or configuration values. Subclasses declare inner enum types (Images, Fonts, Sounds, Text, Ints, etc.) and populate them using the protected set() methods, typically in an inline static initializer.

The manifest is the contract between a class and its resources. By declaring what a class needs in its manifest, the framework's template machinery (AssetsManager, ConfigManager, ResourceManager) can load and cache those resources automatically without any manual loading code in the class body.

Manifest structure

class MyManifest : public ml::Manifest
{
public:
// Required for plugins
static constexpr const char* name = "My Plugin";
static constexpr const char* version = "1.0.0";
// Asset enums
enum class Images { Background, Button };
enum class Fonts { Main };
enum class Sounds { Click };
// Config enums
enum class Text { WelcomeMessage };
enum class Ints { MaxPlayers };
// Component-level flags and states
enum class Flag { Selected };
enum class State { Idle, Active };
private:
// Inline static initializer registers all paths at program startup
inline static const auto _ = [](){
set(Images::Background, "assets/bg.png");
set(Images::Button, "assets/btn.png");
set(Fonts::Main, "assets/main.ttf");
set(Sounds::Click, "assets/click.wav");
set(Text::WelcomeMessage, std::string("Hello!"));
set(Ints::MaxPlayers, 4);
return 0;
}();
};
Generic button template that combines a shape with a text label.
Definition Button.h:58
Base class for all Malena manifests.
Definition Manifest.h:81
static void set(EnumType key, const char *filepath)
Register an asset file path.
Flag
System-level boolean flags available on every ml::Core object.
Definition Flag.h:60

Accessing registered values

const sf::Texture& bg = ml::TextureManager<MyManifest>::get(MyManifest::Images::Background);
const sf::Font& fnt = ml::FontManager<MyManifest>::get(MyManifest::Fonts::Main);
const std::string& msg = ml::Manifest::getConfig<MyManifest::Text, std::string>(MyManifest::Text::WelcomeMessage);
static const ValueType & getConfig(ConfigType config)
Retrieve a typed configuration value by enum key.
static const sf::Texture & get(const Asset &asset)

Or more conveniently through AssetsManager or Context:

ml::AssetsManager<MyManifest>::get(MyManifest::Images::Background);
static std::enable_if_t< has_Image< M >::value, const sf::Texture & > get(typename M::Images image)
Retrieve a cached sf::Texture by manifest enum value.
See also
AssetsManager, Context, Resources, ResourceManager, ConfigManager

Definition at line 80 of file Manifest.h.

Member Function Documentation

◆ getConfig()

template<typename ConfigType, typename ValueType>
const ValueType & ml::Manifest::getConfig ( ConfigType config)
static

Retrieve a typed configuration value by enum key.

Looks up the value previously registered via set(key, value) where value was not a file path. Throws if the key has not been registered.

Template Parameters
ConfigTypeAn enum type declared inside a Manifest subclass.
ValueTypeThe type of the stored value (e.g., int, float, std::string).
Parameters
configThe specific enum value to look up.
Returns
Const reference to the registered configuration value.

◆ getFilepath()

template<typename Asset>
const std::string & ml::Manifest::getFilepath ( const Asset & asset)
static

Retrieve the file path registered for an asset enum value.

Looks up the path previously registered via set(key, filepath). Throws std::out_of_range if the key has not been registered.

Template Parameters
AssetAn enum type declared inside a Manifest subclass.
Parameters
assetThe specific enum value to look up.
Returns
Const reference to the registered file path string.

◆ set() [1/4]

template<typename E, typename V, typename... Args>
void ml::Manifest::set ( E key,
V && value,
Args &&... args )
staticprotected

Register multiple key-value pairs in one call.

Variadic overload that expands to successive set() calls. Useful for batch registration in the inline static initializer:

set(Images::Background, "assets/bg.png",
Images::Button, "assets/btn.png",
Fonts::Main, "assets/main.ttf");
Template Parameters
EFirst key type.
VFirst value type.
ArgsRemaining key-value pairs.

◆ set() [2/4]

template<typename EnumType>
void ml::Manifest::set ( EnumType key,
const char * filepath )
staticprotected

Register an asset file path.

Associates key with a file path. The path is later retrieved by ResourceManager when loading the asset.

Template Parameters
EnumTypeEnum type of the key (inferred).
Parameters
keyThe enum value to register.
filepathNull-terminated path to the asset file.

◆ set() [3/4]

template<typename EnumType>
void ml::Manifest::set ( EnumType key,
std::string value )
staticprotected

Register a string configuration value.

Associates key with a std::string config value. Distinct from the file-path overload — an explicit std::string signals that this is configuration data, not a resource path.

Template Parameters
EnumTypeEnum type of the key (inferred).
Parameters
keyThe enum value to register.
valueThe string configuration value.

◆ set() [4/4]

template<typename EnumType, typename ValueType>
std::enable_if_t< !std::is_same_v< std::decay_t< ValueType >, const char * > &&!std::is_same_v< std::decay_t< ValueType >, std::string > > ml::Manifest::set ( EnumType key,
ValueType && value )
staticprotected

Register a typed configuration value (int, float, bool, etc.).

Enabled for any ValueType that is not const char* or std::string, routing numeric and boolean config values into their own type-indexed storage.

Template Parameters
EnumTypeEnum type of the key (inferred).
ValueTypeType of the configuration value (inferred).
Parameters
keyThe enum value to register.
valueThe configuration value.

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