![]() |
advgetopt 2.0.49
Parse complex command line arguments and configuration files in C++.
|
#include <validator_duration.h>
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. | |
virtual std::string | name () const override |
Return the name of this validator. | |
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 | |
flag_t | f_flags = VALIDATOR_DURATION_DEFAULT_FLAGS |
Definition at line 48 of file validator_duration.h.
typedef std::uint32_t advgetopt::validator_duration::flag_t |
Definition at line 52 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 will be effective.
[in] | flag_list | The flags used to define the usage of the 'm' suffix. |
Definition at line 112 of file validator_duration.cpp.
References 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 204 of file validator_duration.cpp.
References advgetopt::validator_double::convert_string(), advgetopt::option_flags_merge(), and VALIDATOR_DURATION_LONG.
Referenced by validate().
|
staticinherited |
Definition at line 589 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.
[in] | name_and_params | The validator name and parameters. |
Definition at line 626 of file validator.cpp.
References advgetopt::validator::create(), and advgetopt::option_flags_merge().
|
overridevirtual |
This function returns "duration".
Implements advgetopt::validator.
Definition at line 142 of file validator_duration.cpp.
|
staticinherited |
Definition at line 571 of file validator.cpp.
References advgetopt::option_flags_merge().
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 160 of file validator_duration.cpp.
References convert_string(), f_flags, and advgetopt::option_flags_merge().
|
private |
Definition at line 69 of file validator_duration.h.
Referenced by validator_duration(), and validate().
|
staticconstexpr |
Definition at line 54 of file validator_duration.h.
Definition at line 55 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.