|
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) | |
| ParameterBuilder & | env (String &&s) |
| Set the environment variable for a parameter. More... | |
| ParameterBuilder & | help_string (String &&s) |
| Set help string for this parameter. 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 |
Builder-pattern for defining parameters. See methods for details.
Definition at line 378 of file arg_parser.hpp.
|
inlineexplicit |
Definition at line 384 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 423 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 462 of file arg_parser.hpp.
References FEAT::ParameterBuilder< T_ >::help_string().
Referenced by FEAT::ParameterBuilder< T_ >::help_string().
|
inline |
Set the long flag for a parameter.
| [in] | s | Long flag, must be of the form '–foo'. Additional dashes within the flag are allowed, e.g. '–foo-bar' |
Definition at line 409 of file arg_parser.hpp.
References FEAT::ParameterBuilder< T_ >::long_flag().
Referenced by FEAT::ParameterBuilder< T_ >::long_flag().
|
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 503 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 644 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 675 of file arg_parser.hpp.
References FEAT::value, and XASSERTM.
|
inline |
Conversion operator.
Definition at line 690 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 521 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 487 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 438 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 617 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, must be of the form '-x' where x is some letter |
Definition at line 393 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 586 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 549 of file arg_parser.hpp.
References XASSERTM.
|
private |
Definition at line 381 of file arg_parser.hpp.