rad  5.1.0
Public Member Functions | List of all members
rad::Config Class Reference

#include <config.hpp>

Inheritance diagram for rad::Config:
exciiserver::Config rad::utest::Config

Public Member Functions

 Config (const std::string &name=LOGGER_NAME, const std::string &log_level="ERROR")
 
virtual ~Config ()
 
const elt::configng::CiiConfigDocument & GetConfigDoc ()
 
bpo::options_description & GetOptionsDesc ()
 
bpo::variables_map & GetOptionsMap ()
 
virtual bool ParseOptions (int argc, char *argv[])
 
virtual void LoadConfig (const std::string &filename="")
 
virtual void ConfigureLogging (const std::string &filename="")
 
virtual void ApplyCmdLineOptions ()
 
void MergeConfig (const elt::configng::CiiConfigDocument &cfg_doc)
 
void CreateDefaultConfig (const std::string &default_cfg)
 
template<typename T >
void AddParam (const std::string &key, const T &value)
 
bool HasParam (const std::string &key) const
 
template<typename T >
GetParam (const std::string &key) const
 
template<typename T >
void SetParam (const std::string &key, const T &value)
 
const std::string GetConfigAsString () const
 
std::vector< std::string > SetConfigAsString (const std::string &config)
 
std::string PrintNode (const elt::configng::CiiConfigInstanceNode &node, const std::string &indentation)
 
std::string Print (const elt::configng::CiiConfigInstanceNamespace &instances)
 
std::string Print ()
 
 Config (const Config &)=delete
 
Configoperator= (const Config &)=delete
 Disable copy constructor. More...
 

Detailed Description

This class provide access to the command line options and the configuration parameters stored in the configuration file.

Constructor & Destructor Documentation

◆ Config() [1/2]

rad::Config::Config ( const std::string &  name = LOGGER_NAME,
const std::string &  log_level = "ERROR" 
)
explicit

Default constructor.

Initialize application configuration attributes by

  • first use the default constant values defined in the header
  • override the constant values with environment variables (if defined)
Parameters
nameModule name used for the default log filename and default logger name.
log_levelstartup log level for the root logger.

◆ ~Config()

rad::Config::~Config ( )
virtual

Default destructor.

Reimplemented in rad::utest::Config, and exciiserver::Config.

◆ Config() [2/2]

rad::Config::Config ( const Config )
delete

Member Function Documentation

◆ AddParam()

template<typename T >
void rad::Config::AddParam ( const std::string &  key,
const T &  value 
)

Add a configuration parameter to the stream which will be used to create the initial CiiConfigDocument.

Parameters
keyFully qualified key (e.g. 'cfg.version').
valueValue associated to the key.

◆ ApplyCmdLineOptions()

void rad::Config::ApplyCmdLineOptions ( )
virtual

This method override the configuration loaded from file by re-applying the command line options.

◆ ConfigureLogging()

void rad::Config::ConfigureLogging ( const std::string &  filename = "")
virtual

This method load from a log.properties file the logging configuration and it applies it.

If no filename is passed, it uses the one defined in the application configuration file.

Parameters
[in]filenameLog properties filename.

◆ CreateDefaultConfig()

void rad::Config::CreateDefaultConfig ( const std::string &  default_cfg)

Create the initial applications configuration (CiiConfigDocument) from a given string.

Parameters
default_cfgConfiguration following YAML syntax.

◆ GetConfigAsString()

const std::string rad::Config::GetConfigAsString ( ) const

This method returns the current configuration in a string.

Returns
A textual representation of the current configuration.

◆ GetConfigDoc()

const elt::configng::CiiConfigDocument& rad::Config::GetConfigDoc ( )
inline
Returns
the reference to the CII configuration document where all configuration parameters are stored.

◆ GetOptionsDesc()

bpo::options_description& rad::Config::GetOptionsDesc ( )
inline
Returns
The description/definition of the command line options.

◆ GetOptionsMap()

bpo::variables_map& rad::Config::GetOptionsMap ( )
inline
Returns
The map of the command line options/values.

◆ GetParam()

template<typename T >
T rad::Config::GetParam ( const std::string &  key) const

Return the value associated to a configuration parameter.

Parameters
keyIdentifier of the configuration parameter in OLDB format.
Returns
The value of a configuration parameter.

◆ HasParam()

bool rad::Config::HasParam ( const std::string &  key) const

Check whether a given parameter is part of the configuration.

Parameters
keyKey to convert using a src separator.
Returns
True if key is part of the configuration, False otherwise.

◆ LoadConfig()

void rad::Config::LoadConfig ( const std::string &  filename = "")
virtual

This method load from a configuration file the application configuration overriding the initialization done in the constructor and the command line options.

Parameters
[in]filenameApplication configuration filename. If empty, it reloads the last or default one.

◆ MergeConfig()

void rad::Config::MergeConfig ( const elt::configng::CiiConfigDocument &  cfg_doc)

This method merges the given configuration (loaded from file or string) with the main one stored in this class. TODO: This method could/should be provided by CII.

Parameters
[in]config_nodeConfiguration to merge into the current one.

◆ operator=()

Config& rad::Config::operator= ( const Config )
delete

Disable copy constructor.

◆ ParseOptions()

bool rad::Config::ParseOptions ( int  argc,
char *  argv[] 
)
virtual

This method parses the command line parameters overriding the initialization done in the constructor.

Parameters
[in]argcNumber of command line options.
[in]argvPointer to the array of command line options.
Returns
false if the help or version options have been invoked, true otherwise.

◆ Print() [1/2]

std::string rad::Config::Print ( )

Helper method to print the current application configuration.

Returns
A string containing the configuration in YAML format.

◆ Print() [2/2]

std::string rad::Config::Print ( const elt::configng::CiiConfigInstanceNamespace &  instances)

Helper method to print a CII configuration instance. TODO this should be provided by CII via << operator.

Parameters
instanceReference to the CII Config instance contained by the document.
Returns
A string containing the configuration in YAML format.

◆ PrintNode()

std::string rad::Config::PrintNode ( const elt::configng::CiiConfigInstanceNode &  node,
const std::string &  indentation 
)

Helper method to print a CII configuration node. TODO this should be provided by CII via << operator.

◆ SetConfigAsString()

std::vector< std::string > rad::Config::SetConfigAsString ( const std::string &  config)

This method merges the given configuration with the one currently stored in the Config object. If the configuration is given as a 'key: value'

Note that for the merging to succeed the given configuration must be conistent in terms of data types with one stored.

Parameters
configConfiguration to be applied in textual YAML format.
Returns
A vector of keys corresponding to the given configuration parameters.

◆ SetParam()

template<typename T >
void rad::Config::SetParam ( const std::string &  key,
const T &  value 
)

Set the value of a configuration parameter.

Parameters
keyIdentifier of the configuration parameter in OLDB format.
valueThe value of a configuration parameter.

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