19 constexpr
char s_separator =
':';
30 interval.
lower.reset();
31 interval.
upper.reset();
34 auto pos = buf.find_first_of(s_separator);
36 if (
pos == std::string::npos) {
42 auto lowerStr = buf.substr(0,
pos);
43 interval.
lower = std::stod(lowerStr);
46 if ((
pos + 1) < buf.size()) {
47 auto upperStr = buf.substr(
pos + 1);
48 interval.
upper = std::stod(upperStr);
56 if (not interval.
lower.has_value() and not interval.
upper.has_value()) {
59 if (interval.
lower.has_value()) {
60 os << interval.
lower.value();
63 if (interval.
upper.has_value()) {
64 os << interval.
upper.value();
74 template <
typename value_t,
typename converter_t>
75 void parseVariable(std::istream& is, std::vector<value_t>&
values,
82 std::string::size_type
pos = 0;
83 std::string::size_type
end = std::string::npos;
85 end = buf.find_first_of(s_separator, pos);
86 if (end == std::string::npos) {
88 bufValue = buf.substr(pos);
90 bufValue = buf.substr(pos, end - pos);
93 values.push_back(
convert(bufValue));
94 }
while (end != std::string::npos);
97 template <
typename value_t,
typename converter_t>
98 void parseFixed(std::istream& is,
size_t size,
value_t* values,
101 std::vector<value_t>
tmp(size, 0);
102 parseVariable(is,
tmp, std::forward<converter_t>(
convert));
104 throw std::invalid_argument(
105 "Not enough values for fixed-size user option, expected " +
108 if (size <
tmp.size()) {
109 throw std::invalid_argument(
110 "Too many values for fixed-size user option, expected " +
116 template <
typename value_t>
117 void print(std::ostream&
os,
size_t size,
const value_t* values) {
118 for (
size_t i = 0;
i <
size; ++
i) {
133 parseFixed(is, size, values,
138 std::istream& is, std::vector<double>& values) {
139 parseVariable(is, values, [](
const std::string&
s) {
return std::stod(s); });
143 const double* values) {
144 print(os, size, values);
152 parseFixed(is, size, values,
157 std::istream& is, std::vector<int>& values) {
158 parseVariable(is, values, [](
const std::string&
s) {
return std::stoi(s); });
163 print(os, size, values);