cubos::engine::Settings class final

Stores settings as key-value pairs and provides methods to retrieve them.

Public functions

void clear()
Clears all the settings.
void setBool(const std::string& key, bool value)
Defines a new boolean setting.
auto getBool(const std::string& key, bool defaultValue) -> bool
Retrieves the bool setting with the given key.
void setString(const std::string& key, const std::string& value)
Defines a new string setting.
auto getString(const std::string& key, const std::string& defaultValue) -> std::string
Retrieves the string setting with the given key.
void setInteger(const std::string& key, int value)
Defines a new integer setting.
auto getInteger(const std::string& key, int defaultValue) -> int
Retrieves the integer setting with the given key.
void setDouble(const std::string& key, double value)
Defines a new double setting.
auto getDouble(const std::string& key, double defaultValue) -> double
Retrieves the double setting with the given key.
void merge(const Settings& settingsToMerge)
Merges the settings from settingsToMerge.
auto getValues() const -> const std::unordered_map<std::string, std::string>&
auto getValues() -> std::unordered_map<std::string, std::string>&

Function documentation

void cubos::engine::Settings::setBool(const std::string& key, bool value)

Defines a new boolean setting.

Parameters
key Key.
value Value.

If the setting already exists, overwrites its value.

bool cubos::engine::Settings::getBool(const std::string& key, bool defaultValue)

Retrieves the bool setting with the given key.

Parameters
key Key.
defaultValue Default value.
Returns Current value.

If no setting exists with such key, sets it to defaultValue and returns it. If the setting exists but its value is not "true", returns false.

void cubos::engine::Settings::setString(const std::string& key, const std::string& value)

Defines a new string setting.

Parameters
key Key.
value Value.

If the setting already exists, overwrites its value.

std::string cubos::engine::Settings::getString(const std::string& key, const std::string& defaultValue)

Retrieves the string setting with the given key.

Parameters
key Key.
defaultValue Default value.
Returns Current value.

If no setting exists with such key, sets it to defaultValue and returns it.

void cubos::engine::Settings::setInteger(const std::string& key, int value)

Defines a new integer setting.

Parameters
key Key.
value Value.
Returns Current value.

If the setting already exists, overwrites its value.

int cubos::engine::Settings::getInteger(const std::string& key, int defaultValue)

Retrieves the integer setting with the given key.

Parameters
key Key.
defaultValue Default value.
Returns Current value.

If no setting exists with such key, sets it to defaultValue and returns it. If the setting exists but its value is not a valid integer, returns defaultValue.

void cubos::engine::Settings::setDouble(const std::string& key, double value)

Defines a new double setting.

Parameters
key Key.
value Value.

If the setting already exists, overwrites its value.

double cubos::engine::Settings::getDouble(const std::string& key, double defaultValue)

Retrieves the double setting with the given key.

Parameters
key Key.
defaultValue Default value.
Returns Current value.

If no setting exists with such key, sets it to defaultValue and returns it. If the setting exists but its value is not a valid double, returns the default value.

void cubos::engine::Settings::merge(const Settings& settingsToMerge)

Merges the settings from settingsToMerge.

Parameters
settingsToMerge Settings to be merged to this instance.

If a setting from settingsToMerge is already defined in this instance, its value is overwritten.

const std::unordered_map<std::string, std::string>& cubos::engine::Settings::getValues() const

Returns Underlying std::unordered_map with the settings.

std::unordered_map<std::string, std::string>& cubos::engine::Settings::getValues()

Returns Underlying std::unordered_map with the settings.