|
| SettingsManager (SettingsManagerCreateInfo< CacheTypes... > &createInfo) |
| Create a SettingsManager. More...
|
|
| SettingsManager (const SettingsManager &)=delete |
|
SettingsManager & | operator= (const SettingsManager &)=delete |
|
std::string | toString () const |
|
const util::unordered_string_map< std::string > & | getSettingsMap () const |
| Get a const reference to the underlying map.
|
|
|
const std::string & | get (const std::string &key) const |
| Get a reference to a value. More...
|
|
template<util::IsInPack< CacheTypes... > T> |
const T & | get (const std::string &key) |
| Get a reference to the value coverted to T. More...
|
|
const std::string & | getOr (const std::string &key, const std::string &fallback) |
| Get a reference to the value, or return the fallback if the setting is not present. More...
|
|
template<util::IsInPack< CacheTypes... > T>
requires std::copy_constructible<T> |
const T & | getOr (const std::string &key, const T &fallback) |
| Get a reference to the value coverted to T, or return the fallback if the setting is not present. More...
|
|
const std::string | getCopy (const std::string &key) const |
| Same as get, but returns a copy of value and not a const reference.
|
|
template<util::IsInPack< CacheTypes... > T> |
const T | getCopy (const std::string &key) |
| Same as get<T>, but returns a copy of value and not a const reference.
|
|
const std::string | getCopyOr (const std::string &key, const std::string &fallback) |
| Same as getOr, but returns a copy of value and not a const reference.
|
|
template<util::IsInPack< CacheTypes... > T> |
const T | getCopyOr (const std::string &key, const T &fallback) |
| Same as getOr<T>, but returns a copy of value and not a const reference.
|
|
|
void | set (const std::string &key, const std::string &value) |
| Set the value of key to value. More...
|
|
template<util::IsInPack< CacheTypes... > T> |
void | set (const std::string &key, const T &value) |
| Set the value of key to value. More...
|
|
|
void | addCallbackFunction (const std::string &key, SettingsCallbackFunction callbackFunction) |
| Add a callback function that gets called when the the value to key is changed with set.
|
|
void | removeCallbackFunction (const std::string &key) |
| Remove the callback function for key.
|
|
|
void | writeToFile () const |
|
void | readFromFile (bool checkValidity=true) |
| Read the contents from the provided filepath. More...
|
|
|
- See also
- sm_validity
|
util::unordered_string_map< SettingsManagerAllowedValues< CacheTypes... > > | allowedValues |
|
bool | throwExceptionWhenNewValueNotAllowed |
|
template<NumberInPack< std::string, CacheTypes... > T> |
bool | isValueAllowed (const std::string &key, const T &value) const noexcept |
| Check if a value is allowed for key.
|
|
template<NotNumberInPack< std::string, CacheTypes... > T> |
bool | isValueAllowed (const std::string &key, const T &value) const noexcept |
|
template<util::IsInPack< CacheTypes... > T> |
void | setAllowedValues (const std::string &key, std::vector< T > &allowedValues, SettingsManagerAllowedValueTypes type=SM_LIST) |
| Set the allowed values for a key. More...
|
|
template<util::IsInPack< CacheTypes... > T> |
void | setAllowedValues (const std::string &key, std::vector< T > &&allowedValues, SettingsManagerAllowedValueTypes type=SM_LIST) |
|
void | removeAllowedValues (const std::string &key) noexcept |
| Remove allowed values for key. All values are allowed afterwards.
|
|
void | initAllowedValues () |
| Make sure the allowedValues map is valid. More...
|
|
template<StringConvertible... CacheTypes>
class gz::SettingsManager< CacheTypes >
About
The SettingsManager is basically a map with extra features. It stores key-value pairs in a map. Both key and value are strings, but other types can also be stored.
Restricting values
SettingsManager can restrict the values for a given keys to a range of numbers, or a list of possible strings. This can be done by providing a map containing information on the allowed values in the create info. The settings manager will then never return an invalid value, but it might still throw errors if there is no value set.
Storing other types
While all values are internally strings, SettingsManager can also store different types. The types must satisfy the concept StringConvertible = ConstructibleFromString and ConvertibleToString.
If a value is requested using get<T>(), the value will be converted to T and returned. Additionaly, the converted type is cached so that the conversion can be skipped if it is requested again. The user must instantiate the SettingsManager with all the cache-types beforehand, only those can be retrieved using get.
The strings are converted using fromString(T), which is either user defined for custom types or this library. There is of course no guarantee that the conversion works, the getters will throw an exception if it doesnt.
Callback functions
You can add a callback function for each key that gets called when a setting gets changed.