68[[nodiscard]]
inline ChainableResult<ConfigValue<std::size_t>>
72 std::vector<std::string> err_text{};
73 std::vector<std::vector<FormatParam>> params{};
75 err_text.emplace_back(
"'{}' must be greater than '{}'.");
77 err_text.emplace_back(
"");
78 params.emplace_back();
80 auto [format_text, format_params] = val.
format_data();
81 err_text.append_range(format_text);
82 params.append_range(format_params);
95[[nodiscard]]
inline ChainableResult<ConfigValue<std::size_t>>
98 if (val != 2 && val != 4) {
99 std::vector<std::string> err_text{};
100 std::vector<std::vector<FormatParam>> params{};
102 err_text.emplace_back(
"'{}' must be either '{}' or '{}'.");
108 err_text.emplace_back(
"");
109 params.emplace_back();
111 auto [format_text, format_params] = val.
format_data();
112 err_text.append_range(format_text);
113 params.append_range(format_params);
126[[nodiscard]]
inline ChainableResult<ConfigValue<std::size_t>>
129 if (val != 8 && val != 12) {
130 std::vector<std::string> err_text{};
131 std::vector<std::vector<FormatParam>> params{};
133 err_text.emplace_back(
"'{}' must be either '{}' or '{}'.");
139 err_text.emplace_back(
"");
140 params.emplace_back();
142 auto [format_text, format_params] = val.
format_data();
143 err_text.append_range(format_text);
144 params.append_range(format_params);
175template <
typename T,
typename ConfigInterface,
typename FetchFunc,
typename Comparator>
178 const ConfigInterface &config,
180 const std::string &scope,
181 const std::string &other_field_name,
182 FetchFunc fetch_other,
184 std::string_view error_message)
186 auto other_result = fetch_other(config, type, scope);
189 if (!other_result.has_value()) {
190 return other_result.error();
193 const auto &other_val = other_result.value();
196 if (!comp(val.
value(), other_val.value())) {
197 std::vector<std::string> err_text{};
198 std::vector<std::vector<FormatParam>> params{};
200 err_text.emplace_back(
"'{}' {} '{}'.");
206 err_text.emplace_back(
"");
207 params.emplace_back();
209 auto [format_text, format_params] = val.
format_data();
210 err_text.append_range(format_text);
211 params.append_range(format_params);
213 err_text.emplace_back(
"");
214 params.emplace_back();
215 err_text.emplace_back(
"{}");
217 err_text.emplace_back(
"");
218 params.emplace_back();
220 auto [other_format_text, other_format_params] = other_val.format_data();
221 err_text.append_range(other_format_text);
222 params.append_range(other_format_params);
251template <
typename T,
typename ConfigInterface,
typename FetchFunc>
254 const ConfigInterface &config,
256 const std::string &scope,
257 const std::string &other_field_name,
258 FetchFunc fetch_other)
261 val, config, type, scope, other_field_name, fetch_other, std::greater<>{},
"must be greater than");
278template <
typename T,
typename ConfigInterface,
typename FetchFunc>
281 const ConfigInterface &config,
283 const std::string &scope,
284 const std::string &other_field_name,
285 FetchFunc fetch_other)
288 val, config, type, scope, other_field_name, fetch_other, std::less<>{},
"must be less than");
305template <
typename T,
typename ConfigInterface,
typename FetchFunc>
308 const ConfigInterface &config,
310 const std::string &scope,
311 const std::string &other_field_name,
312 FetchFunc fetch_other)
321 std::greater_equal<>{},
322 "must be greater than or equal to");
339template <
typename T,
typename ConfigInterface,
typename FetchFunc>
342 const ConfigInterface &config,
344 const std::string &scope,
345 const std::string &other_field_name,
346 FetchFunc fetch_other)
349 val, config, type, scope, other_field_name, fetch_other, std::less_equal<>{},
"must be less than or equal to");
365template <
typename T,
typename ConfigInterface,
typename FetchFunc>
368 const ConfigInterface &config,
369 const std::string &scope_param,
370 const std::string &other_field_name,
371 FetchFunc fetch_other)
374 val, config, scope_param, other_field_name, fetch_other, std::equal_to<>{},
"must be equal to");
390template <
typename T,
typename ConfigInterface,
typename FetchFunc>
393 const ConfigInterface &config,
394 const std::string &scope_param,
395 const std::string &other_field_name,
396 FetchFunc fetch_other)
399 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.
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 & canonical_name() const
const T & value() const &
static const Style italic
Italic text formatting.
static const Style none
No styling applied.
static const Style bold
Bold text formatting.
ChainableResult< ConfigValue< T > > compare_values(const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, 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_less_equal(const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, 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_than(const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, const std::string &other_field_name, FetchFunc fetch_other)
Validates that the current value is greater than 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< std::size_t > > size_t_val_eight_or_twelve(const ConfigValue< std::size_t > &val)
Validates that a size_t config value is either 8 or 12.
ChainableResult< ConfigValue< T > > compare_less_than(const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, const std::string &other_field_name, FetchFunc fetch_other)
Validates that the current value is less than 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_equal(const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, 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< 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.
ConfigScopeType
Specifies the scope type for configuration value lookups.
ChainableResult< ConfigValue< std::size_t > > size_t_val_two_or_four(const ConfigValue< std::size_t > &val)
Validates that a size_t config value is either 2 or 4.