ScopedConfiguration
ScopedConfiguration
#include <icy/configuration.h>ScopedConfiguration provides multiple levels of configuration for a module. Multiple levels means that there is a module level scope, and a default scope. When a property is accessed, the module scope value will be used if available, otherwise the default scope value will be used.
Example scoping: Module: channels.[name].modes.[name].[value] Default: modes.[name].[value]
Public Attributes
| Return | Name | Description |
|---|---|---|
Configuration & | config | |
std::string | currentScope | |
std::string | defaultScope |
config
Configuration & configcurrentScope
std::string currentScopedefaultScope
std::string defaultScopePublic Methods
| Return | Name | Description |
|---|---|---|
ScopedConfiguration | #### Parameters | |
ScopedConfiguration | ||
std::string | getString const | Returns the string value, trying currentScope first then defaultScope. |
int | getInt const | Returns the int value, trying currentScope first then defaultScope. |
double | getDouble const | Returns the double value, trying currentScope first then defaultScope. |
bool | getBool const | Returns the bool value, trying currentScope first then defaultScope. |
void | setString | Writes a string value under the scoped key. |
void | setInt | Writes an int value under the scoped key. |
void | setDouble | Writes a double value under the scoped key. |
void | setBool | Writes a bool value under the scoped key. |
std::string | getCurrentScope const | #### Parameters |
std::string | getDafaultKey const | #### Parameters |
std::string | getScopedKey const | #### Parameters |
ScopedConfiguration
ScopedConfiguration(Configuration & config, const std::string & currentScope, const std::string & defaultScope)Parameters
configBacking configuration store.currentScopeKey prefix for the module-level scope.defaultScopeKey prefix for the default/fallback scope.
ScopedConfiguration
ScopedConfiguration(const ScopedConfiguration & that)getString
const
std::string getString(const std::string & key, const std::string & defaultValue, bool forceDefaultScope) constReturns the string value, trying currentScope first then defaultScope.
Parameters
keyProperty key (without scope prefix).defaultValueFallback when neither scope has the key.forceDefaultScopeIf true, skipscurrentScopeand reads fromdefaultScopeonly.
Returns
Property value or defaultValue.
getInt
const
int getInt(const std::string & key, int defaultValue, bool forceDefaultScope) constReturns the int value, trying currentScope first then defaultScope.
Parameters
keyProperty key (without scope prefix).defaultValueFallback when neither scope has the key.forceDefaultScopeIf true, reads fromdefaultScopeonly.
Returns
Property value or defaultValue.
getDouble
const
double getDouble(const std::string & key, double defaultValue, bool forceDefaultScope) constReturns the double value, trying currentScope first then defaultScope.
Parameters
keyProperty key (without scope prefix).defaultValueFallback when neither scope has the key.forceDefaultScopeIf true, reads fromdefaultScopeonly.
Returns
Property value or defaultValue.
getBool
const
bool getBool(const std::string & key, bool defaultValue, bool forceDefaultScope) constReturns the bool value, trying currentScope first then defaultScope.
Parameters
keyProperty key (without scope prefix).defaultValueFallback when neither scope has the key.forceDefaultScopeIf true, reads fromdefaultScopeonly.
Returns
Property value or defaultValue.
setString
void setString(const std::string & key, const std::string & value, bool defaultScope)Writes a string value under the scoped key.
Parameters
keyProperty key (without scope prefix).valueValue to store.defaultScopeIf true, writes todefaultScope; otherwise tocurrentScope.
setInt
void setInt(const std::string & key, int value, bool defaultScope)Writes an int value under the scoped key.
Parameters
keyProperty key (without scope prefix).valueValue to store.defaultScopeIf true, writes todefaultScope; otherwise tocurrentScope.
setDouble
void setDouble(const std::string & key, double value, bool defaultScope)Writes a double value under the scoped key.
Parameters
keyProperty key (without scope prefix).valueValue to store.defaultScopeIf true, writes todefaultScope; otherwise tocurrentScope.
setBool
void setBool(const std::string & key, bool value, bool defaultScope)Writes a bool value under the scoped key.
Parameters
keyProperty key (without scope prefix).valueValue to store.defaultScopeIf true, writes todefaultScope; otherwise tocurrentScope.
getCurrentScope
const
std::string getCurrentScope(const std::string & key) constParameters
keyProperty key (without scope prefix).
Returns
Fully qualified key in currentScope.
getDafaultKey
const
std::string getDafaultKey(const std::string & key) constParameters
keyProperty key (without scope prefix).
Returns
Fully qualified key in defaultScope.
getScopedKey
const
std::string getScopedKey(const std::string & key, bool defaultScope) constParameters
keyProperty key (without scope prefix).defaultScopeIf true, returns thedefaultScopekey; otherwisecurrentScopekey.
Returns
Fully qualified scoped key string.
