Flow 1.0.1
Flow project: Full implementation reference.
|
Un-templated base for Option_set. More...
#include <option_set.hpp>
Public Types | |
enum class | Declare_options_func_call_type { S_FILL_PARSING_ROLE_OPT_TABLE , S_FILL_OUTPUT_HELP_ROLE_OPT_TABLE , S_FILL_OUTPUT_CURRENT_ROLE_OPT_TABLE , S_COMPARE_PARSED_VALS , S_LOAD_VALS_AS_IF_PARSED , S_VALIDATE_STORED_VALS } |
Internal-use type to use with Option_set::Declare_options_func callback. More... | |
Static Public Member Functions | |
template<typename Value > | |
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_CFG_OPTION_SET_DECLARE_OPTION() (see Option_set main constructor doc header). More... | |
template<typename Value > | |
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_CFG_OPTION_SET_DECLARE_OPTION() (see Option_set main constructor doc header). More... | |
Protected Types | |
using | Opt_table = opts::options_description |
Short-hand for boost.program_options config options description, each of which is used for parsing and/or describing (to humans) one or more config option/its value. More... | |
Static Protected Member Functions | |
template<typename Value > | |
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_parsing() and others, in code that will throw an exception with a human-useful message if that validator function indicates the Value passed to it is invalid; else will no-op. More... | |
Un-templated base for Option_set.
Definition at line 33 of file option_set.hpp.
|
protected |
Short-hand for boost.program_options config options description, each of which is used for parsing and/or describing (to humans) one or more config option/its value.
boost.program_options allows for a wide variety of features and capacities for this object type, but our goal is to use it for our specific and more constrained config context, and hence we use this type in more specific/constrained ways which we describe here.
We use it in our context in two primary roles; and since storage space and processor cycle are not practically affected, we tend to store separate copies of an Opt_table
in each role (possibly even more than 1, as there can be sub-roles of each). The roles are:
Values
and a mirroring Iterable_values
. opts::{parse_*|store}()
and other such functions take this Opt_table
and a config source as input. Such an Opt_table
stores a table of options; for each option storing:>>
stream input operator for reading values into the target location from the config source.Values
, which to load with the parsed bits obtained from the config source.Opt_table
. We expect each target value to already contain the default before parsing begins; if the option is not present in the particular config source, then that value remains untouched. Moreover note that the pre-parse value is not necessarily the user-specified default per se; it might be, for example, the value set by the previous config source's parsing phase; or even (in the case of dynamic option sets) in a much earlier config application.Opt_table
via a stream <<
. For each option:<<
stream output operator for writing values via standard stream output.<<
stream output operator. In this case that operator needs to be (conceptually) stored too.<<
would do; for example if we store a Fine_duration
(typically outputting which would be in nanoseconds, because it usually stores nanoseconds), it's often more convenient to round down (if precision would not be lost) and output using coarser units like sec or even minutes, etc. In this case we would prepare this value as an std::string
and store that; instead of storing a value in the original type as in parsing-role Opt_table
. At least these reasons exist to print this value:Definition at line 216 of file option_set.hpp.
|
strong |
Internal-use type to use with Option_set::Declare_options_func callback.
The user of the class need not understand this nor use it directly.
The reason for the Option_set::Declare_options_func call, originally from FLOW_CFG_OPTION_SET_DECLARE_OPTION().
Enumerator | |
---|---|
S_FILL_PARSING_ROLE_OPT_TABLE | Internal use only through macro. Do not use directly. Add option entries into Option_set::m_opts_for_parsing using Option_set::declare_option_for_parsing(). |
S_FILL_OUTPUT_HELP_ROLE_OPT_TABLE | Internal use only through macro. Do not use directly. Add option entries into Option_set::m_opts_for_help using Option_set::declare_option_for_help(). |
S_FILL_OUTPUT_CURRENT_ROLE_OPT_TABLE | Internal use only through macro. Do not use directly. Add option entries into an Option_set::Opt_table that shall be output to an |
S_COMPARE_PARSED_VALS | Internal use only through macro. Do not use directly. Compare recently parsed values in Option_set::m_iterable_values_candidate to the canonical Option_set::m_values values, using Option_set::scan_parsed_option(). |
S_LOAD_VALS_AS_IF_PARSED | Internal use only through macro. Do not use directly. Load values in Option_set::m_values_candidate and Option_set::m_iterable_values_candidate from a ready-made |
S_VALIDATE_STORED_VALS | Internal use only through macro. Do not use directly. Validate values stored – perhaps manually in code, not through parsing – in a |
Definition at line 46 of file option_set.hpp.
|
static |
Internal-through-macro helper function; the user shall not call this directly but only through FLOW_CFG_OPTION_SET_DECLARE_OPTION() (see Option_set main constructor doc header).
Loads an entry into target_opts
which will enable the proper text to appear for that option in Option_set::values_to_ostream() or Option_set::log_values(): including its name, default value, current values, and description.
Value | Type of the value inside a Value_set object. It must be reasonably copyable; and it must be supported by some version (including specialization(s) and overload(s)) of value_to_ostream(). |
name | See Option_set::declare_option_for_parsing(). |
target_opts | The Opt_table that shall be filled out for output to ostream . |
value_default | See Option_set::declare_option_for_help(). |
current_value | Current value to show to the user. |
description | See Option_set::declare_option_for_help(). |
Definition at line 1669 of file option_set.hpp.
References flow::cfg::value_to_ostream().
|
staticprotected |
Returns a function that wraps a Value
->Boolean validator function, as passed to declare_option_for_parsing() and others, in code that will throw an exception with a human-useful message if that validator function indicates the Value
passed to it is invalid; else will no-op.
Value | See Option_set::declare_option_for_parsing(). |
name | See Option_set::declare_option_for_parsing(). For nice human-readable message formation. |
validator_func_moved | See Option_set::declare_option_for_parsing(). |
validator_cond_str | See Option_set::declare_option_for_parsing(). For nice human-readable message formation. |
Definition at line 1610 of file option_set.hpp.
References flow::util::String_ostream::os(), and flow::cfg::value_to_ostream().
Referenced by validate_parsed_option().
|
static |
Internal-through-macro helper function; the user shall not call this directly but only through FLOW_CFG_OPTION_SET_DECLARE_OPTION() (see Option_set main constructor doc header).
Runs the validator function, with the same semantics as in declare_option_for_parsing(), for the given option. If the validation passes, no-op. If the validation fails throws exception containing (in its message) a user-friendly description of what failed.
Value | Type of the value inside a Value_set object. It must be reasonably copyable. |
name | See Option_set::declare_option_for_parsing(). |
value | Value to validate. |
validator_func_moved | See Option_set::declare_option_for_parsing(). |
validator_cond_str | See Option_set::declare_option_for_parsing(). |
Definition at line 1773 of file option_set.hpp.
References throw_on_invalid_func().