class to hold an hmbdc configuration
More...
#include <Config.hpp>
|
| 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 §ion) |
| construct using a fallback ptree, and specify the section ptree More...
|
|
void | setDefaultUserConfig (Config const &c) |
| internal use More...
|
|
ptree const & | getChildExt (const path_type ¶m) |
| Gets the child from the config. More...
|
|
template<typename T > |
T | getExt (const path_type ¶m) const |
| get a value from the config More...
|
|
template<typename T > |
T | getHex (ptree::path_type const ¶m) const |
| get a number value in hex format More...
|
|
template<typename T > |
Config const & | operator() (T &to, const path_type ¶m) 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 ¶m) 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 ¶m) 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...
|
|
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:
- chat.cpp, client-server-netmap.cpp, ping-pong-tcpcast.cpp, ping-pong-udpcast.cpp, rmcast-cp.cpp, server-cluster.cpp, and udpcast-sniff.cpp.
◆ Config() [1/5]
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
-
is | stream as input providing a json stream |
section | pointing to the effective section in the json above |
◆ Config() [2/5]
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
-
is | stream as input providing a json stream |
section | pointing 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
-
json | string as input providing a json text |
section | pointing 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
-
t | ptree as input providing fallbacks (and sections) |
section | pointing to the effective section in the ptree above |
◆ Config() [5/5]
hmbdc::app::config_detail::Config::Config |
( |
ptree const & |
t, |
|
|
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
-
t | ptree as input providing fallbacks |
section | ptree providing section specific values |
◆ content()
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
-
skipThese | skip those config params |
- Returns
- list of string pairs in the original order of ptree nodes
◆ 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] | param | config parameter name |
- Returns
- ptree reference to the child.
◆ getExt()
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
-
param | config parameter name |
- Template Parameters
-
- Returns
- result
- Examples:
- client-server-netmap.cpp.
◆ 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
-
param | config parameter name |
- Template Parameters
-
T | numeric 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 |
|
) |
| const |
|
inline |
fill in a variable with a configured value retrieved using getExt
example cfg(abc, "abc")(def, "def");
- Parameters
-
to | destination |
param | config parameter |
- 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 |
|
) |
| const |
|
inline |
fill an unordered_set with a configured value retrieved using getExt
the value in the Config is a space separated string
- Parameters
-
to | destination |
param | config parameter |
- 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 |
|
) |
| const |
|
inline |
fill an list with a configured value retrieved using getExt
the value in the Config is a json array
- Parameters
-
to | destination |
param | config parameter |
- Returns
- the Config object itself
◆ setDefaultUserConfig()
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
-
c | a config holding configuration values |
◆ operator<<
ostream& operator<< |
( |
ostream & |
os, |
|
|
Config const & |
cfg |
|
) |
| |
|
friend |
stream out the effective settings
- Parameters
-
os | ostream |
cfg | The configuration |
- Returns
- os
The documentation for this struct was generated from the following file: