Validation Rules
Tutorials
Use Validation-Rules as Embedded ELCL Document - Define validation rules from an embedded ELCL document.
Use Validation-Rules Built from Code - Build validation rules directly in C++ with
RulesBuilder.
Interface
-
class RulesBuilder
A builder to create validation rules programmatically.
Public Functions
-
template<typename ...Attributes>
inline void addRule(const NamePathLike &namePath, const RuleType ruleType, Attributes... attributes) Add a rule to the document.
- Parameters:
namePath – The name-path of the new rule.
ruleType – The type of the new rule.
attributes – All the attributes for the rule definition.
-
template<typename ...Attributes>
inline void addAlternative(const NamePathLike &namePath, const RuleType ruleType, Attributes... attributes) Add an alternative to the document.
- Parameters:
namePath – The name-path of the new rule.
ruleType – The type of the new rule.
attributes – All the attributes for the rule definition.
-
void reset()
Reset the builder and discard the current rules.
-
RulesPtr takeRules()
Finalize the rules document and return the rules.
This will finalize the currently processed rules document and return it to the caller. The builder is reset afterward and can be reused to create a new rules document.
If errors are found while finalizing the rules document, an exception is thrown.
- Throws:
Error – (Validation) on any logical error found. E.g. missing key references.
- Returns:
The finalized rules document.
-
template<typename ...Attributes>
-
class Rule
Public Functions
-
virtual NamePath namePath() const = 0
The target name-path of this rule.
This is the name path of the value in the validated document.
-
virtual bool hasDefault() const = 0
If this rule has a default.
-
virtual bool hasCustomError() const = 0
Test if this rule has a custom error message.
-
virtual std::vector<ConstraintPtr> constraints() const = 0
A list of constraints.
-
virtual bool isOptional() const = 0
If this rule is optional.
-
virtual CaseSensitivity caseSensitivity() const = 0
If constraints are tested case-sensitive.
-
virtual bool isSecret() const = 0
If the validated value is a secret.
-
virtual bool hasLocation() const noexcept = 0
Test if there is location info.
-
virtual NamePath namePath() const = 0
-
class RuleType
Construction and Assignment
-
RuleType() = default
Create an undefined value type.
-
inline RuleType(const Enum value)
Create a new value type.
- Parameters:
value – The enum value.
-
~RuleType() = default
Default destructor.
Operators
-
inline constexpr operator Enum() const noexcept
Cast back to the enum value.
Tests
-
inline constexpr bool isUndefined() const noexcept
Test if the type is undefined.
-
inline bool isList() const noexcept
Test if this type represents any kind of list.
-
inline bool isScalar() const noexcept
Test if this type represents a scalar value.
-
inline bool acceptsDefaults() const noexcept
Test if this rule type accepts defaults.
-
RuleType() = default
-
class Constraint
A constraint for a validation-rule.
Public Functions
-
virtual ConstraintType type() const = 0
The type.
-
virtual bool hasCustomError() const = 0
Test if a custom error message set.
-
virtual bool isNegated() const = 0
If the result of this constraint test is negated.
-
virtual bool hasLocation() const noexcept = 0
Test if there is location info.
-
virtual ConstraintType type() const = 0
-
using erbsland::conf::vr::ConstraintPtr = std::shared_ptr<Constraint>
-
class ConstraintType
Construction and Assignment
-
ConstraintType() = default
Create an undefined value type.
-
inline ConstraintType(const Enum value)
Create a new value type.
- Parameters:
value – The enum value.
-
ConstraintType(const ConstraintType&) = default
Default copy constructor.
-
~ConstraintType() = default
Default destructor.
-
ConstraintType &operator=(const ConstraintType&) = default
Default copy assignment.
Operators
-
inline ConstraintType &operator=(const Enum value) noexcept
Assign an enum.
-
inline constexpr operator Enum() const noexcept
Cast back to the enum value.
Tests
-
inline constexpr bool isUndefined() const noexcept
Test if the type is undefined.
Public Functions
-
inline constexpr Enum raw() const noexcept
Access the underlying enum value.
Public Static Functions
-
static ConstraintType fromText(const String &text) noexcept
Create a validation type from a given text.
- Returns:
The validation type or
Undefinedif the text does not match any valid type.
-
static inline const std::array<ConstraintType, 15> &all() noexcept
Get an array with all value types.
-
ConstraintType() = default