30[[nodiscard]]
inline ChainableResult<ConfigValue<std::size_t>>
34 std::vector<std::string> err_text{};
35 std::vector<std::vector<FormatParam>> params{};
37 err_text.emplace_back(
"'{}' must be greater than '{}'");
39 err_text.emplace_back(
"");
40 params.emplace_back();
42 auto [format_text, format_params] = val.
format_data();
43 std::ranges::copy(format_text, std::back_inserter(err_text));
44 std::ranges::copy(format_params, std::back_inserter(params));
79template <
typename T,
typename ConfigInterface,
typename FetchFunc,
typename Comparator>
82 const ConfigInterface &config,
83 const std::string &scope_param,
84 const std::string &other_field_name,
85 FetchFunc fetch_other,
87 std::string_view error_message)
89 auto other_result = fetch_other(config, scope_param);
92 if (!other_result.has_value()) {
93 return other_result.error();
96 const auto &other_val = other_result.value();
99 if (!comp(val.
value(), other_val.value())) {
100 std::vector<std::string> err_text{};
101 std::vector<std::vector<FormatParam>> params{};
103 err_text.emplace_back(
"'{}' {} '{}'");
109 err_text.emplace_back(
"");
110 params.emplace_back();
112 auto [format_text, format_params] = val.
format_data();
113 std::ranges::copy(format_text, std::back_inserter(err_text));
114 std::ranges::copy(format_params, std::back_inserter(params));
116 err_text.emplace_back(
"");
117 params.emplace_back();
118 err_text.emplace_back(
"{}");
120 err_text.emplace_back(
"");
121 params.emplace_back();
123 auto [other_format_text, other_format_params] = other_val.format_data();
124 std::ranges::copy(other_format_text, std::back_inserter(err_text));
125 std::ranges::copy(other_format_params, std::back_inserter(params));
153template <
typename T,
typename ConfigInterface,
typename FetchFunc>
156 const ConfigInterface &config,
157 const std::string &scope_param,
158 const std::string &other_field_name,
159 FetchFunc fetch_other)
162 val, config, scope_param, other_field_name, fetch_other, std::greater<>{},
"must be greater than");
178template <
typename T,
typename ConfigInterface,
typename FetchFunc>
181 const ConfigInterface &config,
182 const std::string &scope_param,
183 const std::string &other_field_name,
184 FetchFunc fetch_other)
187 val, config, scope_param, other_field_name, fetch_other, std::less<>{},
"must be less than");
203template <
typename T,
typename ConfigInterface,
typename FetchFunc>
206 const ConfigInterface &config,
207 const std::string &scope_param,
208 const std::string &other_field_name,
209 FetchFunc fetch_other)
217 std::greater_equal<>{},
218 "must be greater than or equal to");
234template <
typename T,
typename ConfigInterface,
typename FetchFunc>
237 const ConfigInterface &config,
238 const std::string &scope_param,
239 const std::string &other_field_name,
240 FetchFunc fetch_other)
243 val, config, scope_param, other_field_name, fetch_other, std::less_equal<>{},
"must be less than or equal to");
259template <
typename T,
typename ConfigInterface,
typename FetchFunc>
262 const ConfigInterface &config,
263 const std::string &scope_param,
264 const std::string &other_field_name,
265 FetchFunc fetch_other)
268 val, config, scope_param, other_field_name, fetch_other, std::equal_to<>{},
"must be equal to");
284template <
typename T,
typename ConfigInterface,
typename FetchFunc>
287 const ConfigInterface &config,
288 const std::string &scope_param,
289 const std::string &other_field_name,
290 FetchFunc fetch_other)
293 val, config, scope_param, other_field_name, fetch_other, std::not_equal_to<>{},
"must not be equal to");
A result type that maintains a chainable sequence of errors for debugging and error reporting.
A container that wraps a configuration value with its name and source information.
const T & value() const &
Gets a const reference to the underlying value.
std::pair< std::vector< std::string >, std::vector< std::vector< FormatParam > > > format_data() const
Generates formatted text data for displaying this configuration value.
const std::string & name() const
Gets the name of this configuration value.
ChainableResult< ConfigValue< T > > compare_values(const ConfigValue< T > &val, const ConfigInterface &config, const std::string &scope_param, const std::string &other_field_name, FetchFunc fetch_other, Comparator comp, std::string_view error_message)
Generic comparison validator that compares the current value against another config value.
ChainableResult< ConfigValue< T > > compare_equal(const ConfigValue< T > &val, const ConfigInterface &config, const std::string &scope_param, const std::string &other_field_name, FetchFunc fetch_other)
Validates that the current value is equal to another config value.
ChainableResult< ConfigValue< T > > compare_greater_than(const ConfigValue< T > &val, const ConfigInterface &config, const std::string &scope_param, const std::string &other_field_name, FetchFunc fetch_other)
Validates that the current value is greater than another config value.
@ italic
Italic text formatting.
@ none
No styling applied.
@ bold
Bold text formatting.
ChainableResult< ConfigValue< T > > compare_less_equal(const ConfigValue< T > &val, const ConfigInterface &config, const std::string &scope_param, const std::string &other_field_name, FetchFunc fetch_other)
Validates that the current value is less than or equal to another config value.
ChainableResult< ConfigValue< T > > compare_greater_equal(const ConfigValue< T > &val, const ConfigInterface &config, const std::string &scope_param, const std::string &other_field_name, FetchFunc fetch_other)
Validates that the current value is greater than or equal to another config value.
ChainableResult< ConfigValue< std::size_t > > size_t_val_greater_than_zero(const ConfigValue< std::size_t > &val)
Validates that a size_t config value is greater than zero.
ChainableResult< ConfigValue< T > > compare_less_than(const ConfigValue< T > &val, const ConfigInterface &config, const std::string &scope_param, const std::string &other_field_name, FetchFunc fetch_other)
Validates that the current value is less than another config value.
ChainableResult< ConfigValue< T > > compare_not_equal(const ConfigValue< T > &val, const ConfigInterface &config, const std::string &scope_param, const std::string &other_field_name, FetchFunc fetch_other)
Validates that the current value is not equal to another config value.