MarlinMT  0.1.0
marlinmt::Configuration Class Reference

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
 
Configurationoperator= (const Configuration &)=default
 
Configurationoperator= (Configuration &&)=default
 
Constants
template<typename T >
constantAs (const std::string &cn) const
 Get a constant value as type T. More...
 
template<typename T >
constantAs (const std::string &cn, const T &defVal) const
 Get a constant value as type T. More...
 
template<typename T >
ConfigurationaddConstant (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 ConstantsMapconstants () const
 Get the constants map. More...
 
Sections
ConfigSectioncreateSection (const std::string &sn)
 Create a new section by name. More...
 
ConfigSectionsection (const std::string &sn)
 Get a section by name. More...
 
const ConfigSectionsection (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...
 

Detailed Description

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.

Member Typedef Documentation

◆ ConfigSectionMap

◆ ConstantsMap

using marlinmt::Configuration::ConstantsMap = std::map<std::string, std::string>

Definition at line 190 of file Configuration.h.

Constructor & Destructor Documentation

◆ Configuration() [1/3]

marlinmt::Configuration::Configuration ( )
default

◆ ~Configuration()

marlinmt::Configuration::~Configuration ( )
default

◆ Configuration() [2/3]

marlinmt::Configuration::Configuration ( const Configuration )
default

◆ Configuration() [3/3]

marlinmt::Configuration::Configuration ( Configuration &&  )
default

Member Function Documentation

◆ addConstant()

template<typename T >
Configuration& marlinmt::Configuration::addConstant ( const std::string &  cn,
const T &  val 
)
inline

Add a constant.

The value must be convertible to/from string. Throw if already the constant already exists

Parameters
cnthe constant name
valthe 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().

◆ constantAs() [1/2]

template<typename T >
T marlinmt::Configuration::constantAs ( const std::string &  cn) const
inline

Get a constant value as type T.

Throw if not found

Parameters
cnthe constant name

Definition at line 210 of file Configuration.h.

References marlinmt::details::convert< T >::from_string(), and MARLINMT_THROW.

◆ constantAs() [2/2]

template<typename T >
T marlinmt::Configuration::constantAs ( const std::string &  cn,
const T &  defVal 
) const
inline

Get a constant value as type T.

Return the default value if not found

Parameters
cnthe constant name
defValthe default value

Definition at line 226 of file Configuration.h.

References marlinmt::details::convert< T >::from_string().

◆ constants()

const Configuration::ConstantsMap & marlinmt::Configuration::constants ( ) const

Get the constants map.

Definition at line 114 of file Configuration.cc.

Referenced by marlinmt::operator<<().

◆ createSection()

ConfigSection & marlinmt::Configuration::createSection ( const std::string &  sn)

Create a new section by name.

Throw if already exists

Parameters
snthe 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().

◆ hasConstant()

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.

◆ hasSection()

bool marlinmt::Configuration::hasSection ( const std::string &  n) const

Whether the section exists.

Parameters
nthe section name

Definition at line 156 of file Configuration.cc.

Referenced by marlinmt::XMLConfigReader::getReplacementParameter(), and marlinmt::XMLConfigWriter::write().

◆ operator=() [1/2]

Configuration& marlinmt::Configuration::operator= ( const Configuration )
default

◆ operator=() [2/2]

Configuration& marlinmt::Configuration::operator= ( Configuration &&  )
default

◆ replaceConstants()

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.

Parameters
strthe 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().

◆ section() [1/2]

◆ section() [2/2]

const ConfigSection & marlinmt::Configuration::section ( const std::string &  sn) const

Get a section by name.

Throw if doesn't exists

Parameters
snthe section name

Definition at line 140 of file Configuration.cc.

References MARLINMT_THROW.

◆ sections()

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<<().

Member Data Documentation

◆ _constants

ConstantsMap marlinmt::Configuration::_constants {}
private

The constants map.

Definition at line 315 of file Configuration.h.

◆ _sections

ConfigSectionMap marlinmt::Configuration::_sections {}
private

The top level configuration sections.

Definition at line 313 of file Configuration.h.


The documentation for this class was generated from the following files: