hmbdc
simplify-high-performance-messaging-programming
Public Member Functions | Friends | List of all members
hmbdc::app::config_detail::Config Struct Reference

class to hold an hmbdc configuration More...

#include <Config.hpp>

Inheritance diagram for hmbdc::app::config_detail::Config:

Public Member Functions

 Config ()
 empty config
 
 Config (Config const &other)
 copt ctor
 
Configoperator= (Config const &other)
 assignment
 
 Config (std::istream &&is, char const *section=nullptr)
 construct using stream, optionally specifying the section name More...
 
 Config (std::istream &is, char const *section=nullptr)
 construct using stream, optionally specifying the section name More...
 
 Config (char const *json, char const *section=nullptr)
 construct using a string, optionally specifying the section name More...
 
 Config (ptree const &t, char const *section=nullptr)
 construct using another ptree as fallbacks, optionally specifying the section name More...
 
 Config (ptree const &dft, ptree const &section)
 construct using a fallback ptree, and specify the section ptree More...
 
void setAdditionalFallbackConfig (Config const &c)
 set additional defaults More...
 
void setDefaultUserConfig (Config const &c)
 depracated
 
ConfigresetSection (char const *section, bool sectionExists=true)
 change section name More...
 
template<typename ... Args>
Configput (Args &&... args)
 forward the call to ptree's put but return Configure More...
 
ptree const & getChildExt (const path_type &param)
 Gets the child from the config. More...
 
template<typename T >
getExt (const path_type &param, bool throwIfMissing=true) const
 get a value from the config More...
 
template<typename T >
std::vector< T > getArray (const path_type &param) const
 get a vector of value from the json array More...
 
template<typename T >
getHex (ptree::path_type const &param) const
 get a number value in hex format More...
 
template<typename T >
Config const & operator() (T &to, const path_type &param, bool throwIfMissing=true) const
 fill in a variable with a configured value retrieved using getExt More...
 
template<typename T >
Config const & operator() (std::unordered_set< T > &to, const path_type &param, bool throwIfMissing=true) const
 fill an unordered_set with a configured value retrieved using getExt More...
 
template<typename T >
Config const & operator() (std::vector< T > &to, const path_type &param, bool throwIfMissing=true) const
 fill an list with a configured value retrieved using getExt More...
 
std::list< std::pair< std::string, std::string > > content (std::unordered_set< std::string > const &skipThese=std::unordered_set< std::string >()) const
 get contents of all the effective configure in the form of list of string pairs More...
 

Friends

std::ostream & operator<< (std::ostream &os, Config const &cfg)
 stream out the effective settings More...
 

Detailed Description

class to hold an hmbdc configuration

it is based on a two level (fallback and section) json. top level for the fallback values and lower level for the section specific values. a Config instance is always constructed to be associated to 0 or 1 specific section. shown below:

 {
     "parameter_1": "top level, value used as a fallback",
     "parameter_2": "fallback is used when not configured in a section",
     "section_A": {
          "parameter_2": "lower level, a specific value effective in section_A",
          "parameter_1": "a specific value effective in section_A"
     },
     "another_section": {
          "parameter_2": "a specific value effective in another_section"
     }
 }

json array is not supported !!!

Examples:
hello-world.cpp.

Constructor & Destructor Documentation

◆ Config() [1/5]

hmbdc::app::config_detail::Config::Config ( std::istream &&  is,
char const *  section = nullptr 
)
inlineexplicit

construct using stream, optionally specifying the section name

if the section is nullptr, just use the fallback values. if the section name cannot be found, throw an exception

Parameters
isstream as input providing a json stream
sectionpointing to the effective section in the json above

◆ Config() [2/5]

hmbdc::app::config_detail::Config::Config ( std::istream &  is,
char const *  section = nullptr 
)
inlineexplicit

construct using stream, optionally specifying the section name

if the section is nullptr, just use the fallback values. if the section name cannot be found, throw an exception

Parameters
isstream as input providing a json stream
sectionpointing to the effective section in the json above

◆ Config() [3/5]

hmbdc::app::config_detail::Config::Config ( char const *  json,
char const *  section = nullptr 
)
inlineexplicit

construct using a string, optionally specifying the section name

if the section is nullptr, just use the fallback values. if the section name cannot be found, throw an exception

Parameters
jsonstring as input providing a json text
sectionpointing to the effective section in the json above

◆ Config() [4/5]

hmbdc::app::config_detail::Config::Config ( ptree const &  t,
char const *  section = nullptr 
)
inline

construct using another ptree as fallbacks, optionally specifying the section name

if the section is nullptr, just use the fallback values. if the section name cannot be found, throw an exception

Parameters
tptree as input providing fallbacks (and sections)
sectionpointing to the effective section in the ptree above

◆ Config() [5/5]

