rad 6.2.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
rad::Config Class Reference

#include <config.hpp>

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

Public Member Functions

 Config (const std::string &name=LOGGER_NAME, const std::string &log_level="ERROR")
 
 Config (const Config &cfg)
 
virtual ~Config ()
 
Configoperator= (const Config &cfg)
 
const elt::configng::CiiConfigDocument & GetConfigDoc () const
 
bpo::options_description & GetOptionsDesc ()
 
bpo::variables_map & GetOptionsMap ()
 
const std::string & GetOldbPrefixAppenderKey ()
 
void SetOldbPrefixAppenderKey (const std::string &key)
 
std::string BuildOldbPrefix ()
 
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 CheckConfig () const
 
virtual void ValidateConfig (const std::vector< std::string > &keys, const Config &cfg) const
 
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) const
 
std::string Print (const elt::configng::CiiConfigInstanceNamespace &instances) const
 
std::string Print () const
 

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() [2/2]

rad::Config::Config ( const Config & cfg)

Copy constructor.

Makes a deep copy of the configuration including command line options from a source configuration.

Parameters
cfgSource configuration.

◆ ~Config()

rad::Config::~Config ( )
virtual

Default destructor.

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

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.

◆ BuildOldbPrefix()

std::string rad::Config::BuildOldbPrefix ( )
Returns
the OLDB prefix concatenating the configuration value associated with KEY_CONFIG_OLDB_URI_PREFIX key and the value associated with the value of m_oldb_prefix_appender_key (if not empty).

◆ CheckConfig()

void rad::Config::CheckConfig ( ) const

This method uses CII config-ng to check whether the CII configuration document complies with the schema/specification. In case of error(s) an exception is thrown and the error(s) logged. In case of warnings they are all logged.

In case of invalid parameter, an exception is/should be thrown to stop applying the configuration.

◆ 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 ( ) const
inline
Returns
the reference to the CII configuration document where all configuration parameters are stored.

◆ GetOldbPrefixAppenderKey()

const std::string & rad::Config::GetOldbPrefixAppenderKey ( )
inline
Returns
The key of the configuration parameter to be used to build the OLDB prefix.

◆ 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 & cfg)

Assignment operator.

Makes a deep copy of the configuration including command line options (with the exception of BOOST options_description which cannot be assigned) from the given source document.

Parameters
cfgSource configuration.

◆ 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 ( ) const

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) const

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 ) const

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.

◆ SetOldbPrefixAppenderKey()

void rad::Config::SetOldbPrefixAppenderKey ( const std::string & key)
inline

Sets the key identifier to be used to retrieve from the configuration part of the OLDB prefix.

Parameters
keyConfiguration key (e.g. KEY_CONFIG_MODNAME or KEY_CONFIG_PROCNAME) to be used when building the OLDB prefix path.

◆ 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.

◆ ValidateConfig()

void rad::Config::ValidateConfig ( const std::vector< std::string > & keys,
const Config & cfg ) const
virtual

This method allows an application to verify the given configuration before it is merged with the actual/main configuration. In case of invalid parameter, an exception is/should be thrown to stop applying the configuration.

The method can be specialized to verify application specific parameters.

Parameters
keysParameters to be validated.
cfgConfiguration values to be validated.

Reimplemented in MyConfig.


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