22#include "anch-val-export.hpp"
29#include <initializer_list>
53 class ANCH_VAL_EXPORT
Path {
56 using Segment = std::variant<std::string, std::size_t>;
61 std::vector<Segment> _segments;
84 const std::vector<Segment>&
segments() const noexcept;
108 bool operator==(const
Path& other) const = default;
120 ANCH_VAL_EXPORT std::ostream& operator<<(std::ostream& out, const
anch::
val::
Path& path);
151 std::vector<anch::val::Path::Segment> _path;
154 std::vector<anch::val::Violation> _violations;
183 void add(
const std::string& message);
196 template<
typename... C>
209 || (std::integral<N> && !std::same_as<N, bool> && !std::same_as<N, char> && !std::same_as<N, wchar_t>
210 && !std::same_as<N, char8_t> && !std::same_as<N, char16_t> && !std::same_as<N, char32_t>);
220 concept StringLike = std::convertible_to<const V&, std::string_view>;
230 concept MapLike = std::ranges::sized_range<const V> &&
requires {
231 typename V::key_type;
232 typename V::mapped_type;
274 struct IsScalar: std::bool_constant<std::is_arithmetic_v<T> || std::is_enum_v<T> || anch::val::StringLike<T>> {};
293 template<
typename C,
typename D>
294 struct IsScalar<std::chrono::time_point<C, D>>: std::true_type {};
297 template<
typename R,
typename P>
298 struct IsScalar<std::chrono::duration<R, P>>: std::true_type {};
335namespace anch::val::detail {
339 struct IsNullable: std::is_pointer<P> {};
343 struct IsNullable<std::optional<P>>: std::true_type {};
347 struct IsNullable<std::shared_ptr<P>>: std::true_type {};
350 template<
typename P,
typename D>
351 struct IsNullable<std::unique_ptr<P,D>>: std::true_type {};
362 struct UnwrapType<std::optional<P>> {
369 struct UnwrapType<std::shared_ptr<P>> {
375 template<
typename P,
typename D>
376 struct UnwrapType<std::unique_ptr<P,D>> {
383 struct UnwrapType<P*> {
390 using Unwrap =
typename UnwrapType<std::remove_cvref_t<P>>::type;
393 template<
typename C,
typename V>
394 struct IsValueConstraint: std::bool_constant<requires(const C& constraint, const V& value, std::string& message) {
395 { constraint.check(value, message) } -> std::same_as<bool>;
406 template<
typename V,
typename... C>
407 constexpr bool itemsApplicable() {
408 if constexpr (anch::val::MapLike<V>) {
409 return (IsValueConstraint<C, Unwrap<typename V::mapped_type>>::value && ...);
410 }
else if constexpr (anch::val::Collection<V>) {
411 return (IsValueConstraint<C, Unwrap<std::ranges::range_value_t<V>>>::value && ...);
418 template<
typename... C,
typename V>
419 struct IsValueConstraint<anch::val::Items<C...>, V>: std::bool_constant<itemsApplicable<V, C...>()> {};
429 ANCH_VAL_EXPORT
bool matchesFormat(
const std::string& name, std::string_view value);
438 ANCH_VAL_EXPORT std::size_t codePoints(std::string_view str);
448 ANCH_VAL_EXPORT std::optional<std::pair<std::size_t, std::size_t>> decimalDigits(std::string_view decimal);
461 std::string decimalOf(
const V& value);
473 std::string formatValue(
const V& value);
486 template<
typename C,
typename P,
typename X>
487 void applyConstraint(
const C& constraint,
const P& value, X& context);
501 template<
typename P,
typename X,
typename... C>
502 void checkConstraints(
const P& value, X& context,
const C&... constraints);
551 template<anch::val::StringLike V>
552 bool check(
const V& str, std::string& message)
const;
578 template<anch::val::StringLike V>
579 bool check(
const V& str, std::string& message)
const;
593 template<anch::val::Number N>
611 template<anch::val::Number V>
612 bool check(
const V& number, std::string& message)
const;
626 template<anch::val::Number N>
644 template<anch::val::Number V>
645 bool check(
const V& number, std::string& message)
const;
660 template<anch::val::Number N>
675 template<anch::val::Number V>
676 bool check(
const V& number, std::string& message)
const;
700 template<anch::val::Collection V>
725 template<anch::val::Collection V>
750 template<anch::val::MapLike V>
751 bool check(
const V& map, std::string& message)
const;
775 template<anch::val::MapLike V>
776 bool check(
const V& map, std::string& message)
const;
800 template<anch::val::Collection V>
801 requires std::equality_comparable<std::ranges::range_value_t<V>>
833 requires std::equality_comparable_with<V, A>
834 bool check(
const V& value, std::string& message)
const;
851 template<
typename... C>
865 template<
typename V,
typename X>
893 template<anch::val::StringLike V>
894 bool check(
const V& str, std::string& message)
const;
906 template<anch::val::Collection V>
938 bool check(
const V& decimal, std::string& message)
const;
966 bool check(
const V& decimal, std::string& message)
const;
1039 std::shared_ptr<const anch::val::PatternMatcher>
matcher;
1057 template<anch::val::StringLike V>
1058 bool check(
const V& str, std::string& message)
const;
1111 template<anch::val::StringLike V>
1112 bool check(
const V& str, std::string& message)
const;
1124 template<
typename V>
1140 bool check(
const V& value, std::string& error)
const;
1151 template<
typename C,
typename V>
1152 concept ValueConstraint = anch::val::detail::IsValueConstraint<std::remove_cvref_t<C>, V>::value;
1163 template<
typename C,
typename P>
1176 template<
typename... C>
1190 template<
typename... C>
1204 template<
typename P>
1206 return anch::val::detail::IsNullable<std::remove_cvref_t<P>>::value;
1244 template<anch::val::Number N>
1258 template<anch::val::Number N>
1273 template<anch::val::Number N>
1287 template<anch::val::Number N>
1303 template<anch::val::Number N>
1433 template<
typename A>
1447 template<
typename... C>
1462 template<
typename V>
1468#include "val/impl/constraints.hpp"
UUID generator and parser.
Definition uuid.hpp:51
Calendar day (RFC 3339 full-date , JSON schema and OpenAPI date format, XSD xs:date ).
Definition date.hpp:63
Point in time.
Definition dateTime.hpp:89
Time of day (RFC 3339 partial-time , SQL TIME , XSD xs:time without time zone).
Definition time.hpp:48
Path of a value from the root value (validation violations): segments are field names or map keys and...
Definition constraints.hpp:53
Path(std::vector< Segment > segments)
std::variant< std::string, std::size_t > Segment
Definition constraints.hpp:56
bool empty() const noexcept
std::string pointer() const
const std::vector< Segment > & segments() const noexcept
Validation context.
Definition constraints.hpp:146
std::vector< anch::val::Violation > & violations()
void enter(std::string_view field)
void enter(std::size_t index)
void add(const std::string &message)
Definition constraints.hpp:243
Definition constraints.hpp:1164
Definition constraints.hpp:230
Definition constraints.hpp:208
Scalar type (see anch::val::IsScalar ).
Definition constraints.hpp:308
Definition constraints.hpp:220
Definition constraints.hpp:1152
AnCH validation library namespace.
Definition mapper.hpp:150
PatternSyntax
Definition constraints.hpp:988
@ XSD
Definition constraints.hpp:992
@ ECMASCRIPT
Definition constraints.hpp:990
anch::val::Format format(std::string name)
constexpr anch::val::Minimum< N > minimum(N value, bool exclusive=false)
constexpr anch::val::MinItems minItems(std::size_t count)
std::function< bool(std::string_view)> PatternMatcher
Definition constraints.hpp:974
constexpr anch::val::MinProperties minProperties(std::size_t count)
std::function< anch::val::PatternMatcher(std::string_view)> PatternCompiler
Definition constraints.hpp:981
constexpr bool hasValueConstraints()
Definition constraints.hpp:1191
anch::val::Items< std::decay_t< C >... > items(C &&... constraints)
constexpr anch::val::MinLength minLength(std::size_t length)
auto allowed(std::initializer_list< A > values)
constexpr bool isRequired()
Definition constraints.hpp:1177
constexpr anch::val::UniqueItems uniqueItems
Definition constraints.hpp:806
constexpr anch::val::MaxProperties maxProperties(std::size_t count)
constexpr anch::val::Length length(std::size_t length)
void registerFormat(const std::string &name, anch::val::FormatValidator validator)
constexpr anch::val::TotalDigits totalDigits(std::size_t digits)
constexpr anch::val::Required required
Definition constraints.hpp:526
void setPatternCompiler(anch::val::PatternCompiler compiler)
std::function< bool(std::string_view)> FormatValidator
Definition constraints.hpp:1066
constexpr anch::val::Maximum< N > maximum(N value, bool exclusive=false)
anch::val::Custom< V > custom(std::function< bool(const V &)> predicate, std::string message)
anch::val::MultipleOf< N > multipleOf(N value)
constexpr anch::val::Minimum< N > exclusiveMinimum(N value)
constexpr anch::val::Maximum< N > exclusiveMaximum(N value)
constexpr bool isNullable()
Definition constraints.hpp:1205
anch::val::Pattern pattern(std::string_view source)
anch::val::Pattern xsdPattern(std::string_view source)
constexpr anch::val::MaxItems maxItems(std::size_t count)
constexpr anch::val::MaxLength maxLength(std::size_t length)
constexpr anch::val::FractionDigits fractionDigits(std::size_t digits)
AnCH framework base namespace.
Definition app.hpp:30
Allowed values constraint ( enum ).
Definition constraints.hpp:818
bool check(const V &value, std::string &message) const
std::vector< A > values
Definition constraints.hpp:820
Context in which constraints are checked.
Definition constraints.hpp:331
Custom constraint.
Definition constraints.hpp:1125
std::function< bool(const V &)> predicate
Definition constraints.hpp:1127
std::string message
Definition constraints.hpp:1130
bool check(const V &value, std::string &error) const
Maximum number of fraction digits constraint (XSD fractionDigits facet).
Definition constraints.hpp:950
bool check(const V &decimal, std::string &message) const
std::size_t value
Definition constraints.hpp:952
Scalar type: value type checked as a whole, without fields (it is not described by anch::Mapping ).
Definition constraints.hpp:274
Items constraints.
Definition constraints.hpp:852
void apply(const V &items, X &context) const
std::tuple< C... > constraints
Definition constraints.hpp:854
Exact length constraint (XSD length facet).
Definition constraints.hpp:879
bool check(const V &items, std::string &message) const
std::size_t value
Definition constraints.hpp:881
bool check(const V &str, std::string &message) const
Maximum number of items constraint ( maxItems ).
Definition constraints.hpp:711
std::size_t value
Definition constraints.hpp:713
bool check(const V &items, std::string &message) const
Maximum string length constraint ( maxLength ).
Definition constraints.hpp:564
bool check(const V &str, std::string &message) const
std::size_t value
Definition constraints.hpp:566
Maximum number of map entries constraint ( maxProperties ).
Definition constraints.hpp:761
std::size_t value
Definition constraints.hpp:763
bool check(const V &map, std::string &message) const
Maximum value constraint ( maximum and exclusiveMaximum ).
Definition constraints.hpp:627
bool check(const V &number, std::string &message) const
N value
Definition constraints.hpp:629
bool exclusive
Definition constraints.hpp:632
Minimum number of items constraint ( minItems ).
Definition constraints.hpp:686
bool check(const V &items, std::string &message) const
std::size_t value
Definition constraints.hpp:688
Minimum string length constraint ( minLength ).
Definition constraints.hpp:537
bool check(const V &str, std::string &message) const
std::size_t value
Definition constraints.hpp:539
Minimum number of map entries constraint ( minProperties ).
Definition constraints.hpp:736
bool check(const V &map, std::string &message) const
std::size_t value
Definition constraints.hpp:738
Minimum value constraint ( minimum and exclusiveMinimum ).
Definition constraints.hpp:594
bool check(const V &number, std::string &message) const
bool exclusive
Definition constraints.hpp:599
N value
Definition constraints.hpp:596
Multiple of constraint ( multipleOf ).
Definition constraints.hpp:661
bool check(const V &number, std::string &message) const
N value
Definition constraints.hpp:663
String pattern constraint ( pattern ).
Definition constraints.hpp:1037
bool check(const V &str, std::string &message) const
std::string source
Definition constraints.hpp:1042
anch::val::PatternSyntax syntax
Definition constraints.hpp:1045
std::shared_ptr< const anch::val::PatternMatcher > matcher
Definition constraints.hpp:1039
Required field constraint.
Definition constraints.hpp:523
Maximum number of digits constraint (XSD totalDigits facet).
Definition constraints.hpp:922
std::size_t value
Definition constraints.hpp:924
bool check(const V &decimal, std::string &message) const
Unique items constraint ( uniqueItems ).
Definition constraints.hpp:789
bool check(const V &items, std::string &message) const
Constraint violation found by a validation (see anch::val::ValidationContext ).
Definition constraints.hpp:129
std::string message
Definition constraints.hpp:134
anch::val::Path path
Definition constraints.hpp:131