hmbdc::app::config_detail::Config::Config ( ptree const &  dft,
ptree const &  section 
)
inline

construct using a fallback ptree, and specify the section ptree

if the section is nullptr, just use the fallback values. if the section name cannot be found, throw an exception

Parameters
dftptree as input providing fallbacks
sectionptree providing section specific values

Member Function Documentation

◆ content()

std::list<std::pair<std::string, std::string> > hmbdc::app::config_detail::Config::content ( std::unordered_set< std::string > const &  skipThese = std::unordered_set<std::string>()) const
inline

get contents of all the effective configure in the form of list of string pairs

only effective ones are shown

Parameters
skipTheseskip those config params
Returns
list of string pairs in the original order of ptree nodes

◆ getArray()

template<typename T >
std::vector<T> hmbdc::app::config_detail::Config::getArray ( const path_type &  param) const
inline

get a vector of value from the json array

check the section for it, if not found, try use fallback provided if still missing, search using the default user config values set by setDefaultUserConfig.

Parameters
paramconfig parameter name
throwIfMissing- true if no config found, throw an exception; otherwise return empty
Template Parameters
Ttype of the value
Returns
result

◆ getChildExt()

ptree const& hmbdc::app::config_detail::Config::getChildExt ( const path_type &  param)
inline

Gets the child from the config.

check the section for it, if not found, try use fallback provided if still missing, search using the default user config values set by setDefaultUserConfig. Throw exception ptree_bad_path if all fail

Parameters
[in]paramconfig parameter name
Returns
ptree reference to the child.

◆ getExt()

template<typename T >
T hmbdc::app::config_detail::Config::getExt ( const path_type &  param,
bool  throwIfMissing = true 
) const
inline

get a value from the config

check the section for it, if not found, try use fallback provided if still missing, search using the default user config values set by setDefaultUserConfig. If throwIfMissing, throw exception ptree_bad_path if all fail

Parameters
paramconfig parameter name
throwIfMissing- true if no config found, throw an exception; otherwise return empty
Template Parameters
Ttype of the value
Returns
result

◆ getHex()

template<typename T >
T hmbdc::app::config_detail::Config::getHex ( ptree::path_type const &  param) const
inline

get a number value in hex format

check the section for it, if not found, try use fallback provided if still missing, search using the default user config values set by setDefaultUserConfig. Throw exception ptree_bad_path if all fail

Parameters
paramconfig parameter name
Template Parameters
Tnumeric type of the value: int , uint64_t ...
Returns
result

◆ operator()() [1/3]

template<typename T >
Config const& hmbdc::app::config_detail::Config::operator() ( T &  to,
const path_type &  param,
bool  throwIfMissing = true 
) const
inline

fill in a variable with a configured value retrieved using getExt

example cfg(abc, "abc")(def, "def");

Parameters
todestination
paramconfig parameter
throwIfMissing- true if no config found, throw an exception
Returns
the Config object itself

◆ operator()() [2/3]

template<typename T >
Config const& hmbdc::app::config_detail::Config::operator() ( std::unordered_set< T > &  to,
const path_type &  param,
bool  throwIfMissing = true 
) const
inline

fill an unordered_set with a configured value retrieved using getExt

the value in the Config is a space separated string

Parameters
todestination
paramconfig parameter
throwIfMissing- true if no config found, throw an exception; otherwise ignored
Returns
the Config object itself

◆ operator()() [3/3]

template<typename T >
Config const& hmbdc::app::config_detail::Config::operator() ( std::vector< T > &  to,
const path_type &  param,
bool  throwIfMissing = true 
) const
inline

fill an list with a configured value retrieved using getExt

the value in the Config is a space separated string

Parameters
todestination
paramconfig parameter
throwIfMissing- true if no config found, throw an exception; otherwise ignored
Returns
the Config object itself

◆ put()

template<typename ... Args>
Config& hmbdc::app::config_detail::Config::put ( Args &&...  args)
inline

forward the call to ptree's put but return Configure

Template Parameters
Argswhatever ptree put expect
Parameters
argswhatever ptree put expect
Returns
object itself
Examples:
hello-world.cpp.

◆ resetSection()

Config& hmbdc::app::config_detail::Config::resetSection ( char const *  section,
bool  sectionExists = true 
)
inline

change section name

the fallbacks also changes accordingly if possible

Parameters
sectionnew section name
sectionExistscheck if the section exist in current config
  • exlcuding fallbacks if set to true
Returns
object itself

◆ setAdditionalFallbackConfig()

void hmbdc::app::config_detail::Config::setAdditionalFallbackConfig ( Config const &  c)
inline

set additional defaults

previously set defaults take precedence

Parameters
ca config holding configuration values

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
Config const &  cfg 
)
friend

stream out the effective settings

Parameters
osostream
cfgThe configuration
Returns
os

The documentation for this struct was generated from the following file: