23#include "flow/error/error.hpp"
25#include <boost/algorithm/string.hpp>
26#include <boost/unordered_set.hpp>
54 S_FILL_PARSING_ROLE_OPT_TABLE,
62 S_FILL_OUTPUT_HELP_ROLE_OPT_TABLE,
71 S_FILL_OUTPUT_CURRENT_ROLE_OPT_TABLE,
80 S_COMPARE_PARSED_VALS,
90 S_LOAD_VALS_AS_IF_PARSED,
100 S_VALIDATE_STORED_VALS
129 template<
typename Value>
131 const Value& value_default,
const Value& current_value,
155 template<
typename Value>
157 Function<
bool (
const Value& val)>&& validator_func_moved,
235 template<
typename Value>
238 Function<
bool (
const Value& val)>&& validator_func_moved,
417template<
typename Value_set>
421 private boost::noncopyable
710 bool* success_or_null =
nullptr);
821 bool* success_or_null =
nullptr,
822 const boost::unordered_set<std::string>& allowed_unregistered_opts_or_empty = {});
938 template<
typename Value>
940 Function<
bool (
const Value& val)>&& validator_func_moved,
962 template<
typename Value>
981 template<
typename Value>
1005 template<
typename Value>
1034 const boost::unordered_set<std::string>&
option_names()
const;
1172#define FLOW_CFG_OPTION_SET_DECLARE_OPTION(ARG_m_value, ARG_description, ARG_bool_validate_expr) \
1173 FLOW_CFG_OPTION_SET_DECLARE_OPTION_WITH_KNOBS(ARG_m_value, ARG_description, ARG_bool_validate_expr, false)
1193#define FLOW_CFG_OPTION_SET_DECLARE_OPTION_NO_ACC(ARG_m_value, ARG_description, ARG_bool_validate_expr) \
1194 FLOW_CFG_OPTION_SET_DECLARE_OPTION_WITH_KNOBS(ARG_m_value, ARG_description, ARG_bool_validate_expr, true)
1292#define FLOW_CFG_OPTION_SET_DECLARE_OPTION_KEYED(ARG_m_value, ARG_description, ARG_bool_validate_expr, ARG_key) \
1293 FLOW_UTIL_SEMICOLON_SAFE \
1295 const ::std::string FLOW_CFG_SET_DECL_OPT_KEYED_name \
1296 = ::flow::cfg::value_set_member_id_to_opt_name_keyed(#ARG_m_value, ARG_key); \
1297 FLOW_CFG_OPTION_SET_DECLARE_OPTION_MANUALLY_NAMED \
1298 (ARG_m_value, FLOW_CFG_SET_DECL_OPT_KEYED_name.c_str(), ARG_description, ARG_bool_validate_expr, false); \
1316#define FLOW_CFG_OPTION_SET_DECLARE_OPTION_KEYED_NO_ACC(ARG_m_value, ARG_description, ARG_bool_validate_expr, ARG_key) \
1317 FLOW_UTIL_SEMICOLON_SAFE \
1319 const ::std::string FLOW_CFG_SET_DECL_OPT_KEYED_name \
1320 = ::flow::cfg::value_set_member_id_to_opt_name_keyed(#ARG_m_value, ARG_key); \
1321 FLOW_CFG_OPTION_SET_DECLARE_OPTION_MANUALLY_NAMED \
1322 (ARG_m_value, FLOW_CFG_SET_DECL_OPT_KEYED_name.c_str(), ARG_description, ARG_bool_validate_expr, true); \
1345#define FLOW_CFG_OPTION_SET_DECLARE_OPTION_WITH_KNOBS(ARG_m_value, ARG_description, ARG_bool_validate_expr, \
1346 ARG_no_accumulation) \
1347 FLOW_UTIL_SEMICOLON_SAFE \
1349 const ::std::string FLOW_CFG_SET_DECL_OPT_name = ::flow::cfg::value_set_member_id_to_opt_name(#ARG_m_value); \
1350 FLOW_CFG_OPTION_SET_DECLARE_OPTION_MANUALLY_NAMED \
1351 (ARG_m_value, FLOW_CFG_SET_DECL_OPT_name.c_str(), ARG_description, ARG_bool_validate_expr, \
1352 ARG_no_accumulation); \
1384#define FLOW_CFG_OPTION_SET_DECLARE_OPTION_MANUALLY_NAMED(ARG_m_value, ARG_opt_name_c_str, \
1385 ARG_description, ARG_bool_validate_expr, \
1386 ARG_no_accumulation) \
1387 FLOW_UTIL_SEMICOLON_SAFE \
1389 char const * const FLOW_CFG_SET_DECL_OPT_MANUAL_name_c_str = ARG_opt_name_c_str; \
1391 const ::flow::util::String_view FLOW_CFG_SET_DECL_OPT_MANUAL_name_view{FLOW_CFG_SET_DECL_OPT_MANUAL_name_c_str}; \
1392 const bool FLOW_CFG_SET_DECL_OPT_MANUAL_no_acc = ARG_no_accumulation; \
1393 switch (args.m_call_type) \
1395 case ::flow::cfg::Option_set_base::Declare_options_func_call_type::S_FILL_PARSING_ROLE_OPT_TABLE: \
1397 using Value = decltype(args.m_args.m_fill_parsing_role_opt_table_args.m_values_candidate->ARG_m_value); \
1400 flow::Function<bool (const Value&)> FLOW_CFG_SET_DECL_OPT_MANUAL_validator_func \
1401 = [FLOW_CFG_SET_DECL_OPT_MANUAL_name_std_str = std::string{FLOW_CFG_SET_DECL_OPT_MANUAL_name_c_str}] \
1402 ([[maybe_unused]] const Value& val) -> bool { return ARG_bool_validate_expr; }; \
1403 args.m_args.m_fill_parsing_role_opt_table_args.m_option_set \
1404 ->declare_option_for_parsing \
1405 (FLOW_CFG_SET_DECL_OPT_MANUAL_name_view, \
1406 &args.m_args.m_fill_parsing_role_opt_table_args.m_values_candidate->ARG_m_value, \
1412 FLOW_CFG_SET_DECL_OPT_MANUAL_no_acc \
1413 ? &args.m_args.m_fill_parsing_role_opt_table_args.m_values_default_no_acc->ARG_m_value \
1415 ::std::move(FLOW_CFG_SET_DECL_OPT_MANUAL_validator_func), \
1416 ::flow::util::String_view{#ARG_bool_validate_expr}); \
1419 case ::flow::cfg::Option_set_base::Declare_options_func_call_type::S_FILL_OUTPUT_HELP_ROLE_OPT_TABLE: \
1420 args.m_args.m_fill_output_help_role_opt_table_args.m_option_set \
1421 ->declare_option_for_help \
1422 (FLOW_CFG_SET_DECL_OPT_MANUAL_name_view, \
1423 args.m_args.m_fill_output_help_role_opt_table_args.m_values_default->ARG_m_value, \
1426 case ::flow::cfg::Option_set_base::Declare_options_func_call_type::S_FILL_OUTPUT_CURRENT_ROLE_OPT_TABLE: \
1427 ::flow::cfg::Option_set_base::declare_option_for_output \
1428 (FLOW_CFG_SET_DECL_OPT_MANUAL_name_view, \
1429 args.m_args.m_fill_output_current_role_opt_table_args.m_target_opts, \
1430 args.m_args.m_fill_output_current_role_opt_table_args.m_values_default->ARG_m_value, \
1431 args.m_args.m_fill_output_current_role_opt_table_args.m_values_current->ARG_m_value, \
1434 case ::flow::cfg::Option_set_base::Declare_options_func_call_type::S_COMPARE_PARSED_VALS: \
1435 args.m_args.m_compare_parsed_vals_args.m_option_set \
1436 ->scan_parsed_option \
1437 (FLOW_CFG_SET_DECL_OPT_MANUAL_name_view, \
1438 args.m_args.m_compare_parsed_vals_args.m_option_set->values().ARG_m_value); \
1440 case ::flow::cfg::Option_set_base::Declare_options_func_call_type::S_LOAD_VALS_AS_IF_PARSED: \
1441 args.m_args.m_load_val_as_if_parsed_args.m_option_set \
1442 ->load_option_value_as_if_parsed \
1443 (FLOW_CFG_SET_DECL_OPT_MANUAL_name_view, \
1444 &args.m_args.m_load_val_as_if_parsed_args.m_values_candidate->ARG_m_value, \
1445 args.m_args.m_load_val_as_if_parsed_args.m_values_to_load->ARG_m_value); \
1447 case ::flow::cfg::Option_set_base::Declare_options_func_call_type::S_VALIDATE_STORED_VALS: \
1450 using Value = decltype(args.m_args.m_validate_stored_vals_args.m_values_to_validate->ARG_m_value); \
1451 flow::Function<bool (const Value&)> FLOW_CFG_SET_DECL_OPT_MANUAL_validator_func \
1452 = [FLOW_CFG_SET_DECL_OPT_MANUAL_name_std_str = std::string{FLOW_CFG_SET_DECL_OPT_MANUAL_name_c_str}] \
1453 ([[maybe_unused]] const Value& val) -> bool { return ARG_bool_validate_expr; }; \
1455 ::flow::cfg::Option_set_base::validate_parsed_option \
1456 (FLOW_CFG_SET_DECL_OPT_MANUAL_name_view, \
1457 args.m_args.m_validate_stored_vals_args.m_values_to_validate->ARG_m_value, \
1458 ::std::move(FLOW_CFG_SET_DECL_OPT_MANUAL_validator_func), \
1459 ::flow::util::String_view{#ARG_bool_validate_expr}); \
1468template<
typename Value_set>
1472 m_nickname(nickname),
1474 m_declare_opts_func(std::move(declare_opts_func_moved)),
1478 FLOW_LOG_TRACE(
"Option_set[" << *
this <<
"]: Created with default values payload. Options table setup begins.");
1495 FLOW_LOG_TRACE(
"Option_set[" << *
this <<
"]: Options table setup finished. Null set? = [" <<
null() <<
"].");
1498template<
typename Value_set>
1504template<
typename Value_set>
1510template<
typename Value_set>
1516template<
typename Value_set>
1519 return m_parsing ? &m_values_candidate :
nullptr;
1522template<
typename Value_set>
1531 constexpr unsigned int LINE_LENGTH = 1000;
1532 constexpr unsigned int DESC_LENGTH = LINE_LENGTH - 2;
1534 Opt_table opts_for_output{LINE_LENGTH, DESC_LENGTH};
1537 args.
m_call_type = Declare_options_func_args::Call_type::S_FILL_OUTPUT_CURRENT_ROLE_OPT_TABLE;
1539 = { &opts_for_output, &m_values_default,
1540 values_or_null ? values_or_null : &m_values };
1541 m_declare_opts_func(args);
1543 os << opts_for_output;
1546template<
typename Value_set>
1553 values_to_ostream(os.os(), values_or_null);
1555 FLOW_LOG_WITH_CHECKING(sev,
"Option_set[" << *
this <<
"]: Values payload [" << summary <<
"]:\n" << os.str());
1558template<
typename Value_set>
1561 os << m_opts_for_help;
1564template<
typename Value_set>
1571 help_to_ostream(os.os());
1576template<
typename Value_set>
1582template<
typename Value_set>
1583template<
typename Value>
1585 Value* target_value,
const Value* value_default_if_no_acc,
1586 Function<
bool (
const Value& val)>&& validator_func_moved,
1594 assert(target_value);
1595 string name(name_view);
1597 m_opt_names.insert(name);
1600 FLOW_LOG_TRACE(
"Option_set[" << *
this <<
"]: Options table of parsing-role: "
1601 "Declaring parsing-capable option [" << name <<
"]; raw shallow size [" <<
sizeof(Value) <<
"].");
1606 const auto val_spec = value<Value>(target_value)
1607 ->notifier(throw_on_invalid_func(name_view, std::move(validator_func_moved),
1608 validator_cond_str_view));
1613 if (value_default_if_no_acc)
1616 String_ostream default_str_os;
1618 default_str_os.os() << flush;
1620 val_spec->default_value(*value_default_if_no_acc, default_str_os.str());
1623 m_opts_for_parsing.add_options()(name.c_str(), val_spec);
1628template<
typename Value>
1631 Function<
bool (
const Value& val)>&& validator_func_moved,
1639 return [validator_func = std::move(validator_func_moved),
1640 validator_cond_str =
string{validator_cond_str_view},
1641 name =
string{name_view}]
1644 if (!(validator_func(val)))
1646 String_ostream msg_os;
1647 msg_os.
os() <<
"Option [" << name <<
"]: "
1648 "Validation failed; the following condition must hold: [" << validator_cond_str <<
"]. "
1649 "Option value `val` = [";
1651 msg_os.os() <<
"]." << flush;
1652 throw Runtime_error{msg_os.str()};
1657template<
typename Value_set>
1658template<
typename Value>
1667 assert(!description.empty());
1673 String_ostream default_str_os;
1675 default_str_os.os() << flush;
1677 m_opts_for_help.add_options()
1678 (
string{name}.c_str(),
1681 ->default_value(value_default, default_str_os.str()),
1682 string{description}.c_str());
1687template<
typename Value>
1689 const Value& value_default,
const Value& current_value,
1697 assert(!description.empty());
1706 String_ostream description_os;
1710 description_os.os() <<
" (";
1714 description_os.os() <<
") <==current | default==^\n"
1715 " " << description << flush;
1718 String_ostream default_str_os;
1720 default_str_os.os() << flush;
1722 target_opts->add_options()
1723 (
string{name}.c_str(),
1726 ->default_value(value_default, default_str_os.str()),
1727 description_os.str().c_str());
1732template<
typename Value_set>
1733template<
typename Value>
1736 using boost::any_cast;
1738 string name{name_view};
1746 const auto it = m_iterable_values_candidate.find(name);
1747 if (it == m_iterable_values_candidate.end())
1753 const auto& new_val = any_cast<const Value&>(it->second);
1754 const auto& old_val = canonical_value;
1756 if (old_val == new_val)
1758 m_iterable_values_candidate.erase(name);
1763template<
typename Value_set>
1764template<
typename Value>
1766 Value* target_value,
1767 const Value& source_value)
1770 string name{name_view};
1772 assert(target_value);
1780 *target_value = source_value;
1783 m_iterable_values_candidate[name] = source_value;
1791template<
typename Value>
1793 Function<
bool (
const Value& val)>&& validator_func_moved,
1796 const auto validate_or_throw_func =
throw_on_invalid_func(name_view, std::move(validator_func_moved),
1797 validator_cond_str_view);
1798 validate_or_throw_func(value);
1801template<
typename Value_set>
1803 (
const fs::path& cfg_path,
bool allow_unregistered,
bool* success_or_null,
1804 const boost::unordered_set<std::string>& allowed_unregistered_opts_or_empty)
1811 using opts::variables_map;
1812 using boost::system::system_category;
1814 using std::exception;
1818 if (success_or_null)
1822 parse_config_file(cfg_path, allow_unregistered,
nullptr, allowed_unregistered_opts_or_empty);
1824 catch (
const exception& exc)
1827 *success_or_null =
false;
1830 *success_or_null =
true;
1838 FLOW_LOG_INFO(
"Option_set[" << *
this <<
"]: State CANONICAL: Request to parse file [" << cfg_path <<
"]; "
1839 "entering state PARSING. Initial candidate values payload initialized from current canonical "
1840 "values payload. Details follow (TRACE log level).");
1842 assert(m_iterable_values_candidate.empty());
1846 FLOW_LOG_INFO(
"Option_set[" << *
this <<
"]: State PARSING: Request to parse file [" << cfg_path <<
"]; "
1847 "continuing by parsing this next config source. "
1848 "The values payload going into it is as it was after the previous config source. "
1849 "Details follow (TRACE log level).");
1852 log_values(
"pre-parsing candidate config", &m_values_candidate,
log::Sev::S_TRACE);
1854 ifstream ifs{cfg_path};
1857 const Error_code sys_err_code{errno, system_category()};
1860 throw Runtime_error{sys_err_code,
ostream_op_string(
"Could not open file [", cfg_path,
"].")};
1870 const auto values_candidate_backup = m_values_candidate;
1871 opts::parsed_options parsed_options{&m_opts_for_parsing};
1874 parsed_options = opts::parse_config_file(ifs, m_opts_for_parsing, allow_unregistered);
1876 catch (
const exception& exc)
1878 m_values_candidate = values_candidate_backup;
1882 "Parsing file [" << cfg_path <<
"]: Exception occurred; parse failed. Values payload untouched. "
1883 "Message = [" << exc.what() <<
"].");
1891 if (allow_unregistered)
1893 for (
const auto& option : parsed_options.options)
1895 if (option.unregistered)
1897 assert(!option.original_tokens.empty());
1898 const string opt_name = option.original_tokens.front();
1900 if (allowed_unregistered_opts_or_empty.empty())
1903 FLOW_LOG_TRACE(
"Option_set[" << *
this <<
"]: State PARSING: Ignoring unregistered option named "
1904 "[" << opt_name <<
"]. We were not given an approved-list. Perhaps this file contains "
1905 "other option sets, or it has to do with forward/backward-compatibility.");
1909 if (!
key_exists(allowed_unregistered_opts_or_empty, opt_name))
1912 m_values_candidate = values_candidate_backup;
1914 FLOW_LOG_WARNING(
"Option_set[" << *
this <<
"]: State PARSING: Unregistered option named "
1915 "[" << opt_name <<
"] is not approved; parse failed. Values payload untouched.");
1917 "] is not approved; parse failed.")};
1922 FLOW_LOG_TRACE(
"Option_set[" << *
this <<
"]: State PARSING: Ignoring unregistered option named "
1923 "[" << opt_name <<
"]; it is in the approved-list. Perhaps this file contains "
1924 "other option sets.");
1934 FLOW_LOG_TRACE(
"Option_set[" << *
this <<
"]: State PARSING: Parsed general format successfully. "
1935 "Will now parse each option's value.");
1945 variables_map fresh_iterable_values;
1948 store(parsed_options, fresh_iterable_values);
1950 catch (
const exception& exc)
1953 m_values_candidate = values_candidate_backup;
1956 "Parsed file [" << cfg_path <<
"]: Exception occurred; individual option parsing failed. "
1957 "Values payload untouched. Message = [" << exc.what() <<
"].");
1961 FLOW_LOG_TRACE(
"Option_set[" << *
this <<
"]: State PARSING: Parsed each individual option successfully. "
1962 "Will now further validate each option value logically and store on success.");
1968 notify(fresh_iterable_values);
1970 catch (
const exception& exc)
1973 m_values_candidate = values_candidate_backup;
1976 "Parsed file [" << cfg_path <<
"]: Exception occurred; individual logical validation failed. "
1977 "Values payload untouched. Message = [" << exc.what() <<
"].");
1982 for (
const auto& pair : fresh_iterable_values)
1984 const auto& name = pair.first;
1985 const auto& var_value = pair.second.value();
1987 assert((!
key_exists(m_iterable_values_candidate, name) ||
1988 (m_iterable_values_candidate[name].type() == var_value.type())));
1990 m_iterable_values_candidate[name] = var_value;
1995 args.
m_call_type = Declare_options_func_args::Call_type::S_COMPARE_PARSED_VALS;
1997 m_declare_opts_func(args);
2005 FLOW_LOG_TRACE(
"Option_set[" << *
this <<
"]: State PARSING: Validate/store succeded. "
2006 "Further validation deferred until attempt to enter state CANONICAL. "
2007 "Updated values payload details follow.");
2008 log_values(
"post-parsing candidate config", &m_values_candidate,
log::Sev::S_TRACE);
2011template<
typename Value_set>
2017 FLOW_LOG_INFO(
"Option_set[" << *
this <<
"]: State CANONICAL: Request to load values from source struct "
2018 "[" << &src_values <<
"]; entering state PARSING. "
2019 "Any preceding canonical state will be ignored. Details follow (TRACE log level).");
2021 assert(m_iterable_values_candidate.empty());
2025 FLOW_LOG_INFO(
"Option_set[" << *
this <<
"]: State PARSING: Request to load values from source struct "
2026 "[" << &src_values <<
"]; continuing by parsing this next config source. "
2027 "Any current candidate values payload will be overwritten entirely. "
2028 "Details follow (TRACE log level).");
2043 args.
m_call_type = Declare_options_func_args::Call_type::S_LOAD_VALS_AS_IF_PARSED;
2045 m_declare_opts_func(args);
2053 args.
m_call_type = Declare_options_func_args::Call_type::S_COMPARE_PARSED_VALS;
2055 m_declare_opts_func(args);
2057 log_values(
"post-loading (perhaps baseline or rewound) candidate config", &m_values_candidate,
log::Sev::S_TRACE);
2060template<
typename Value_set>
2067 FLOW_LOG_INFO(
"Option_set[" << *
this <<
"]: State PARSING: Entering state CANONICAL. "
2068 "Values payload finalized. Details follow (TRACE log level).");
2069 log_values(
"entering-CANONICAL-state finalized config", &m_values_candidate,
log::Sev::S_TRACE);
2075 for (
const auto& pair : m_iterable_values_candidate)
2077 const auto& name = pair.first;
2078 FLOW_LOG_INFO(
"Option_set[" << *
this <<
"]: Detected change in option named [" << name <<
"].");
2081 if (change_detected)
2083 *change_detected = (!m_iterable_values_candidate.empty());
2089 m_values = m_values_candidate;
2090 m_iterable_values_candidate.clear();
2093template<
typename Value_set>
2098 FLOW_LOG_INFO(
"Option_set[" << *
this <<
"]: State PARSING: Rejecting candidate payload built; "
2099 "reverting to state CANONICAL.");
2101 m_iterable_values_candidate.clear();
2104 m_values_candidate = m_values;
2108template<
typename Value_set>
2111 validate_values(values(), success_or_null);
2114template<
typename Value_set>
2117 const auto candidate = values_candidate();
2118 assert(candidate &&
"Do not invoke validate_values_candidate() in CANONICAL state; only while PARSING.");
2119 validate_values(*candidate, success_or_null);
2122template<
typename Value_set>
2125 bool* success_or_null)
2127 using std::exception;
2130 if (success_or_null)
2134 validate_values(logger_ptr, values_to_validate, declare_opts_func);
2136 catch (
const exception& exc)
2139 *success_or_null =
false;
2142 *success_or_null =
true;
2150 args.
m_call_type = Declare_options_func_args::Call_type::S_VALIDATE_STORED_VALS;
2159 declare_opts_func(args);
2161 catch (
const exception& exc)
2163 FLOW_LOG_WARNING(
"Stand-alone validation check failed: Details: [" << exc.what() <<
"].");
2168template<
typename Value_set>
2171 validate_values(get_logger(), values_to_validate, m_declare_opts_func, success_or_null);
2174template<
typename Value_set>
2177 return os <<
'[' << val.
m_nickname <<
"]@" << &val;
2180template<
typename Value>
2186template<
typename Rep,
typename Period>
2191 using boost::chrono::ceil;
2192 using boost::chrono::nanoseconds;
2193 using boost::chrono::microseconds;
2194 using boost::chrono::milliseconds;
2195 using boost::chrono::seconds;
2196 using boost::chrono::minutes;
2197 using boost::chrono::hours;
2200 using raw_ticks_t = uint64_t;
2203 nanoseconds val_ns{val};
2206 raw_ticks_t raw_abs_ticks = (val_ns.count() < 0) ? (-val_ns.count()) : val_ns.count();
2211 if (raw_abs_ticks == 0)
2213 os << seconds::zero();
2219 const auto try_next_unit = [&](
auto pre_division_dur, raw_ticks_t divide_by) ->
bool
2221 if ((raw_abs_ticks % divide_by) == 0)
2224 raw_abs_ticks /= divide_by;
2232 if (!(try_next_unit(val_ns, 1000)
2233 || try_next_unit(ceil<microseconds>(val), 1000)
2234 || try_next_unit(ceil<milliseconds>(val), 1000)
2235 || try_next_unit(ceil<seconds>(val), 60)
2236 || try_next_unit(ceil<minutes>(val), 60)))
2238 os << ceil<hours>(val);
2242template<
typename Element>
2245 for (
size_t idx = 0; idx != val.size(); ++idx)
2250 if (idx != (val.size() - 1))
2257template<
typename Key>
2263 using boost::regex_match;
2264 using boost::smatch;
2273 smatch matched_groups;
2277 const string member_id_str{member_id};
2279 const bool matched_ok =
2282 assert(matched_ok &&
"Member identifier must look like: <longest possible stuff>[<key to replace>]<the rest>");
2284 constexpr char INDEX_SEP_BEFORE =
'.';
2293 size_t(matched_groups[1].length())}),
2297 size_t(matched_groups[2].length())}));
Un-templated base for Option_set.
static void declare_option_for_output(util::String_view name, opts::options_description *target_opts, const Value &value_default, const Value ¤t_value, util::String_view description)
Internal-through-macro helper function; the user shall not call this directly but only through FLOW_C...
static Function< void(const Value &val)> throw_on_invalid_func(util::String_view name, Function< bool(const Value &val)> &&validator_func_moved, util::String_view validator_cond_str)
Returns a function that wraps a Value->Boolean validator function, as passed to declare_option_for_pa...
Declare_options_func_call_type
Internal-use type to use with Option_set::Declare_options_func callback.
@ S_FILL_OUTPUT_HELP_ROLE_OPT_TABLE
Internal use only through macro.
@ S_FILL_PARSING_ROLE_OPT_TABLE
Internal use only through macro.
static void validate_parsed_option(util::String_view name, const Value &value, Function< bool(const Value &val)> &&validator_func_moved, util::String_view validator_cond_str)
Internal-through-macro helper function; the user shall not call this directly but only through FLOW_C...
opts::options_description Opt_table
Short-hand for boost.program_options config options description, each of which is used for parsing an...
The core config-parsing facility, which builds parsing/comparison/output capabilities on top of a giv...
typename Values::Ptr Mutable_values_ptr
Short-hand for ref-counted pointer to a mutable Values (config payload storable in an Option_set).
void validate_values(bool *success_or_null=nullptr) const
Validates the current contents of values() using the validators *this Option_set<Value_set> is config...
const boost::unordered_set< std::string > & option_names() const
Returns set of all option names declared by the option-declaring function passed to the constructor.
std::map< std::string, boost::any > Iterable_values
Similar to a boost.program_options parsing results variables_map, which conceptually mirrors the resu...
Opt_table m_opts_for_parsing
The parsing-role Opt_table (see extensive explanation in Opt_table doc header).
Iterable_values m_iterable_values_candidate
Structure mirroring m_values_candidate, where the values are the parsing-enabled members of m_values_...
void validate_values_candidate(bool *success_or_null=nullptr) const
Equivalent to validate_values(success_or_null) but validates *values_candidate() instead of values().
Mutable_values_ptr mutable_values_copy() const
Convenience method that heap-allocates a copy of the internally stored values() and wraps in a ref-co...
void values_to_ostream(std::ostream &os, const Values *values_or_null=nullptr) const
Writes a multi-line user-suitable representation of the current values in a Values object,...
const std::string m_nickname
See nickname ctor arg.
boost::unordered_set< std::string > m_opt_names
See option_names().
void log_help(util::String_view summary, log::Sev sev=log::Sev::S_INFO) const
Logs a multi-line help message using help_to_ostream().
Values m_values
See values().
void load_option_value_as_if_parsed(util::String_view name, Value *target_value, const Value &source_value)
Internal-through-macro helper function; the user shall not call this directly but only through FLOW_C...
const Values & values() const
Externally immutable internally stored canonical (current) config values as last constructed or parse...
Declare_options_func m_declare_opts_func
The Opt_table-filling, or m_iterable_values_candidate-scanning, callback passed to the constructor an...
typename Values::Const_ptr Values_ptr
Short-hand for ref-counted pointer to an immutable Value_set (config payload storable in an Option_se...
void declare_option_for_parsing(util::String_view name, Value *target_value, const Value *value_default_if_no_acc, Function< bool(const Value &val)> &&validator_func_moved, util::String_view validator_cond_str)
Internal-through-macro helper function; the user shall not call this directly but only through FLOW_C...
Opt_table m_opts_for_help
The output-role Opt_table, help-text sub-role (see extensive explanation in Opt_table doc header).
Value_set Values
Short-hand for the template parameter type Value_set.
Option_set(log::Logger *logger_ptr, util::String_view nickname, Declare_options_func &&declare_opts_func_moved)
Constructs an option set in CANONICAL state with a default-valued values() payload and options declar...
void parse_config_file(const fs::path &cfg_path, bool allow_unregistered, bool *success_or_null=nullptr, const boost::unordered_set< std::string > &allowed_unregistered_opts_or_empty={})
Enters into (from CANONICAL state) or continues in PARSING state by parsing the config source in the ...
bool m_parsing
See values_candidate() – true if and only if that returns non-null (PARSING state; else CANONICAL sta...
void reject_candidate()
In PARSING state, returns to CANONICAL state, as if no parse attempts have occurred.
bool null() const
Return true if and only if the option-declaring function passed to the constructor declared no option...
void declare_option_for_help(util::String_view name, const Value &value_default, util::String_view description)
Internal-through-macro helper function; the user shall not call this directly but only through FLOW_C...
void canonicalize_candidate(bool *change_detected=nullptr)
In PARSING state enters CANONICAL state, finalizing values() from values_candidate().
const Values * values_candidate() const
Returns null in CANONICAL state; or in PARSING state a pointer to the not-yet-canonical values after ...
void help_to_ostream(std::ostream &os) const
Prints a multi-line help message about the set of options that *this can parse.
Values m_values_candidate
See values_candidate().
Values m_values_default
Copy of values() when it is first constructed; i.e., the defaults.
void log_values(util::String_view summary, const Values *values_or_null=nullptr, log::Sev sev=log::Sev::S_INFO) const
Logs the given values payload using values_to_ostream().
void parse_direct_values(const Values &src_values)
Enters into (from CANONICAL state) or continues in PARSING state by simply setting *values_candidate(...
void scan_parsed_option(util::String_view name, const Value &canonical_value)
Internal-through-macro helper function; the user shall not call this directly but only through FLOW_C...
An std::runtime_error (which is an std::exception) that stores an Error_code.
Convenience class that simply stores a Logger and/or Component passed into a constructor; and returns...
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
Similar to ostringstream but allows fast read-only access directly into the std::string being written...
std::ostream & os()
Access to stream that will write to owned string.
#define FLOW_ERROR_SYS_ERROR_LOG_WARNING()
Logs a warning about the (often errno-based or from a library) error code in sys_err_code.
#define FLOW_LOG_INFO(ARG_stream_fragment)
Logs an INFO message into flow::log::Logger *get_logger() with flow::log::Component get_log_component...
#define FLOW_LOG_WARNING(ARG_stream_fragment)
Logs a WARNING message into flow::log::Logger *get_logger() with flow::log::Component get_log_compone...
#define FLOW_LOG_WITH_CHECKING(ARG_sev, ARG_stream_fragment)
Logs a message of the specified severity into flow::log::Logger *get_logger() with flow::log::Compone...
#define FLOW_LOG_SET_CONTEXT(ARG_logger_ptr, ARG_component_payload)
For the rest of the block within which this macro is instantiated, causes all FLOW_LOG_....
#define FLOW_LOG_TRACE(ARG_stream_fragment)
Logs a TRACE message into flow::log::Logger *get_logger() with flow::log::Component get_log_component...
Flow module that facilitates configuring modules, such as applications and APIs, via statically and/o...
void value_to_ostream(std::ostream &os, const Value &val)
Serializes a value of type Value to the given ostream suitably for output in Option_set-related outpu...
std::string value_set_member_id_to_opt_name(util::String_view member_id, char sep_replacement='-')
Utility, used by FLOW_CFG_OPTION_SET_DECLARE_OPTION() internally but made available as a public API i...
std::string value_set_member_id_to_opt_name_keyed(util::String_view member_id, const Key &key)
Similar to value_set_member_id_to_opt_name() but used by FLOW_CFG_OPTION_SET_DECLARE_OPTION_KEYED() i...
const boost::regex VALUE_SET_MEMBER_ID_TO_OPT_NAME_KEYED_REGEX
An internal constant for value_set_member_id_to_opt_name_keyed().
std::ostream & operator<<(std::ostream &os, const Option_set< Value_set > &val)
Serializes (briefly) an Option_set to a standard output stream.
Sev
Enumeration containing one of several message severity levels, ordered from highest to lowest.
@ S_TRACE
Message indicates any condition that may occur with great frequency (thus verbose if logged).
@ S_INFO
Message indicates a not-"bad" condition that is not frequent enough to be of severity Sev::S_TRACE.
void store(T *target_val, const boost::type_identity_t< T > &val)
Default store(&target_stats.m_val, val) that simply assigns *target_val = val.
bool key_exists(const Container &container, const typename Container::key_type &key)
Returns true if and only if the given key is present at least once in the given associative container...
std::string ostream_op_string(T &&... ostream_args)
Equivalent to ostream_op_to_string() but returns a new string by value instead of writing to the call...
Basic_string_view< char > String_view
Commonly used char-based Basic_string_view. See its doc header.
boost::system::error_code Error_code
Short-hand for a boost.system error code (which basically encapsulates an integer/enum error code and...
Flow_log_component
The flow::log::Component payload enumeration comprising various log components used by Flow's own int...
Internal-use structure to use with Declare_options_func callback.
Option_set * m_option_set
m_option_set->m_opts_for_parsing shall be filled out.
const Values * m_values_current
The current values loaded into *m_target_opts (e.g., via description text) will originate here.
struct flow::cfg::Option_set::Declare_options_func_args::@0::@1 m_fill_parsing_role_opt_table_args
Corresponds to Call_type::S_FILL_PARSING_ROLE_OPT_TABLE.
struct flow::cfg::Option_set::Declare_options_func_args::@0::@2 m_fill_output_help_role_opt_table_args
Corresponds to Call_type::S_FILL_OUTPUT_HELP_ROLE_OPT_TABLE.
struct flow::cfg::Option_set::Declare_options_func_args::@0::@3 m_fill_output_current_role_opt_table_args
Corresponds to Call_type::S_FILL_OUTPUT_CURRENT_ROLE_OPT_TABLE.
struct flow::cfg::Option_set::Declare_options_func_args::@0::@5 m_load_val_as_if_parsed_args
Corresponds to Call_type::S_LOAD_VALS_AS_IF_PARSED.
struct flow::cfg::Option_set::Declare_options_func_args::@0::@4 m_compare_parsed_vals_args
Corresponds to Call_type::S_COMPARE_PARSED_VALS.
const Values * m_values_to_validate
Each validator-enabled (via a Declare_options_func) member in this structure shall be validated.
const Values * m_values_default
m_option_set->m_values_default: defaults loaded into Option_set::m_opts_for_help will originate here.
const Values * m_values_to_load
Values shall be copied from this external Value_set.
opts::options_description * m_target_opts
m_target_opts shall be filled out based on the defaults earlier saved into m_values_default and curre...
Call_type m_call_type
Why Declare_options_func is being called.
Values * m_values_candidate
m_option_set->m_values_candidate, the parsing-in-progress Value_set filled out whenever parsing using...
const Values * m_values_default_no_acc
m_option_set->m_values_default: the defaults loaded into m_values_candidate at the top of each parse,...
union flow::cfg::Option_set::Declare_options_func_args::@0 m_args
The args to pass in depending on m_call_type.
struct flow::cfg::Option_set::Declare_options_func_args::@0::@6 m_validate_stored_vals_args
Corresponds to Call_type::S_VALIDATE_STORED_VALS.