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);
156 else if(
r ==
"large")
163 std::string::size_type
const pos(
r.find(
"..."));
164 if(
pos == std::string::npos)
168 cppthread::log << cppthread::log_level_t::error
170 <<
" is not a valid duration or flag."
178 std::string
const min_value(snapdev::trim_string(
r.substr(0,
pos)));
183 cppthread::log << cppthread::log_level_t::error
185 <<
" is not a valid value for your range's start;"
186 " it must be a valid duration,"
187 " optionally preceded by a sign (+ or -)."
193 std::string
const max_value(snapdev::trim_string(
r.substr(
pos + 3)));
198 cppthread::log << cppthread::log_level_t::error
200 <<
" is not a valid value for your range's end;"
201 " it must be a valid duration,"
202 " optionally preceded by a sign (+ or -)."
210 cppthread::log << cppthread::log_level_t::error
212 <<
" has to be smaller or equal to "
214 <<
"; you have an invalid duration range."
233 return std::string(
"duration");
315 std::string
const & value
323 char const *
s(value.c_str());
344 while(*
s >=
'0' && *
s <=
'9')
354 while(*
s >=
'0' && *
s <=
'9');
364#pragma GCC diagnostic push
365#pragma GCC diagnostic ignored "-Wrestrict"
372#pragma GCC diagnostic pop
445 else if(
suffix ==
"minute"
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.
static bool convert_string(std::string const &duration, flag_t flags, double &result)
Convert a string to a double value representing a duration.
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 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.