51#include <cppthread/log.h>
56#include <snapdev/trim_string.h>
61#include <snapdev/poison.h>
82 validator::register_validator(*
this);
87 return std::string(
"integer");
92 return std::make_shared<validator_integer>(data);
156 std::string::size_type
const pos(
r.find(
"..."));
157 if(
pos == std::string::npos)
161 cppthread::log << cppthread::log_level_t::error
163 <<
" is not a valid standalone value for your ranges;"
164 " it must only be digits, optionally preceeded by a sign (+ or -)"
165 " and not overflow an int64_t value."
173 std::string
const min_value(snapdev::trim_string(
r.substr(0,
pos)));
178 cppthread::log << cppthread::log_level_t::error
180 <<
" is not a valid value for your range's start;"
181 " it must only be digits, optionally preceeded by a sign (+ or -)"
182 " and not overflow an int64_t value."
188 std::string
const max_value(snapdev::trim_string(
r.substr(
pos + 3)));
193 cppthread::log << cppthread::log_level_t::error
195 <<
" is not a valid value for your range's end;"
196 " it must only be digits, optionally preceeded by a sign (+ or -)"
197 " and not overflow an int64_t value."
205 cppthread::log << cppthread::log_level_t::error
207 <<
" has to be smaller or equal to "
209 <<
"; you have an invalid range."
227 return std::string(
"integer");
292 char const *
s(value.c_str());
295 if(*
s ==
'-' || *
s ==
'+')
343 if(
integer > 0x8000000000000000ULL)
351 if(
integer > 0x7FFFFFFFFFFFFFFFULL)
360 std::int64_t
digit(std::numeric_limits<std::int64_t>::max());
361 if(
c >=
'0' &&
c <=
'9')
365 else if(
c >=
'a' &&
c <=
'f')
369 else if(
c >=
'A' &&
c <=
'F')
validator_integer_factory()
virtual std::shared_ptr< validator > create(string_list_t const &data) const override
virtual std::string get_name() const override
range_t::vector_t f_allowed_values
virtual bool validate(std::string const &value) const override
Determine whether value is an integer.
static bool convert_string(std::string const &number, std::int64_t &result)
Convert a string to an std::int64_t value.
validator_integer(string_list_t const &data)
Initialize the integer validator.
virtual std::string name() const override
Return the name of this validator.
validator_integer_factory g_validator_integer_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.