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

#include <config.hpp>

Public Member Functions

 Config ()
 
virtual ~Config ()
 
const elt::configng::CiiConfigDocument & GetConfigDoc ()
 
bool ParseOptionsAndLoad (int argc, char *argv[])
 
void LoadConfig (const std::string &filename="")
 
void ConfigureLogging (const std::string &filename="")
 
void MergeConfig (const elt::configng::CiiConfigDocument &cfg_doc)
 
std::string ConvertKey (const std::string &key, const char src_separator, const char dst_separator)
 
template<typename T >
GetParam (const std::string &key, const char separator=KEY_SEPARATOR_OLDB)
 
template<typename T >
void SetParam (const std::string &key, const T &value, const char separator=KEY_SEPARATOR_OLDB)
 
template<typename T >
void AddParam (const std::string &key, const T &value, const char separator=KEY_SEPARATOR_OLDB)
 
void CreateDefaultConfig ()
 
void CreateDefaultConfig (const std::string &default_cfg)
 
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]

exciiserver::Config::Config ( )

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)

◆ ~Config()

exciiserver::Config::~Config ( )
virtual

Default destructor.

◆ Config() [2/2]

exciiserver::Config::Config ( const Config )
delete

Member Function Documentation

◆ AddParam()

template<typename T >
void exciiserver::Config::AddParam ( const std::string &  key,
const T &  value,
const char  separator = KEY_SEPARATOR_OLDB 
)

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

◆ ConfigureLogging()

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

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

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

Parameters
[in]filenameLog properties filename.

◆ ConvertKey()

std::string exciiserver::Config::ConvertKey ( const std::string &  key,
const char  src_separator,
const char  dst_separator 
)

Utility to replace separators in a key. E.g.: from CII OLDB URI '/' separator to YAML '.' or vice-versa to be able to dump the configuration to the OLDB.

Parameters
keyKey to convert using a src separator.
src_separatorSeparator used in the given key.
dst_separatorSeparator to be used in the returned key.
Returns
Converted key.

◆ CreateDefaultConfig() [1/2]

void exciiserver::Config::CreateDefaultConfig ( )

Create the initial applications configuration (CiiConfigDocument) from the stream, containing all configuration parameters initialized with default values.

◆ CreateDefaultConfig() [2/2]

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

◆ GetConfigDoc()

const elt::configng::CiiConfigDocument& exciiserver::Config::GetConfigDoc ( )
inline

◆ GetParam()

template<typename T >
T exciiserver::Config::GetParam ( const std::string &  key,
const char  separator = KEY_SEPARATOR_OLDB 
)

Return the value associated to a configuration parameter.

Parameters
keyIdentifier of the configuration parameter in OLDB format.
separatorKey separator character, e.g. '.' for CFG, '/' for OLDB.
Returns
The value of a configuration parameter.

◆ LoadConfig()

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

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.

◆ MergeConfig()

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

This method merges the given configuration (e.g. loaded from file or string) with the one stored in this class. This method could be provided by CII.

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

◆ operator=()

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

Disable copy constructor.

◆ ParseOptionsAndLoad()

bool exciiserver::Config::ParseOptionsAndLoad ( int  argc,
char *  argv[] 
)

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 option has been invoked, true otherwise.

◆ Print() [1/2]

std::string exciiserver::Config::Print ( )

Helper method to print the current application configuration.

Returns
A string containing the configuration in YAML format.

◆ Print() [2/2]

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

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

◆ PrintNode()

std::string exciiserver::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.

◆ SetParam()

template<typename T >
void exciiserver::Config::SetParam ( const std::string &  key,
const T &  value,
const char  separator = KEY_SEPARATOR_OLDB 
)

Set the value of a configuration parameter.

Parameters
keyIdentifier of the configuration parameter in OLDB format.
valueThe value of a configuration parameter.
separatorKey separator character, e.g. '.' for CFG, '/' for OLDB.

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