Settings class final
#include <engine/settings/settings.hpp>
Stores settings as key-value pairs and provides methods to retrieve them.
Public static functions
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 save(std::string_view path = "/settings.json", int indent = 2) const -> bool
- Save settings as json to specified path.
- auto getValues() const -> const std::unordered_map<std::string, std::string>&
- auto getValues() -> std::unordered_map<std::string, std::string>&
Function documentation
static Settings cubos:: engine:: Settings:: load(std::string_view path = "/settings.json")
Load settings from json in specified path.
| Parameters | |
|---|---|
| path | Virtual cubos:: path to read settings from. |
| Returns | Loaded settings object. |
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.
bool cubos:: engine:: Settings:: save(std::string_view path = "/settings.json",
int indent = 2) const
Save settings as json to specified path.
| Parameters | |
|---|---|
| path | Virtual cubos:: path to write settings in. |
| indent | Indent of the Json, -1 for no whitespace. |
| Returns | Whether call was successful. |
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. |
|---|