|
FEAT 3
Finite Element Analysis Toolbox
|
Builder-pattern for defining parameters. See methods for details. More...
#include <arg_parser.hpp>
Public Member Functions | |
| ParameterBuilder (std::shared_ptr< Intern::ParameterCore > core, String env_prefix, String property_path_prefix, String flag_prefix) | |
| template<typename V_ = T_, typename = std::enable_if_t<std::is_same_v<std::deque<String>, V_>>> | |
| ParameterBuilder & | bootstrap () |
| Mark this parameter as a bootstrap parameter. More... | |
| template<typename U_ , typename Fn_ > | |
| ParameterBuilder & | derives_from (const Parameter< U_ > ¶m, Fn_ &&fn) |
| ArgParser::derive_from wrapper for casting lambdas to function pointers. More... | |
| template<typename U_ > | |
| ParameterBuilder & | derives_from (const Parameter< U_ > ¶m, T_(*fn)(const U_ &)) |
| Derive this parameter from another parameter if it has not been set by the user. More... | |
| template<typename U_ , typename V_ , typename W_ , typename Fn_ > | |
| ParameterBuilder & | derives_from (const Parameter< U_ > ¶m_one, const Parameter< V_ > ¶m_two, const Parameter< W_ > ¶m_three, Fn_ &&fn) |
| ArgParser::derive_from wrapper for casting lambdas to function pointers. More... | |
| template<typename U_ , typename V_ , typename W_ > | |
| ParameterBuilder & | derives_from (const Parameter< U_ > ¶m_one, const Parameter< V_ > ¶m_two, const Parameter< W_ > ¶m_three, T_(*fn)(const U_ &, const V_ &, const W_ &)) |
| Derive this parameter from three other parameters if it has not been set by the user. More... | |
| template<typename U_ , typename V_ , typename Fn_ > | |
| ParameterBuilder & | derives_from (const Parameter< U_ > ¶m_one, const Parameter< V_ > ¶m_two, Fn_ &&fn) |
| ArgParser::derive_from wrapper for casting lambdas to function pointers. More... | |
| template<typename U_ , typename V_ > | |
| ParameterBuilder & | derives_from (const Parameter< U_ > ¶m_one, const Parameter< V_ > ¶m_two, T_(*fn)(const U_ &, const V_ &)) |
| Derive this parameter from two other parameters if it has not been set by the user. More... | |
| ParameterBuilder & | env (const String &s) |
| Set the environment variable for a parameter. More... | |
| ParameterBuilder & | help_string (String &&s) |
| Set help string for this parameter. More... | |
| template<typename U_ > | |
| ParameterBuilder & | hide_if (const Parameter< U_ > ¶meter, bool(*condition)(const T_ &)) |
| Conditionally mark another parameter as hidden. More... | |
| ParameterBuilder & | long_flag (String s) |
| Set the long flag for a parameter. More... | |
| ParameterBuilder & | name (String &&s) |
| Set a name for this parameter. More... | |
| template<typename U_ > | |
| ParameterBuilder & | needs (const Parameter< U_ > ¶meter) |
| Mark another parameter as needed by this one. More... | |
| template<typename U_ > | |
| ParameterBuilder & | needs_if (const Parameter< U_ > ¶meter, bool(*condition)(const T_ &)) |
| Conditionally mark another parameter as needed by this one. More... | |
| operator Parameter< T_ > () | |
| Conversion operator. More... | |
| ParameterBuilder & | parser (T_(*parser_fn)(const String &)) |
| Set a custom parser for this parameter. More... | |
| ParameterBuilder & | placeholder (String &&s) |
| Set a placeholder text for the argument of this parameter. More... | |
| ParameterBuilder & | property (String &&s) |
| Set the property map path for a parameter. More... | |
| ParameterBuilder & | required () |
| Mark this parameter as required. More... | |
| ParameterBuilder & | short_flag (String &&s) |
| Set the short flag for a parameter. More... | |
| ParameterBuilder & | validator (bool(*validator_fn)(const T_ &)) |
| Set a validator for this paramater. More... | |
| ParameterBuilder & | validator (void(*validator_fn)(const T_ &)) |
| Set a validator for this paramater. More... | |
Private Attributes | |
| std::shared_ptr< Intern::ParameterCore > | _core |
| String | _env_prefix |
| String | _flag_prefix |
| String | _property_path_prefix |
Builder-pattern for defining parameters. See methods for details.
Definition at line 485 of file arg_parser.hpp.
|
inlineexplicit |
Definition at line 495 of file arg_parser.hpp.
|
inline |
Mark this parameter as a bootstrap parameter.
A common FEAT idiom is parsing a path (or paths) to a property map from the command line, loading that property map, and then parsing remaining options from that map. Naively, this would required defining at least two parsers, where the first parser just determines the paths of the property maps and the second parser does the full parsing run. To avoid this parameters can be marked as bootstrap parameters. The ArgParser::bootstrap method will parse just those parameters, with no further validation, and assemble a merged property map from the given paths. With that merged property map the full parsing can then be run.
Definition at line 888 of file arg_parser.hpp.
References FEAT::ParameterBuilder< T_ >::bootstrap().
Referenced by FEAT::ParameterBuilder< T_ >::bootstrap().
|
inline |
ArgParser::derive_from wrapper for casting lambdas to function pointers.
Definition at line 934 of file arg_parser.hpp.
References FEAT::ParameterBuilder< T_ >::derives_from().
|
inline |
Derive this parameter from another parameter if it has not been set by the user.
| [in] | param | Parameter this parameter derives from |
| [in] | fn | Function which calculates value from other parameter. |
Indicates that this parameter should have its value set based on the value of one other parameter, if this parameter has not been set by the user. If this parameter has been set by the user, the value set by the user will be kept. A parameter that has no flags, properties, or environment variables associated with it will always be derived.
Definition at line 908 of file arg_parser.hpp.
References XASSERT, and XASSERTM.
Referenced by FEAT::ParameterBuilder< T_ >::derives_from().
|
inline |
ArgParser::derive_from wrapper for casting lambdas to function pointers.
Definition at line 1019 of file arg_parser.hpp.
References FEAT::ParameterBuilder< T_ >::derives_from().
|
inline |
Derive this parameter from three other parameters if it has not been set by the user.
| [in] | param_one | First parameter this parameter derives from |
| [in] | param_two | Second parameter this parameter derives from |
| [in] | param_three | Third parameter this parameter derives from |
| [in] | fn | Function which calculates value from other parameter. |
Indicates that this parameter should have its value set based on the value of three other parameters, if this parameter has not been set by the user. If this parameter has been set by the user, the value set by the user will be kept. A parameter that has no flags, properties, or environment variables associated with it will always be derived.
Definition at line 992 of file arg_parser.hpp.
|
inline |
ArgParser::derive_from wrapper for casting lambdas to function pointers.
Definition at line 972 of file arg_parser.hpp.
References FEAT::ParameterBuilder< T_ >::derives_from().
|
inline |
Derive this parameter from two other parameters if it has not been set by the user.
| [in] | param_one | First parameter this parameter derives from |
| [in] | param_two | Second parameter this parameter derives from |
| [in] | fn | Function which calculates value from other parameter. |
Indicates that this parameter should have its value set based on the value of two other parameters, if this parameter has not been set by the user. If this parameter has been set by the user, the value set by the user will be kept. A parameter that has no flags, properties, or environment variables associated with it will always be derived.
Definition at line 953 of file arg_parser.hpp.
|
inline |
Set the environment variable for a parameter.
| [in] | s | Environment variable |
The parameters value will be taken from this environment variable during parsing, if the environment variable is set.
Definition at line 562 of file arg_parser.hpp.
|
inline |
Set help string for this parameter.
| [in] | s | Help string |
Sets the description of this parameter for the help text shown by ArgParser::usage.
The parameter definition
will result in the following snippet in the help text
* --mesh <mesh> * Mesh to operate on *
Definition at line 617 of file arg_parser.hpp.
References FEAT::ParameterBuilder< T_ >::help_string().
Referenced by FEAT::ParameterBuilder< T_ >::help_string().
|
inline |
Conditionally mark another parameter as hidden.
| [in] | parameter | The parameter to be conditionally hidden |
| [in] | condition | Function pointer to predicate |
Indicates that if this parameter is set by the user and has a certain value, as indicated by the condition function, then the given parameter should be hidden. A parameter is hidden as soon as any of the hide_if conditions regarding the parameter are fulfilled.
To ensure that no parameter is accidentally hidden, accessing the value of hidden parameter is an error and aborts the program.
Use this option if one parameter is unused, depending on another parameters value.
Definition at line 861 of file arg_parser.hpp.
References FEAT::value, and XASSERTM.
|
inline |
Set the long flag for a parameter.
| [in] | s | long flag, can be of form "foo" or "--foo". Additional dashes within the flag are allowed, e.g. '–foo-bar' |
Definition at line 534 of file arg_parser.hpp.
References FEAT::String::starts_with(), and XASSERTM.
|
inline |
Set a name for this parameter.
| [in] | s | Name for parameter |
The name will be used in error messages and the ArgParser::display() method to identify the parameter. If no name is set, the name will be derived from either a flag, the property path, or the environment variable. If none of these are set the name is '<anonymous>'.
Definition at line 658 of file arg_parser.hpp.
|
inline |
Mark another parameter as needed by this one.
| [in] | parameter | The parameter needed by this parameter |
Indicates that if this parameter is set by the user, then the given parameter must be set by the user as well.
Use this option if one parameter is not meaningful without another parameter. A filename for example might be meaningless without setting an output directory.
Alternatively consider combining the data into a single type with a custom parser and combining the dependent parameters into a single parameter.
Definition at line 799 of file arg_parser.hpp.
References XASSERTM.
|
inline |
Conditionally mark another parameter as needed by this one.
| [in] | parameter | The parameter needed by this parameter |
| [in] | condition | Function pointer to predicate |
Indicates that if this parameter is set by the user and has a certain value, as indicated by the condition function, then the given parameter must be set by the user as well.
Use this option if one parameter is sometimes not meaningful without another parameter. For example, if this parameter chooses a solver to use, then the different solver settings are only required if that solver is actually chosen.
Definition at line 830 of file arg_parser.hpp.
References FEAT::value, and XASSERTM.
|
inline |
Conversion operator.
Definition at line 1032 of file arg_parser.hpp.
|
inline |
Set a custom parser for this parameter.
| [in] | parser_fn | Pointer to parser function |
Allows setting a custom ad-hoc parser for this parameter, rather than relying on the usual String::parse method.
The parsing function is expected to throw a std::invalid_argument exception if any errors occur. The message given in the exception will be shown to the user.
Definition at line 676 of file arg_parser.hpp.
|
inline |
Set a placeholder text for the argument of this parameter.
| [in] | s | Placeholder |
The placeholder text will be shown in place of the parameters arguments in the help text generated by ArgParser::usage.
The parameter definition
will result in the following snippet in the help text
* --mesh <mesh> * Mesh to operate on *
Definition at line 642 of file arg_parser.hpp.
References FEAT::ParameterBuilder< T_ >::placeholder().
Referenced by FEAT::ParameterBuilder< T_ >::placeholder().
|
inline |
Set the property map path for a parameter.
| [in] | s | PropertyMap path |
The parameter will be filled with the (parsed) value refered to by this path. The path is always interpreted as relative to the root of the property map given to the ArgParser.
Definition at line 586 of file arg_parser.hpp.
|
inline |
Mark this parameter as required.
A required parameter must be set by the user. It is not enough for it to be default initialized.
Definition at line 772 of file arg_parser.hpp.
References FEAT::ParameterBuilder< T_ >::required().
Referenced by FEAT::ParameterBuilder< T_ >::required().
|
inline |
Set the short flag for a parameter.
| [in] | s | Short flag, can be of form "x" or "-x" where x is some letter. |
Definition at line 512 of file arg_parser.hpp.
References XASSERTM.
|
inline |
Set a validator for this paramater.
| [in] | validator_fn | Pointer to validator function |
Validators are run after argument parsing to ensure that parameters fulfill additional properties beyond just their type. This allows you to ensure that, for example, a integer parameter is within a specific of number, or that a file at a given file path actually exists.
This specific overload of this method expects a validator function that returns a boolean indicating whether the given value passes validation. A failed validation produces an error with a generic "Failed boolean test" message. If you want to supply a more useful error message to your users, see the non-boolean overload of this function.
Definition at line 741 of file arg_parser.hpp.
References XASSERTM.
|
inline |
Set a validator for this paramater.
| [in] | validator_fn | Pointer to validator function |
Validators are run after argument parsing to ensure that parameters fulfill additional properties beyond just their type. This allows you to ensure that, for example, a integer parameter is within a specific of number, or that a file at a given file path actually exists.
This specific overload of this method expects a validator function that throws a std::invalid_argument exception if the given value does not pass validation. The message given to the std::invalid_argument exception is forwarded to the user.
Definition at line 704 of file arg_parser.hpp.
References XASSERTM.
|
private |
Definition at line 488 of file arg_parser.hpp.
|
private |
Definition at line 490 of file arg_parser.hpp.
|
private |
Definition at line 492 of file arg_parser.hpp.
|
private |
Definition at line 491 of file arg_parser.hpp.