hmbdc
simplify-high-performance-messaging-programming
Public Member Functions | 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 (istream &&is, char const *section=nullptr)
 construct using stream, optionally specifying the section name More...
 
 Config (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 &t, ptree const &section)
 construct using a fallback ptree, and specify the section ptree More...
 
void setDefaultUserConfig (Config const &c)
 internal use More...
 
template<typename T >
getExt (const path_type &param) const
 get a value from the config More...
 
template<typename T >
getHex (ptree::path_type const &param)
 get a number value in hex format More...
 
template<typename T >
Config const & operator() (T &to, const path_type &param) 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) 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) const
 fill an list with a configured value retrieved using getExt More...
 
list< pair< string, string > > content (unordered_set< string > const &skipThese=unordered_set< string >()) const
 get contents of all the effective configure in the form of list of string pairs 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"
     }
 }
Examples:
chat.cpp, client-server-netmap.cpp, mcast-sniff.cpp, ping-pong-mcast.cpp, ping-pong-tcpcast.cpp, rmcast-cp.cpp, and server-cluster.cpp.

Constructor & Destructor Documentation

hmbdc::app::config_detail::Config::Config ( 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
hmbdc::app::config_detail::Config::Config ( 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
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
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
hmbdc::app::config_detail::Config::Config ( ptree const &  t,
ptree const &  section 
)
inlineexplicit

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
tptree as input providing fallbacks
sectionptree providing section specific values

Member Function Documentation

list<pair<string, string> > hmbdc::app::config_detail::Config::content ( unordered_set< string > const &  skipThese = unordered_set<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
template<typename T >
T hmbdc::app::config_detail::Config::getExt ( const path_type &  param) 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. Throw exception ptree_bad_path if all fail

Parameters
paramconfig parameter name
Template Parameters
Ttype of the value
Returns
result
Examples:
client-server-netmap.cpp.
template<typename T >
T hmbdc::app::config_detail::Config::getHex ( ptree::path_type const &  param)
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
template<typename T >
Config const& hmbdc::app::config_detail::Config::operator() ( T &  to,
const path_type &  param 
) const
inline

fill in a variable with a configured value retrieved using getExt

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

Parameters
todestination
paramconfig parameter
Returns
the Config object itself
template<typename T >
Config const& hmbdc::app::config_detail::Config::operator() ( std::unordered_set< T > &  to,
const path_type &  param 
) 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
Returns
the Config object itself
template<typename T >
Config const& hmbdc::app::config_detail::Config::operator() ( std::vector< T > &  to,
const path_type &  param 
) const
inline

fill an list with a configured value retrieved using getExt

the value in the Config is a json array

Parameters
todestination
paramconfig parameter
Returns
the Config object itself
void hmbdc::app::config_detail::Config::setDefaultUserConfig ( Config const &  c)
inline

internal use

this is to set the default user config values (not the fallback values)

Parameters
ca config holding configuration values

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