40#include <cppthread/log.h>
45#include <snapdev/trim_string.h>
50#include <snapdev/poison.h>
70 validator::register_validator(*
this);
75 return std::string(
"duration");
80 return std::make_shared<validator_duration>(data);
185 else if(
r ==
"large")
189 else if(!
r.empty() && (
r[0] | 0x20) >=
'a' && (
r[0] | 0x20) <=
'z')
194 cppthread::log << cppthread::log_level_t::error
196 <<
" is not a valid duration suffix or flag."
205 std::string::size_type
const pos(
r.find(
"..."));
206 if(
pos == std::string::npos)
210 cppthread::log << cppthread::log_level_t::error
212 <<
" is not a valid duration."
220 std::string
const min_value(snapdev::trim_string(
r.substr(0,
pos)));
225 cppthread::log << cppthread::log_level_t::error
227 <<
" is not a valid value for your range's start;"
228 " it must be a valid duration,"
229 " optionally preceded by a sign (+ or -)."
235 std::string
const max_value(snapdev::trim_string(
r.substr(
pos + 3)));
240 cppthread::log << cppthread::log_level_t::error
242 <<
" is not a valid value for your range's end;"
243 " it must be a valid duration,"
244 " optionally preceded by a sign (+ or -)."
252 cppthread::log << cppthread::log_level_t::error
254 <<
" has to be smaller or equal to "
256 <<
"; you have an invalid duration range."
275 return std::string(
"duration");
371 std::string
const & value
380 char const *
s(value.c_str());
401 while(*
s >=
'0' && *
s <=
'9')
411 while(*
s >=
'0' && *
s <=
'9');
494 std::string
const &
suffix
530 return 86400.0 * 30.0;
537 else if(
suffix ==
"minute"
545 return 86400.0 * 30.0;
548 ||
suffix ==
"microsecond"
549 ||
suffix ==
"microseconds")
554 ||
suffix ==
"millisecond"
555 ||
suffix ==
"milliseconds")
564 ||
suffix ==
"nanoseconds")
584 return 86400.0 * 7.0;
593 return 86400.0 * 365.0;
virtual std::shared_ptr< validator > create(string_list_t const &data) const override
validator_duration_factory()
virtual std::string get_name() const override
static bool convert_string(std::string const &number, double &result)
Convert a string to a double value.
virtual std::string name() const override
Return the name of this validator.
range_t::vector_t f_allowed_values
virtual bool validate(std::string const &value) const override
Determine whether value is a valid duration.
validator_duration(string_list_t const &data)
Initialize the duration validator.
static bool convert_string(std::string const &duration, flag_t flags, double suffix_default_factor, double &result)
Convert a string to a double value representing a duration.
static double suffix_to_factor(std::string const &suffix, flag_t flags, double suffix_default_factor)
Convert a duration suffix in a factor.
static constexpr flag_t VALIDATOR_DURATION_LONG
void set_error(std::string const &msg) const
validator_duration_factory g_validator_duration_factory
The advgetopt environment to parse command line options.
constexpr flag_t option_flags_merge()
std::vector< std::string > string_list_t
Declaration of validators which can be used to verify the parameters.
Declaration of validators which can be used to verify the parameters.