softwarecontainer
0.18.0-739e8d7 2017-05-04
|
Represents the configuration of SoftwareContainer (the component) More...
#include <config.h>
Public Member Functions | |
Config (std::vector< std::unique_ptr< ConfigSource >> sources, MandatoryConfigs mandatory, ConfigDependencies dependencies) | |
Constructor - retrieves all configs from the available sources. More... | |
std::string | getStringValue (const std::string &group, const std::string &key) const |
getStringValue Get a config value of type string More... | |
int | getIntValue (const std::string &group, const std::string &key) const |
getIntValue Get a config value of type int More... | |
bool | getBoolValue (const std::string &group, const std::string &key) const |
getBoolValue Get a config value of type bool More... | |
Represents the configuration of SoftwareContainer (the component)
Config gathers all config items present from config sources, and provides the values for these configs when asked. Config handles logic for what is to be considered mandatory or optional, and dependencies between configs.
Config reads all config items from the sources on creation, and stores them for retrieval when users of Config asks for a config value.
Config item uniqueness is based on the combination of config group and config key. Therefore, it is OK to have the same key in multiple groups, but a key must be unique within a group.
Some configs are optional and some are mandatory. A config can become mandatory if some other specified config depends on it. E.g. if an optional config in the main config file is uncommented and thus used, it might mean that other configs are mandatory as a consequence.
It is an error if a mandatory config can not be found or if one or more dependencies to a config can not be found.
There are three different config sources:
The config sources as considered in the above order, i.e. first command line options, then the main config file etc. If a config was retrieved from more than one source, i.e. duplicates, only the value of the highest prioritized source will be returned, and the other(s) ignored.
It is an error if a config requested by the user of Config is not found, even if the config is optional.
softwarecontainer::Config::Config | ( | std::vector< std::unique_ptr< ConfigSource >> | sources, |
MandatoryConfigs | mandatory, | ||
ConfigDependencies | dependencies | ||
) |
Constructor - retrieves all configs from the available sources.
This constructor retrieves all ConfigItem objects from the available config sources, and keeps them for later access by users of Config.
sources | A list of config sources implementing the ConfigSource interface |
mandatory | Configs that are to be considered mandatory |
dependencies | Dependee configs and their respective dependencies |
ConfigMandatoryError | If any mandatory config is missing, i.e. it is not returned by any config source. |
ConfigDependencyError | If one of more dependencies are not met, i.e. there is a config present that has dependencies and all of those dependencies could not be found. |
Definition at line 29 of file config.cpp.
std::string softwarecontainer::Config::getStringValue | ( | const std::string & | group, |
const std::string & | key | ||
) | const |
getStringValue Get a config value of type string
group | The name of the config group the value belongs to |
key | The key for the config value |
ConfigNotFoundError | If the config identified with 'group' and 'key' couldn't be found |
Definition at line 129 of file config.cpp.
int softwarecontainer::Config::getIntValue | ( | const std::string & | group, |
const std::string & | key | ||
) | const |
getIntValue Get a config value of type int
group | The name of the config group the value belongs to |
key | The key for the config value |
ConfigNotFoundError | If the config identified with 'group' and 'key' couldn't be found |
Definition at line 134 of file config.cpp.
bool softwarecontainer::Config::getBoolValue | ( | const std::string & | group, |
const std::string & | key | ||
) | const |
getBoolValue Get a config value of type bool
group | The name of the config group the value belongs to |
key | The key for the config value |
ConfigNotFoundError | If the config identified with 'group' and 'key' couldn't be found |
Definition at line 139 of file config.cpp.