Loading...
Searching...
No Matches
ml::ConfigManager< Manifest > Class Template Reference

Manifest-driven accessor for typed configuration values. More...

#include <ConfigManager.h>

Static Public Member Functions

static void ensureInitialized ()
 Ensure the manifest's config values have been registered.
template<typename M = Manifest>
static std::enable_if_t< has_Booleans< M >::value, bool > get (typename M::Booleans config)
 Retrieve a boolean config value.
template<typename M = Manifest>
static std::enable_if_t< has_Floats< M >::value, float > get (typename M::Floats config)
 Retrieve a float config value.
template<typename M = Manifest>
static std::enable_if_t< has_Ints< M >::value, int > get (typename M::Integers config)
 Retrieve an integer config value.
template<typename M = Manifest>
static std::enable_if_t< has_Strings< M >::value, const std::string & > get (typename M::Text config)
 Retrieve a string config value.

Detailed Description

template<typename Manifest>
class ml::ConfigManager< Manifest >

Manifest-driven accessor for typed configuration values.

ConfigManager<Manifest> provides typed get() overloads for each configuration enum declared in a manifest. Each overload is enabled only when the corresponding enum exists, so missing config types are caught at compile time.

Manifest config enums

Enum name in manifest Value type Example
Text std::string Window title, labels
Ints int Max players, tile size
Floats float Speed multiplier, volume
Booleans bool Debug mode, fullscreen

Usage

class MyManifest : public ml::Manifest {
public:
enum class Text { Title };
enum class Ints { MaxPlayers };
enum class Floats { Speed };
private:
inline static const auto _ = [](){
set(Text::Title, std::string("My Game"));
set(Ints::MaxPlayers, 4);
set(Floats::Speed, 1.5f);
return 0;
}();
};
const std::string& title = ml::ConfigManager<MyManifest>::get(MyManifest::Text::Title);
int maxPlayers = ml::ConfigManager<MyManifest>::get(MyManifest::Ints::MaxPlayers);
float speed = ml::ConfigManager<MyManifest>::get(MyManifest::Floats::Speed);
static std::enable_if_t< has_Strings< M >::value, const std::string & > get(typename M::Text config)
Retrieve a string config value.
Base class for all Malena manifests.
Definition Manifest.h:81
static void set(EnumType key, const char *filepath)
Register an asset file path.
A framework-integrated text object with word-wrap support.
Definition Text.h:54

Or more conveniently via Context:

struct MyCtx : public ml::Context<MyManifest> {};
const std::string& title = MyCtx::ConfigMgr::get(MyManifest::Text::Title);
Combines AssetsManager, ConfigManager, and StateManager for a manifest into one convenience struct.
Definition Context.h:60
Template Parameters
ManifestA Manifest subclass declaring config enums (Text, Ints, Floats, Booleans).
See also
Manifest, Context, AssetsManager

Definition at line 88 of file ConfigManager.h.

Member Function Documentation

◆ ensureInitialized()

template<typename Manifest>
void ml::ConfigManager< Manifest >::ensureInitialized ( )
static

Ensure the manifest's config values have been registered.

Called internally before the first get() access. May be called explicitly if you need to guarantee initialization order.

◆ get() [1/4]

template<typename Manifest>
template<typename M = Manifest>
std::enable_if_t< has_Booleans< M >::value, bool > ml::ConfigManager< Manifest >::get ( typename M::Booleans config)
static

Retrieve a boolean config value.

Only available when Manifest declares a Booleans enum.

Parameters
configThe Booleans enum value to look up.
Returns
The registered bool value.

◆ get() [2/4]

template<typename Manifest>
template<typename M = Manifest>
std::enable_if_t< has_Floats< M >::value, float > ml::ConfigManager< Manifest >::get ( typename M::Floats config)
static

Retrieve a float config value.

Only available when Manifest declares a Floats enum.

Parameters
configThe Floats enum value to look up.
Returns
The registered float value.

◆ get() [3/4]

template<typename Manifest>
template<typename M = Manifest>
std::enable_if_t< has_Ints< M >::value, int > ml::ConfigManager< Manifest >::get ( typename M::Integers config)
static

Retrieve an integer config value.

Only available when Manifest declares an Ints enum.

Parameters
configThe Ints enum value to look up.
Returns
The registered int value.

◆ get() [4/4]

template<typename Manifest>
template<typename M = Manifest>
std::enable_if_t< has_Strings< M >::value, const std::string & > ml::ConfigManager< Manifest >::get ( typename M::Text config)
static

Retrieve a string config value.

Only available when Manifest declares a Text enum.

Parameters
configThe Text enum value to look up.
Returns
Const reference to the registered std::string value.

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