constraints.h File Reference

Contains constraints, built-in constraint tags, fields and models. More...

#include <algorithm>
#include <unordered_set>
#include <regex>
#include "layer.h"
#include "utility.h"
#include "containers.h"
Include dependency graph for constraints.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  garlic::ConstraintResult
 Result of a constriant test. More...
 
class  garlic::Constraint
 Smallest unit of data validation. More...
 
struct  garlic::type_tag
 Constraint Tag that passes if the layer has matching data type. More...
 
struct  garlic::range_tag
 Constraint Tag that passes if the layer is within a certain boundary. More...
 
struct  garlic::regex_tag
 Constraint Tag that passes if a specified regex pattern passes the test. More...
 
struct  garlic::any_tag
 Constraint Tag that passes if any of the inner constraints pass. More...
 
struct  garlic::list_tag
 Constraint Tag that passes if the layer is a list and all its elements pass the inner constraints. More...
 
class  garlic::tuple_tag
 Constraint Tag that passes if the layer is a list and its first n elements pass the first n constraints. More...
 
class  garlic::map_tag
 Constraint Tag that passes if the layer's members pass key and value constraints. More...
 
struct  garlic::all_tag
 Constraint Tag that passes if all inner constraints pass the layer. More...
 
struct  garlic::literal_tag< T >
 Constraint Tag that passes if layer is equal to a specified value. More...
 
class  garlic::Field
 A named group of Constraint elements. More...
 
struct  garlic::Field::ValidationResult
 List of all failed constraints. More...
 
class  garlic::Model
 An object to describe a Model. More...
 
struct  garlic::Model::FieldDescriptor
 Field Record. More...
 
struct  garlic::model_tag
 Constraint Tag that passes if the specified Model passes the layer. More...
 
struct  garlic::field_tag
 Constraint Tag that passes if the specified Field passes the layer. More...
 

Typedefs

using garlic::constraint_registry = internal::registry< type_tag, range_tag, regex_tag, any_tag, list_tag, tuple_tag, map_tag, all_tag, model_tag, field_tag, string_literal_tag, int_literal_tag, double_literal_tag, bool_literal_tag, null_literal_tag >
 Built-in constraint tags.
 

Functions

template<GARLIC_VIEW Layer, typename Container , typename BackInserterIterator >
void garlic::test_constraints (Layer &&value, Container &&constraints, BackInserterIterator it)
 Run a number of constraints on a layer. More...
 
template<GARLIC_VIEW Layer, typename Container >
static bool garlic::test_constraints_quick (Layer &&value, Container &&constraints)
 
template<GARLIC_VIEW Layer, typename Container >
static ConstraintResult garlic::test_constraints_first_failure (Layer &&value, Container &&constraints)
 
template<typename Tag , typename... Args>
Constraint garlic::make_constraint (Args &&... args) noexcept
 Create a generic Constraint based on a constraint tag. More...
 

Detailed Description

Contains constraints, built-in constraint tags, fields and models.

Function Documentation

◆ make_constraint()

template<typename Tag , typename... Args>
Constraint garlic::make_constraint ( Args &&...  args)
inlinenoexcept

Create a generic Constraint based on a constraint tag.

Template Parameters
Tagany built-in constraint tag that is registered in constraint_registry.
Argsappropriate set of arguments for the constraint tag used.
Note
You will get a compile-time error if you use a tag that is not registered.

◆ test_constraints()

template<GARLIC_VIEW Layer, typename Container , typename BackInserterIterator >
void garlic::test_constraints ( Layer &&  value,
Container &&  constraints,
BackInserterIterator  it 
)
inline

Run a number of constraints on a layer.

Template Parameters
Layerany readable layer that conforms to garlic::ViewLayer concept.
Containerany constainer that stores a number of Constraint items and has begin() and end()
Parameters
ita back inserter iterator to store ConstraintResult items.

◆ test_constraints_first_failure()

template<GARLIC_VIEW Layer, typename Container >
static ConstraintResult garlic::test_constraints_first_failure ( Layer &&  value,
Container &&  constraints 
)
inlinestatic
Returns
the first failed Constraint or return an ok Constraint if all Constraint checks pass.
Template Parameters
Layerany readable layer that conforms to garlic::ViewLayer concept.
Containerany constainer that stores a number of Constraint items and has begin() and end()

◆ test_constraints_quick()

template<GARLIC_VIEW Layer, typename Container >
static bool garlic::test_constraints_quick ( Layer &&  value,
Container &&  constraints 
)
inlinestatic
Returns
whether or not a readable layer passes all constraint tests.
Template Parameters
Layerany readable layer that conforms to garlic::ViewLayer concept.
Containerany constainer that stores a number of Constraint items and has begin() and end()