26#ifndef MYSQL_HARNESS_CONFIG_OPTION_INCLUDED
27#define MYSQL_HARNESS_CONFIG_OPTION_INCLUDED
37#include "harness_export.h"
44 double max_value = std::numeric_limits<double>::max());
66T
option_as_int(
const std::string_view &value,
const std::string &option_desc,
67 T min_value = std::numeric_limits<T>::min(),
68 T max_value = std::numeric_limits<T>::max()) {
69 const char *
start = value.data();
70 const char *end =
start + value.size();
73 using integral_type = std::conditional_t<std::is_same_v<T, bool>, uint8_t, T>;
75 integral_type int_result;
78 if (ptr == end && ec == std::errc{}) {
83 if (int_result <=
static_cast<integral_type
>(max_value) &&
84 int_result >=
static_cast<integral_type
>(min_value)) {
89 throw std::invalid_argument(option_desc +
" needs value between " +
92 std::string(value) +
"'");
102 T min_value = std::numeric_limits<T>::min(),
103 T max_value = std::numeric_limits<T>::max()) {
104 return option_as_int<T>(value, option_desc, min_value, max_value);
110 constexpr IntOption(T min_value = std::numeric_limits<T>::min(),
111 T max_value = std::numeric_limits<T>::max())
114 T
operator()(
const std::string &value,
const std::string &option_desc) {
127 const std::string & ) {
134 bool operator()(
const std::string &value,
const std::string &option_desc) {
135 if (value ==
"true" || value ==
"1")
return true;
136 if (value ==
"false" || value ==
"0")
return false;
138 throw std::invalid_argument(
139 option_desc +
" needs a value of either 0, 1, false or true, was '" +
151 value_type max_value = std::numeric_limits<value_type>::max())
155 const std::string &option_desc) {
167template <
typename Dur>
173 using __base::__base;
176 const std::string &option_desc) {
179 return std::chrono::duration_cast<duration_type>(
180 std::chrono::duration<double>(
result));
Definition: config_option.h:132
bool operator()(const std::string &value, const std::string &option_desc)
Definition: config_option.h:134
Definition: config_option.h:168
Dur duration_type
Definition: config_option.h:170
duration_type operator()(const std::string &value, const std::string &option_desc)
Definition: config_option.h:175
Definition: config_option.h:145
FloatingPointOption(value_type min_value=0, value_type max_value=std::numeric_limits< value_type >::max())
Definition: config_option.h:149
value_type max_value_
Definition: config_option.h:162
value_type operator()(const std::string &value, const std::string &option_desc)
Definition: config_option.h:154
V value_type
Definition: config_option.h:147
value_type min_value_
Definition: config_option.h:161
Definition: config_option.h:108
T min_value_
Definition: config_option.h:120
T max_value_
Definition: config_option.h:121
constexpr IntOption(T min_value=std::numeric_limits< T >::min(), T max_value=std::numeric_limits< T >::max())
Definition: config_option.h:110
T operator()(const std::string &value, const std::string &option_desc)
Definition: config_option.h:114
Definition: config_option.h:124
std::string operator()(const std::string &value, const std::string &)
Definition: config_option.h:126
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:180
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:50
T option_as_uint(const std::string_view &value, const std::string &option_desc, T min_value=std::numeric_limits< T >::min(), T max_value=std::numeric_limits< T >::max())
Get a unsigned integer.
Definition: config_option.h:101
double HARNESS_EXPORT option_as_double(const std::string &value, const std::string &option_desc, double min_value=0, double max_value=std::numeric_limits< double >::max())
Definition: config_option.cc:33
T option_as_int(const std::string_view &value, const std::string &option_desc, T min_value=std::numeric_limits< T >::min(), T max_value=std::numeric_limits< T >::max())
Gets an integer using the given option value.
Definition: config_option.h:66
FloatingPointOption< double > DoubleOption
Definition: config_option.h:165
static std::enable_if_t< std::is_unsigned< T >::value, stdx::expected< T, std::error_code > > from_chars(const std::string &value, int base=10)
convert a numeric string to a number.
Definition: tcp_address.cc:63