AnCH validation library namespace. More...
Classes | |
| struct | Allowed |
Allowed values constraint ( enum ). More... | |
| struct | CheckContext |
| Context in which constraints are checked. More... | |
| struct | CheckContext< anch::csv::detail::ReadContext > |
anch-val constraints checked when CSV fields are read ( Options::readCheckConstraints ) | |
| struct | CheckContext< anch::csv::detail::WriteContext > |
anch-val constraints checked when CSV fields are written ( Options::writeCheckConstraints ) | |
| struct | CheckContext< anch::json::ReaderContext > |
anch-val constraints checked on deserialization: deserialize_check_constraints option, violations raise anch::json::MappingError ( CONSTRAINT_VIOLATION , with the path of the value) More... | |
| struct | CheckContext< anch::json::WriterContext > |
anch-val constraints checked on serialization: serialize_check_constraints option, violations raise anch::json::MappingError ( CONSTRAINT_VIOLATION ) More... | |
| struct | Custom |
| Custom constraint. More... | |
| struct | Format |
String format constraint ( format ). More... | |
| struct | FractionDigits |
Maximum number of fraction digits constraint (XSD fractionDigits facet). More... | |
| struct | IsScalar |
Scalar type: value type checked as a whole, without fields (it is not described by anch::Mapping ). More... | |
| struct | IsScalar< anch::date::Date > |
| struct | IsScalar< anch::date::DateTime > |
| struct | IsScalar< anch::date::Time > |
| struct | IsScalar< anch::UUID > |
| struct | IsScalar< std::chrono::duration< R, P > > |
| struct | IsScalar< std::chrono::time_point< C, D > > |
| struct | Items |
| Items constraints. More... | |
| struct | Length |
Exact length constraint (XSD length facet). More... | |
| struct | Maximum |
Maximum value constraint ( maximum and exclusiveMaximum ). More... | |
| struct | MaxItems |
Maximum number of items constraint ( maxItems ). More... | |
| struct | MaxLength |
Maximum string length constraint ( maxLength ). More... | |
| struct | MaxProperties |
Maximum number of map entries constraint ( maxProperties ). More... | |
| struct | Minimum |
Minimum value constraint ( minimum and exclusiveMinimum ). More... | |
| struct | MinItems |
Minimum number of items constraint ( minItems ). More... | |
| struct | MinLength |
Minimum string length constraint ( minLength ). More... | |
| struct | MinProperties |
Minimum number of map entries constraint ( minProperties ). More... | |
| struct | MultipleOf |
Multiple of constraint ( multipleOf ). More... | |
| class | Path |
| Path of a value from the root value (validation violations): segments are field names or map keys and collection items indexes. Formats format it their way (JSON Pointer with pointer , XPath for XML, ...). More... | |
| struct | Pattern |
String pattern constraint ( pattern ). More... | |
| struct | Required |
| Required field constraint. More... | |
| struct | TotalDigits |
Maximum number of digits constraint (XSD totalDigits facet). More... | |
| struct | UniqueItems |
Unique items constraint ( uniqueItems ). More... | |
| class | ValidationContext |
| Validation context. More... | |
| class | ValidationMapper |
Mapper which validates the fields of a described type ( anch::Mapping ). More... | |
| struct | Violation |
| Constraint violation found by a validation (see anch::val::ValidationContext ). More... | |
Concepts | |
| concept | Collection |
| concept | FieldConstraint |
| concept | MapLike |
| concept | Number |
| concept | Scalar |
| Scalar type (see anch::val::IsScalar ). | |
| concept | StringLike |
| concept | Validatable |
Type which can be validated: scalar ( anch::val::IsScalar ), described object ( anch::Mapping ), or std::optional , pointer, collection or map of them. | |
| concept | ValueConstraint |
Typedefs | |
| using | PatternMatcher = std::function<bool(std::string_view)> |
| using | PatternCompiler = std::function<anch::val::PatternMatcher(std::string_view)> |
| using | FormatValidator = std::function<bool(std::string_view)> |
Enumerations | |
| enum class | PatternSyntax { ECMASCRIPT , XSD } |
Functions | |
| std::ostream & | operator<< (std::ostream &out, const anch::val::Path &path) |
| void | setPatternCompiler (anch::val::PatternCompiler compiler) |
| void | setPatternCompiler (anch::val::PatternSyntax syntax, anch::val::PatternCompiler compiler) |
| void | registerFormat (const std::string &name, anch::val::FormatValidator validator) |
| template<typename... C> | |
| constexpr bool | isRequired () |
| template<typename... C> | |
| constexpr bool | hasValueConstraints () |
| template<typename P> | |
| constexpr bool | isNullable () |
| constexpr anch::val::MinLength | minLength (std::size_t length) |
| constexpr anch::val::MaxLength | maxLength (std::size_t length) |
| template<anch::val::Number N> | |
| constexpr anch::val::Minimum< N > | minimum (N value, bool exclusive=false) |
| template<anch::val::Number N> | |
| constexpr anch::val::Minimum< N > | exclusiveMinimum (N value) |
| template<anch::val::Number N> | |
| constexpr anch::val::Maximum< N > | maximum (N value, bool exclusive=false) |
| template<anch::val::Number N> | |
| constexpr anch::val::Maximum< N > | exclusiveMaximum (N value) |
| template<anch::val::Number N> | |
| anch::val::MultipleOf< N > | multipleOf (N value) |
| constexpr anch::val::MinItems | minItems (std::size_t count) |
| constexpr anch::val::MaxItems | maxItems (std::size_t count) |
| constexpr anch::val::MinProperties | minProperties (std::size_t count) |
| constexpr anch::val::MaxProperties | maxProperties (std::size_t count) |
| anch::val::Pattern | pattern (std::string_view source) |
| anch::val::Pattern | xsdPattern (std::string_view source) |
| constexpr anch::val::Length | length (std::size_t length) |
| constexpr anch::val::TotalDigits | totalDigits (std::size_t digits) |
| constexpr anch::val::FractionDigits | fractionDigits (std::size_t digits) |
| anch::val::Format | format (std::string name) |
| template<typename A> | |
| auto | allowed (std::initializer_list< A > values) |
| template<typename... C> | |
| anch::val::Items< std::decay_t< C >... > | items (C &&... constraints) |
| template<typename V> | |
| anch::val::Custom< V > | custom (std::function< bool(const V &)> predicate, std::string message) |
| template<typename T> | |
| std::vector< anch::val::Violation > | validate (const T &value) |
| template<typename T> | |
| bool | isValid (const T &value) |
Variables | |
| constexpr anch::val::Required | required {} |
| constexpr anch::val::UniqueItems | uniqueItems {} |
AnCH validation library namespace.
Fields constraints shared by formats. See AnCH validation library documentation.
| using anch::val::FormatValidator = std::function<bool(std::string_view)> |
Format validator: returns true when the value is valid
| using anch::val::PatternCompiler = std::function<anch::val::PatternMatcher(std::string_view)> |
Pattern compiler: builds the matcher of a pattern (ECMA-262 regular expression for JSON Schema)
| using anch::val::PatternMatcher = std::function<bool(std::string_view)> |
Pattern matcher: returns true when the value matches the pattern
|
strong |
Pattern syntax
| Enumerator | |
|---|---|
| ECMASCRIPT | ECMA-262 regular expression (JSON Schema): the pattern is searched in the value |
| XSD | XML Schema regular expression (XSD |
| auto anch::val::allowed | ( | std::initializer_list< A > | values | ) |
Allowed values constraint ( enum ). Character strings literals are stored as std::string .
| A | the values type |
| values | the allowed values |
| anch::val::Custom< V > anch::val::custom | ( | std::function< bool(const V &)> | predicate, |
| std::string | message ) |
Custom constraint
| V | the value type |
| predicate | the predicate (true when value is valid) |
| message | the error message |
|
constexpr |
exclusiveMaximum constraint: value has to be lower than bound
| N | the bound type |
| value | the bound |
|
constexpr |
exclusiveMinimum constraint: value has to be greater than bound
| N | the bound type |
| value | the bound |
| anch::val::Format anch::val::format | ( | std::string | name | ) |
format constraint
| name | the format name |
|
constexpr |
XSD fractionDigits facet
| digits | the maximum number of fraction digits |
|
constexpr |
Check if constraints contain value constraints (other than anch::val::Required )
| C | the constraints types |
true when one of the constraints is not anch::val::Required
|
constexpr |
Check if type can hold null value: std::optional , std::shared_ptr , std::unique_ptr or pointer
| P | the type |
true when type can hold null value
|
constexpr |
| bool anch::val::isValid | ( | const T & | value | ) |
Check if value is valid ( anch::val::validate returns no violation)
| T | the value type |
| value | the value |
true when value is valid| anch::val::Items< std::decay_t< C >... > anch::val::items | ( | C &&... | constraints | ) |
Items constraints
| C | the items constraints types |
| constraints | the constraints to check on every item |
|
constexpr |
XSD length facet
| length | the length (code points of a string, items of a collection) |
|
constexpr |
maximum constraint
| N | the bound type |
| value | the maximum value |
| exclusive | value has to be lower than value |
|
constexpr |
maxItems constraint
| count | the maximum number of items |
|
constexpr |
maxLength constraint
| length | the maximum length (Unicode code points) |
|
constexpr |
maxProperties constraint (map entries)
| count | the maximum number of entries |
|
constexpr |
minimum constraint
| N | the bound type |
| value | the minimum value |
| exclusive | value has to be greater than value |
|
constexpr |
minItems constraint
| count | the minimum number of items |
|
constexpr |
minLength constraint
| length | the minimum length (Unicode code points) |
|
constexpr |
minProperties constraint (map entries)
| count | the minimum number of entries |
| anch::val::MultipleOf< N > anch::val::multipleOf | ( | N | value | ) |
multipleOf constraint
| N | the divisor type |
| value | the divisor |
| std::invalid_argument | divisor is not strictly positive |
| std::ostream & anch::val::operator<< | ( | std::ostream & | out, |
| const anch::val::Path & | path ) |
Write path as a JSON Pointer
| out | the output stream |
| path | the path |
| anch::val::Pattern anch::val::pattern | ( | std::string_view | source | ) |
pattern constraint
| source | the pattern (ECMA-262 regular expression with the default compiler) |
| std::regex_error | invalid pattern (default compiler) |
| void anch::val::registerFormat | ( | const std::string & | name, |
| anch::val::FormatValidator | validator ) |
Register format validator (thread safe). It replaces the validator already registered with this name.
Registered formats:
email : dot-atom local part (64 characters at most) and host name domain (no quoted local part nor address literal) ;hostname : RFC 1123 host name (labels of 63 characters at most, 253 characters at most) ;ipv4 and ipv6 : inet_pton (no leading zero in IPv4 addresses, no IPv6 zone) ;uri : RFC 3986 scheme followed by URI characters (percent encoding is checked, not the URI structure) ;byte : base64 with padding (RFC 4648) ;uuid (with ANCH_UUID ), date-time and date (with ANCH_DATE , RFC 3339, anch-date range: years 1678 to 2261 for date-time ).| name | the format name |
| validator | the validator, nullptr to remove the format |
| void anch::val::setPatternCompiler | ( | anch::val::PatternCompiler | compiler | ) |
Set the pattern compiler used by anch::val::pattern . The default compiler uses std::regex (ECMAScript grammar) and std::regex_search . Another engine (RE2, PCRE2, ...) can be used for performance or for UTF-8 support: std::regex works on bytes ( . matches one byte, character classes do not contain multi-bytes characters).
The compiler is used when patterns are built: it has to be set before mappers registration (mappers are registered on their first use). A pattern is compiled once for every format (each format registers the description of a type): its matcher is shared until the compiler of its syntax is changed.
| compiler | the compiler, nullptr to restore the default compiler |
| void anch::val::setPatternCompiler | ( | anch::val::PatternSyntax | syntax, |
| anch::val::PatternCompiler | compiler ) |
Set the pattern compiler of a syntax (see setPatternCompiler). The default XSD compiler translates XSD patterns to std::regex , matched on the whole value ( std::regex_match ), when the translation keeps their meaning: ^ and $ are ordinary characters, \s is [ \t\n\r] , \d is [0-9] (ASCII digits only). Constructs which need Unicode properties ( \p{..} , \P{..} , \i , \I , \c , \C , \w , \W ) and character class subtractions ( [a-z-[aeiou]] ) are refused ( std::invalid_argument ): another compiler (ICU, PCRE2, ...) can be plugged for them.
| syntax | the pattern syntax |
| compiler | the compiler, nullptr to restore the default compiler |
|
constexpr |
XSD totalDigits facet
| digits | the maximum number of digits |
| std::vector< anch::val::Violation > anch::val::validate | ( | const T & | value | ) |
Validate value without serializing it: constraints of the fields of described objects ( anch::Mapping ) and of their nested values. Every violation is returned with its path ( anch::val::Path , JSON Pointer with pointer() ), in fields registration order.
| T | the value type (described object, collection, map, std::optional , ...) |
| value | the value |
| anch::val::Pattern anch::val::xsdPattern | ( | std::string_view | source | ) |
XSD pattern facet: the pattern matches the whole value
| source | the pattern (XML Schema regular expression) |
| std::invalid_argument | pattern not supported by the default compiler (see setPatternCompiler) |
| std::regex_error | invalid pattern (default compiler) |
|
inlineconstexpr |
Required constraint instance
|
inlineconstexpr |
UniqueItems constraint instance