MarlinMT
0.1.0
|
Configuration class. More...
#include <Configuration.h>
Public Types | |
using | ConfigSectionMap = ConfigSection::ConfigSectionMap |
using | ConstantsMap = std::map< std::string, std::string > |
Public Member Functions | |
Configuration ()=default | |
~Configuration ()=default | |
Configuration (const Configuration &)=default | |
Configuration (Configuration &&)=default | |
Configuration & | operator= (const Configuration &)=default |
Configuration & | operator= (Configuration &&)=default |
Constants | |
template<typename T > | |
T | constantAs (const std::string &cn) const |
Get a constant value as type T. More... | |
template<typename T > | |
T | constantAs (const std::string &cn, const T &defVal) const |
Get a constant value as type T. More... | |
template<typename T > | |
Configuration & | addConstant (const std::string &cn, const T &val) |
Add a constant. More... | |
bool | hasConstant (const std::string &cn) const |
Whetehr the constant is registered in the configuration. More... | |
const ConstantsMap & | constants () const |
Get the constants map. More... | |
Sections | |
ConfigSection & | createSection (const std::string &sn) |
Create a new section by name. More... | |
ConfigSection & | section (const std::string &sn) |
Get a section by name. More... | |
const ConfigSection & | section (const std::string &sn) const |
Get a section by name. More... | |
std::vector< std::string > | sections () const |
Get the list of subsections. More... | |
bool | hasSection (const std::string &n) const |
Whether the section exists. More... | |
Helper methods | |
void | replaceConstants (std::string &str) const |
Replace all occurences of ${constant_name} in the input string where "constant_name" must match a registered constant name. More... | |
Private Attributes | |
ConfigSectionMap | _sections {} |
The top level configuration sections. More... | |
ConstantsMap | _constants {} |
The constants map. More... | |
Configuration class.
Top level configuration class holding config sections and constant. It is the main object to populate when reading the configuration from config files
Definition at line 187 of file Configuration.h.
Definition at line 189 of file Configuration.h.
using marlinmt::Configuration::ConstantsMap = std::map<std::string, std::string> |
Definition at line 190 of file Configuration.h.
|
default |
|
default |
|
default |
|
default |
|
inline |
Add a constant.
The value must be convertible to/from string. Throw if already the constant already exists
cn | the constant name |
val | the constant value |
Definition at line 242 of file Configuration.h.
References marlinmt::ConfigSection::hasSection(), MARLINMT_THROW, and marlinmt::ConfigSection::section().
Referenced by marlinmt::XMLConfigReader::parseConstant().
|
inline |
Get a constant value as type T.
Throw if not found
cn | the constant name |
Definition at line 210 of file Configuration.h.
References marlinmt::details::convert< T >::from_string(), and MARLINMT_THROW.
|
inline |
Get a constant value as type T.
Return the default value if not found
cn | the constant name |
defVal | the default value |
Definition at line 226 of file Configuration.h.
References marlinmt::details::convert< T >::from_string().
const Configuration::ConstantsMap & marlinmt::Configuration::constants | ( | ) | const |
Get the constants map.
Definition at line 114 of file Configuration.cc.
Referenced by marlinmt::operator<<().
ConfigSection & marlinmt::Configuration::createSection | ( | const std::string & | sn | ) |
Create a new section by name.
Throw if already exists
sn | the new section name |
Definition at line 120 of file Configuration.cc.
References MARLINMT_THROW.
Referenced by marlinmt::Application::dumpExampleConfig(), marlinmt::XMLConfigReader::parseExecuteSection(), marlinmt::XMLConfigReader::parseProcessorParameters(), and marlinmt::XMLConfigReader::parseSection().
bool marlinmt::Configuration::hasConstant | ( | const std::string & | cn | ) | const |
Whetehr the constant is registered in the configuration.
Definition at line 108 of file Configuration.cc.
bool marlinmt::Configuration::hasSection | ( | const std::string & | n | ) | const |
Whether the section exists.
n | the section name |
Definition at line 156 of file Configuration.cc.
Referenced by marlinmt::XMLConfigReader::getReplacementParameter(), and marlinmt::XMLConfigWriter::write().
|
default |
|
default |
void marlinmt::Configuration::replaceConstants | ( | std::string & | str | ) | const |
Replace all occurences of ${constant_name} in the input string where "constant_name" must match a registered constant name.
str | the input string to modify |
Definition at line 162 of file Configuration.cc.
References MARLINMT_THROW_T.
Referenced by marlinmt::XMLConfigReader::parametersFromXMLElement(), marlinmt::XMLConfigReader::parseConstant(), marlinmt::XMLConfigReader::parseExecuteSection(), and marlinmt::XMLConfigReader::processIncludeElement().
ConfigSection & marlinmt::Configuration::section | ( | const std::string & | sn | ) |
Get a section by name.
Throw if doesn't exists
sn | the section name |
Definition at line 130 of file Configuration.cc.
References MARLINMT_THROW.
Referenced by marlinmt::concurrency::PEPScheduler::configureProcessors(), marlinmt::XMLConfigReader::getReplacementParameter(), marlinmt::SimpleScheduler::initialize(), marlinmt::BookStoreManager::initialize(), marlinmt::GeometryManager::initialize(), marlinmt::Processor::initialize(), marlinmt::operator<<(), and marlinmt::XMLConfigWriter::write().
const ConfigSection & marlinmt::Configuration::section | ( | const std::string & | sn | ) | const |
Get a section by name.
Throw if doesn't exists
sn | the section name |
Definition at line 140 of file Configuration.cc.
References MARLINMT_THROW.
std::vector< std::string > marlinmt::Configuration::sections | ( | ) | const |
Get the list of subsections.
Definition at line 150 of file Configuration.cc.
References marlinmt::details::keys().
Referenced by marlinmt::operator<<().
|
private |
The constants map.
Definition at line 315 of file Configuration.h.
|
private |
The top level configuration sections.
Definition at line 313 of file Configuration.h.