hlcc 2.0.0-beta2+pre1
Loading...
Searching...
No Matches
Public Member Functions | List of all members
hlcc::trksim::Config Class Reference

#include <config.hpp>

Inheritance diagram for hlcc::trksim::Config:

Public Member Functions

 Config ()
 
virtual ~Config ()
 
std::string PrintFormat (const elt::configng::CiiConfigInstanceNamespace &instances, const cfghelpers::SerializationFormat &format=cfghelpers::SerializationFormat::YAML)
 
std::string PrintKeys (const elt::configng::CiiConfigInstanceNode &node, const std::vector< std::string > &keys, const cfghelpers::SerializationFormat &format=cfghelpers::SerializationFormat::YAML)
 
std::vector< std::string > UpdateConfigFromKeyval (const std::string &keyval, rad::SMAdapter &sm, bool allow_partial_update)
 
std::vector< std::string > UpdateConfigFromFile (const std::string &file_name, rad::SMAdapter &sm, bool allow_partial_update)
 
std::vector< std::string > UpdateConfig (elt::configng::CiiConfigDocument &cfg_doc, rad::SMAdapter &sm, bool allow_partial_update)
 
bool SplitKeyValue (const std::string &keyval, std::string &key, std::string &value)
 
void SplitVectorStr (const std::string &vector_str, std::string &vector_name, int &vector_index) const
 
std::string GetComment (const std::string &key)
 
std::string GetUnits (const std::string &key)
 
ConfigPack GetConfigPack ()
 
template<typename T >
GetDefaultValue (const std::string &key)
 
 Config (const Config &)=delete
 
Configoperator= (const Config &)=delete
 Disable copy constructor.
 

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]

hlcc::trksim::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)

The rad-app way of building the configuration is as below using the AddParam<> template. Because in hlcc we are supporting metadata in configuration parameters we cannot build the configuration using AddParam<> because this method doesn't support metadata

Because we now support metadata for configuration parameter we build configuration directly by providing a yaml string containing the complete definition for all parameters types. Because all parameters have the 'default' metadata we take advantage of it and during the configuration instantiation below all parameters will be created with default value from 'default' metadata. Below we are replacing all the default placeholders in the definition with the defaults defined in code. This way we just need to change one place if need to modify the default values avoiding ambiguity.

◆ ~Config()

hlcc::trksim::Config::~Config ( )
virtual

Default destructor.

◆ Config() [2/2]

hlcc::trksim::Config::Config ( const Config )
delete

Member Function Documentation

◆ GetComment()

std::string hlcc::trksim::Config::GetComment ( const std::string &  key)

Return the metadata comment of the referred parameter.

Parameters
keyIdentifier of the configuration parameter in OLDB format.
Returns
The comment of a configuration parameter as a string.

◆ GetConfigPack()

ConfigPack hlcc::trksim::Config::GetConfigPack ( )

Retrieve whole configuration and build a configuration pack object

Returns
The configuration pack object.

◆ GetDefaultValue()

template<typename T >
T hlcc::trksim::Config::GetDefaultValue ( const std::string &  key)

Return the metadata default value of the referred parameter.

Parameters
keyIdentifier of the configuration parameter in OLDB format.
Returns
The default value of the configuration parameter as the instantiated type.

◆ GetUnits()

std::string hlcc::trksim::Config::GetUnits ( const std::string &  key)

Return the metadata units of the referred parameter.

Parameters
keyIdentifier of the configuration parameter in OLDB format.
Returns
The units of a configuration parameter as a string.

◆ operator=()

Config & hlcc::trksim::Config::operator= ( const Config )
delete

Disable copy constructor.

◆ PrintFormat()

std::string hlcc::trksim::Config::PrintFormat ( const elt::configng::CiiConfigInstanceNamespace &  instances,
const cfghelpers::SerializationFormat format = cfghelpers::SerializationFormat::YAML 
)

Helper method to print the whole CII configuration.

Parameters
instancesCiiConfigInstanceNamespace, configuration instance
formatSerializationFormat, serialization format for the output string
Returns
std::string, containing the configuration print result.

◆ PrintKeys()

std::string hlcc::trksim::Config::PrintKeys ( const elt::configng::CiiConfigInstanceNode &  node,
const std::vector< std::string > &  keys,
const cfghelpers::SerializationFormat format = cfghelpers::SerializationFormat::YAML 
)

Helper method to print partially the application configuration.

Parameters
instancesCiiConfigInstanceNamespace, configuration instance
keysstd::vector<std::string>, containing the configuration keys to print.
formatSerializationFormat, serialization format for the output string
Returns
std::string, containing the configuration print result.

◆ SplitKeyValue()

bool hlcc::trksim::Config::SplitKeyValue ( const std::string &  keyval,
std::string &  key,
std::string &  value 
)

Split a given key/value string (e.g. "cfg/version: 'alpha'") into key (e.g. "cfg/version") and value (e.g. "alpha").

Parameters
keyvalInput string containing the key-value using fully qualified key.
keyOutput string representing the key.
valueOutput string representing the value.
Returns
True if the key is a fully qualified, false otherwise.

◆ SplitVectorStr()

void hlcc::trksim::Config::SplitVectorStr ( const std::string &  vector_str,
std::string &  vector_name,
int &  vector_index 
) const

Split a vector identifier in name and index. For example "devices[3]" is split into the string "devices" and the index 3. TODO: lcg: There is an implementation of this method in the parent class but it is private so we added it here also so we can use it for the purpose to demonstrate the metadata usage in top of rad-app implementation of the config class. This should be deleted later and probably make the implementation in the parent class public id really needed in the end.

Parameters
vector_strInput string (e.g. "devices[3]")
vector_nameOutput name of the vector (e.g. "devices")
vector_sizeOutput index of the vector (e.g. 3) a vector.

◆ UpdateConfig()

std::vector< std::string > hlcc::trksim::Config::UpdateConfig ( elt::configng::CiiConfigDocument &  cfg_doc,
rad::SMAdapter &  sm,
bool  allow_partial_update 
)

Helper method to update configuration partially from a yaml string at runtime This method will make first an assessment of the parameters, checking if it is possible/safe to update.

Parameters
[in]cfg_docCiiConfigDocument, with the configuration to update
[in]smReference to the SM Adapter used to inject internal events.
[in]allow_partial_update,iftrue it will update the parameter that are allowed if false it will only update if all are allowed
Returns
list_updated_keys strings vector, with all the updated config keys
Exceptions
ConfigError,ifnot possible to update the configuration.

◆ UpdateConfigFromFile()

std::vector< std::string > hlcc::trksim::Config::UpdateConfigFromFile ( const std::string &  file_name,
rad::SMAdapter &  sm,
bool  allow_partial_update 
)

Helper method to update configuration partially from a yaml config file This method will make first an assessment of the parameters, checking if it is possible/safe to update.

Parameters
[in]file_namestring, containing the config yaml file path
[in]smReference to the SM Adapter used to inject internal events.
[in]allow_partial_update,iftrue it will update the parameter that are allowed if false it will only update if all are allowed
Returns
list_updated_keys strings vector, with all the updated config keys
Exceptions
ConfigError,ifnot possible to load the string ans config document

◆ UpdateConfigFromKeyval()

std::vector< std::string > hlcc::trksim::Config::UpdateConfigFromKeyval ( const std::string &  keyval,
rad::SMAdapter &  sm,
bool  allow_partial_update 
)

Helper method to update configuration partially from a yaml string containing key-value at runtime. This method will make first an assessment of the parameters, one by one, checking if it is possible/safe to update. The string format must be Yaml compliant, check the example: '"cfg.rous.timer_period_s: 123\n cfg.ready_for_handover.estimation_period_ms: 456"' The separation between config parameters must be 'newline' character followed by 2 spaces.

Parameters
[in]keyvalstring, containing the yaml with parameters to be updated
[in]smReference to the SM Adapter used to inject internal events.
[in]allow_partial_update,iftrue it will update the parameter that are allowed if false it will only update if all are allowed
Returns
list_updated_keys strings vector, with all the updated config keys
Exceptions
ConfigError,ifnot possible to load the string ans config document

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