![]() |
advgetopt 2.0.49
Parse complex command line arguments and configuration files in C++.
|
#include <validator_duration.h>


Classes | |
| struct | range_t |
Public Types | |
| typedef std::uint32_t | flag_t |
| typedef std::shared_ptr< validator > | pointer_t |
| typedef std::vector< pointer_t > | vector_t |
Public Member Functions | |
| validator_duration (string_list_t const &data) | |
| Initialize the duration validator. | |
| std::string const & | get_error () const |
| virtual std::string | name () const override |
| Return the name of this validator. | |
| void | set_error (std::string const &msg) const |
| virtual bool | validate (std::string const &value) const override |
| Determine whether value is a valid duration. | |
Static Public Member Functions | |
| static bool | convert_string (std::string const &duration, flag_t flags, double &result) |
| Convert a string to a double value representing a duration. | |
| static pointer_t | create (std::string const &name, string_list_t const &data) |
| static pointer_t | create (std::string const &name_and_params) |
| Set the validator for this option. | |
| static void | register_validator (validator_factory const &factory) |
Static Public Attributes | |
| static constexpr flag_t | VALIDATOR_DURATION_DEFAULT_FLAGS = 0x00 |
| static constexpr flag_t | VALIDATOR_DURATION_LONG = 0x01 |
Private Attributes | |
| range_t::vector_t | f_allowed_values = range_t::vector_t() |
| std::string | f_error = std::string("<error undefined>") |
| flag_t | f_flags = VALIDATOR_DURATION_DEFAULT_FLAGS |
Definition at line 49 of file validator_duration.h.
| typedef std::uint32_t advgetopt::validator_duration::flag_t |
Definition at line 53 of file validator_duration.h.
|
inherited |
Definition at line 64 of file validator.h.
|
inherited |
Definition at line 65 of file validator.h.
| advgetopt::validator_duration::validator_duration | ( | string_list_t const & | flag_list | ) |
The constructor accepts a string defining the acceptable durations.
The string uses the following format:
'small' stands for small values (down to 1 second).
'large' stands for large values (so the 'm' suffix represents month, not minutes).
The 'small' and 'large' flags are exclusive, the last one is effective. Note that the 'm' suffix is the only one affected. If you want to specifically specify minutes or months you can also enter the entire word:
The duration range can use any duration on the left hand side and right hand side. The whole expression cannot include any spaces.
For example, the following defines a duration range between one second and one minute:
If a side is omitted the default is used: the minimum of the left hand side and the maximum for the right hand side. The minimum must be smaller or equal to the maximum.
When no suffix is specified, seconds are assumed.
| [in] | flag_list | The flags used to define the usage of the 'm' suffix. |
Definition at line 148 of file validator_duration.cpp.
References convert_string(), f_allowed_values, f_flags, advgetopt::option_flags_merge(), and VALIDATOR_DURATION_LONG.
|
static |
This function is used to convert a string to a double representing a duration. The duration can be specified with one of the following suffixes:
The "m" suffix is interpreted as "minute" by default. The flags passed to the contructor can change that interpretation into "month" instead.
One month uses 30 days.
One year uses 365 days.
Note that the input can be a double. So you can define a duration of "1.3 seconds" or "2.25 days".
| [in] | value | The value to be converted to a duration. |
| [in] | flags | The flags to determine how to interpret the suffix. |
| [out] | result | The resulting duration in seconds. |
Definition at line 314 of file validator_duration.cpp.
References advgetopt::validator_double::convert_string(), advgetopt::option_flags_merge(), and VALIDATOR_DURATION_LONG.
Referenced by validator_duration(), and validate().
|
staticinherited |
Definition at line 605 of file validator.cpp.
References advgetopt::validator::name(), and advgetopt::option_flags_merge().
Referenced by advgetopt::validator::create(), and advgetopt::option_info::set_validator().
|
staticinherited |
This function parses the specified name and optional parameters and create a corresponding validator for this option.
The name_and_params string can be defined as:
The list of parameters is optional. There may be an empty, just one, or any number of parameters. How the parameters are parsed is left to the validator to decide.
If the input string is empty, the current validator, if one is installed, gets removed.
The complete grammar of the name_and_params name and parameters can be written as a comma separated list of function calls, we have a special case for regex which do not require the function call. thing is pretty much anything other than the few special characters (comma, space, parenthesis, and quotes). To include a special character in thing either use a string or escape the character.
| [in] | name_and_params | The validator name and parameters. |
Definition at line 666 of file validator.cpp.
References advgetopt::validator::create(), and advgetopt::option_flags_merge().
|
inherited |
Definition at line 581 of file validator.cpp.
References advgetopt::validator::f_error.
|
overridevirtual |
This function returns "duration".
Implements advgetopt::validator.
Definition at line 231 of file validator_duration.cpp.
|
staticinherited |
Definition at line 587 of file validator.cpp.
References advgetopt::option_flags_merge().
Definition at line 575 of file validator.cpp.
References advgetopt::validator::f_error, and advgetopt::option_flags_merge().
Referenced by advgetopt::validator_double::validate(), validate(), advgetopt::validator_email::validate(), advgetopt::validator_integer::validate(), advgetopt::validator_keywords::validate(), advgetopt::validator_length::validate(), advgetopt::validator_list::validate(), advgetopt::validator_regex::validate(), and advgetopt::validator_size::validate().
This function verifies that the specified value is a valid duration.
It makes sures that the value is a valid decimal number which optionally starts with a sign ([-+]?) and is optionally followed by a known measurement suffix.
| [in] | value | The value to validate. |
Implements advgetopt::validator.
Definition at line 249 of file validator_duration.cpp.
References convert_string(), f_allowed_values, f_flags, advgetopt::option_flags_merge(), and advgetopt::validator::set_error().
|
private |
Definition at line 79 of file validator_duration.h.
Referenced by validator_duration(), and validate().
|
mutableprivateinherited |
Definition at line 82 of file validator.h.
Referenced by advgetopt::validator::get_error(), and advgetopt::validator::set_error().
|
private |
Definition at line 78 of file validator_duration.h.
Referenced by validator_duration(), and validate().
|
staticconstexpr |
Definition at line 55 of file validator_duration.h.
Definition at line 56 of file validator_duration.h.
Referenced by validator_duration(), and convert_string().
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.