2 #include "creativity/cmdargs/strings.hpp" 3 #include <boost/program_options/errors.hpp> 4 #include <boost/program_options/options_description.hpp> 5 #include <boost/program_options/positional_options.hpp> 6 #include <boost/program_options/value_semantic.hpp> 34 operator const T& ()
const {
return val_; }
39 if (std::is_unsigned<T>::value) {
return type_string<T>() + u8
"⩾0"; }
40 return type_string<T>();
60 template <
typename T,
long min,
long denom = 1>
65 if (*
this < min / (
double) denom)
66 throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);
82 template<
typename T,
long max,
long denom = 1>
87 if (*
this > max / (
double) denom)
88 throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);
102 template<
typename T,
long min,
long max,
long denom = 1>
119 template <
typename T,
long lower,
long denom = 1>
124 if (*
this <= lower / (
double) denom)
125 throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);
139 template <
typename T,
long upper,
long denom = 1>
144 if (*
this >= upper / (
double) denom)
145 throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);
156 template <class V, typename = typename std::enable_if<std::is_base_of<ValidationTag, V>::value>::type>
157 void validate(boost::any &v,
const std::vector<std::string> &values, V*,
int) {
161 validators::check_first_occurrence(v);
163 std::string s(validators::get_single_string(values));
165 if (std::is_unsigned<typename V::value_type>::value and std::regex_search(s, std::regex(
"^\\s*-")))
166 throw invalid_option_value(s);
170 auto val = boost::lexical_cast<
typename V::value_type>(s);
173 v = boost::any(V(val));
176 throw invalid_option_value(s);
static std::string validationString()
Returns a string representation of this validation object.
Definition: Validation.hpp:38
Validation wrapper for options that have a maximum value.
Definition: Validation.hpp:83
Primary namespace for all Creativity library code.
Definition: config.hpp:4
static std::string validationString()
Returns string representation of this validation.
Definition: Validation.hpp:109
T val_
The stored value.
Definition: Validation.hpp:47
Validation wrapper base class.
Definition: Validation.hpp:29
static std::string validationString()
Returns string representation of this validation.
Definition: Validation.hpp:92
T value_type
The type T that this object validates.
Definition: Validation.hpp:36
static std::string validationString()
Returns string representation of this validation.
Definition: Validation.hpp:129
Below(T v)
Constructor. Throws if v >= upper.
Definition: Validation.hpp:143
Range(T v)
Constructor. Throws if v < min or v > max.
Definition: Validation.hpp:106
Validation(T v)
Constructs with an initial value.
Definition: Validation.hpp:32
Min(T v)
Constructor. Throws if v < min.
Definition: Validation.hpp:64
Validation tag; any Validation class must (ultimately) inherit from this class.
Definition: Validation.hpp:15
static std::string validationString()
Returns string representation of this validation.
Definition: Validation.hpp:70
Validation wrapper for options that have both a minimum and maximum value.
Definition: Validation.hpp:103
void validate(boost::any &v, const std::vector< std::string > &values, V *, int)
Overload of validate for boost to convert from string to a validated data type.
Definition: Validation.hpp:157
Validation wrapper for options that have a minimum value.
Definition: Validation.hpp:61
Validation wrapper for options that have a strict inequality boundary that the value must be below...
Definition: Validation.hpp:140
Max(T v)
Constructor. Throws if v > max.
Definition: Validation.hpp:86
static std::string validationString()
Returns string representation of this validation.
Definition: Validation.hpp:149
std::string output_string(T v)
Returns a value converted to a string; in most cases this just passes the value to std::to_string for...
Definition: strings.hpp:25
Validation wrapper for options that have a strict inequality boundary that the value must be above...
Definition: Validation.hpp:120
Above(T v)
Constructor. Throws if v <= lower.
Definition: Validation.hpp:123