garlic::Constraint Class Referencefinal

Smallest unit of data validation. More...

#include <constraints.h>

Public Member Functions

 operator bool () const noexcept
 
template<GARLIC_VIEW Layer>
ConstraintResult test (const Layer &value) const noexcept
 Perform the constraint test on the layer and return the result. More...
 
template<GARLIC_VIEW Layer>
bool quick_test (const Layer &value) const noexcept
 Very similar to Constraint::test() but it only returns a boolean. More...
 

Static Public Member Functions

template<typename Tag , typename... Args>
static Constraint make (Args &&... args) noexcept
 Create a generic Constraint based on a constraint tag. More...
 
static Constraint empty () noexcept
 Make a Constraint without any context.
 

Detailed Description

Smallest unit of data validation.

A Constraint is a generic type that can be used to validate any type that conforms to garlic::ViewLayer.

This type cannot be inherited and it does not have public constructors. The proper way to create a Constraint is to use Constraint::make() or its shorthand make_constraint().

If needed, one can define an uninitialized Constraint using Constraint::empty() but this Constraint should not be passed to any other object as it is uninitialized and can lead to crashes or at least undefined behaviors.

Note
You should think of Constraint as a shared pointer to a context data that can be used to instantiate test and quick_test methods when needed. Thus, copying a Constraint does not really deep copy its inside, it creates a new pointer that holds onto the inner context, much like a shared pointer. In fact it does use a shared pointer inside.
auto regex_constriant = garlic::make_constraint<garlic::regex_tag>("\\d");
auto copy = regex_constraint; // uses the same context as regex_constraint.
&copy.context() == &regex_constraint.context(); // true

Member Function Documentation

◆ make()

template<typename Tag , typename... Args>
Constraint garlic::Constraint::make ( Args &&...  args)
staticnoexcept

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.

◆ operator bool()

garlic::Constraint::operator bool ( ) const
inlinenoexcept
Returns
whether or not the constraint is initialized.

◆ quick_test()

template<GARLIC_VIEW Layer>
bool garlic::Constraint::quick_test ( const Layer &  value) const
inlinenoexcept

Very similar to Constraint::test() but it only returns a boolean.

Template Parameters
Layerany readable layer that conforms to the garlic::ViewLayer concept.

◆ test()

template<GARLIC_VIEW Layer>
ConstraintResult garlic::Constraint::test ( const Layer &  value) const
inlinenoexcept

Perform the constraint test on the layer and return the result.

Template Parameters
Layerany readable layer that conforms to the garlic::ViewLayer concept.

The documentation for this class was generated from the following file: