Configuration Validation Rules

Validation rules describe the expected shape and content of a configuration tree. A rule selects a name path and type, then adds attributes such as optionality, defaults, version ranges, dependencies, secrecy, and descriptive metadata. Constraints narrow accepted values with equality, membership, bounds, multiples, character classes, regular expressions, references, and text-part checks.

Rules can be read from a parsed rules document with erbsland::conf::vr::Rules::createFromDocument or built directly in C++ with erbsland::conf::vr::RulesBuilder.

using namespace el::text::literals;
using namespace el::conf::vr;
using namespace el::conf::vr::builder;

RulesBuilder builder;
builder.configureRoot(
    Title{"Server Settings"_el},
    Dependency{
        DependencyMode::XNOR,
        {"server.certificate"_el},
        {"server.signing_key"_el},
        "Certificate and signing key must be configured together."_el});
builder.addRule("server"_el, RuleType::Section);
builder.addRule("server.port"_el, RuleType::Integer, Minimum{1}, Maximum{65535});
builder.addRule("server.certificate"_el, RuleType::Text, IsOptional{});
builder.addRule("server.signing_key"_el, RuleType::Text, IsOptional{}, IsSecret{});
builder.addRule("server.name"_el, RuleType::Text, IsOptional{}, Default{"localhost"_el});
auto rules = builder.takeRules();

rules->validate(document, 1);

Validation follows document order and rule ordering. It can attach rule metadata and insert declared defaults into the validated branch. It throws a validation-category erbsland::conf::ConfError on the first failure. Reuse finalized rules for multiple documents, passing the document version explicitly.

Builder attributes check their compatibility with the selected rule type while rules are finalized. This catches invalid rule definitions before application configuration is validated.

The builder’s implicit root rule represents the document or section passed to Rules::validate(). Use configureRoot() for root metadata, dependencies, key indexes, version restrictions, and other root attributes. DependencyMode is part of the public validation-rule API, so defining cross-value relationships never requires an implementation header.

Rules written as ELCL documents use structural sections for rule definitions and reserved vr_dependency and vr_key section lists for relationships. ELCL documents cannot contain scalar values directly at their document root, so root scalar metadata such as a title is a programmatic-builder feature; dependencies and key indexes work in both forms.

Interface

class Attribute

Base interface for validation-rule builder attributes.

Custom attributes may implement this interface without depending on internal rule types.

Subclassed by erbsland::conf::vr::builder::CaseSensitive, erbsland::conf::vr::builder::ConfVersion, erbsland::conf::vr::builder::ConstraintAttribute, erbsland::conf::vr::builder::CustomError, erbsland::conf::vr::builder::Default, erbsland::conf::vr::builder::Dependency, erbsland::conf::vr::builder::Description, erbsland::conf::vr::builder::IsOptional, erbsland::conf::vr::builder::IsSecret, erbsland::conf::vr::builder::KeyIndex, erbsland::conf::vr::builder::MaximumVersion, erbsland::conf::vr::builder::MinimumVersion, erbsland::conf::vr::builder::Title, erbsland::conf::vr::builder::Type

Public Functions

virtual void apply(RuleDefinition &rule) const = 0

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

inline void operator()(RuleDefinition &rule) const

Apply this attribute using function-call syntax.

Parameters:

rule – The rule definition to modify.

class CaseSensitive : public erbsland::conf::vr::builder::Attribute

Sets the case sensitivity used by the rule.

Public Functions

inline explicit CaseSensitive(const text::CaseSensitivity caseSensitivity = text::CaseSensitivity::CaseSensitive)

Set the case sensitivity for a rule.

Parameters:

caseSensitivity – The requested case sensitivity.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class ConfVersion : public erbsland::conf::vr::builder::Attribute

Restricts a rule to specific versions.

Public Functions

inline explicit ConfVersion(std::vector<Integer> versions, const bool isNegated = false)

Creates a configuration-version attribute from a version list.

Parameters:
  • versions – The accepted configuration versions.

  • isNegatedtrue to reject the listed versions.

inline explicit ConfVersion(const std::initializer_list<Integer> versions, const bool isNegated = false)

Creates a configuration-version attribute from a version list.

Parameters:
  • versions – The accepted configuration versions.

  • isNegatedtrue to reject the listed versions.

inline explicit ConfVersion(const Integer version, const bool isNegated = false)

Creates a configuration-version attribute from one version.

Parameters:
  • version – The accepted configuration version.

  • isNegatedtrue to reject the version.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class CustomError : public erbsland::conf::vr::builder::Attribute

Sets the default validation error message for a rule.

Public Functions

inline explicit CustomError(text::String errorMessage)

Set a custom validation error message.

Parameters:

errorMessage – The message to move into the attribute.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class Default : public erbsland::conf::vr::builder::Attribute

Assigns a default value to a rule.

Public Functions

explicit Default(ValuePtr value)

Creates a default-value attribute from a configuration value.

Parameters:

value – The default configuration value.

explicit Default(Integer value)

Creates an integer default-value attribute.

explicit Default(bool value)

Creates a Boolean default-value attribute.

explicit Default(Float value)

Creates a floating-point default-value attribute.

explicit Default(text::String value)

Creates a text default-value attribute.

explicit Default(const time::Date &value)

Creates a date default-value attribute.

explicit Default(const time::Time &value)

Creates a time default-value attribute.

explicit Default(const time::TimeWithZone &value)

Creates a zoned-time default-value attribute.

explicit Default(const time::DateTime &value)

Creates a date-time default-value attribute.

explicit Default(const mem::ByteBlock &value)

Creates a byte-block default-value attribute.

explicit Default(const time::CalendarDelta &value)

Creates a time-delta default-value attribute.

explicit Default(const re::RegExPtr &value)

Creates a regular-expression default-value attribute.

template<typename TValue>
inline explicit Default(const TValue value)

Creates an integer default-value attribute from a native integer.

template<typename TValue>
inline explicit Default(const TValue value)

Creates a floating-point default-value attribute from a native float.

explicit Default(const std::vector<Integer> &values)

Creates a default-value attribute from integer values.

Parameters:

values – The default integer values.

explicit Default(const std::vector<bool> &values)

Creates a default-value attribute from Boolean values.

Parameters:

values – The default Boolean values.

explicit Default(const std::vector<Float> &values)

Creates a default-value attribute from floating-point values.

Parameters:

values – The default floating-point values.

explicit Default(const text::StringList &values)

Creates a default-value attribute from text values.

Parameters:

values – The default text values.

explicit Default(const std::vector<mem::ByteBlock> &values)

Creates a default-value attribute from byte-block values.

Parameters:

values – The default byte-block values.

explicit Default(const std::vector<std::vector<Integer>> &values)

Creates a default-value attribute from integer matrices.

Parameters:

values – The default integer matrices.

explicit Default(const std::vector<std::vector<Float>> &values)

Creates a default-value attribute from floating-point matrices.

Parameters:

values – The default floating-point matrices.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

inline const ValuePtr &value() const noexcept

Get the represented configuration value.

class Dependency : public erbsland::conf::vr::builder::Attribute

Adds a dependency relation between source and target paths.

Public Functions

inline Dependency(const DependencyMode mode, std::vector<NamePathLike> sources, std::vector<NamePathLike> targets, text::String errorMessage = {})

Creates a dependency relation from path collections.

Parameters:
  • mode – The dependency mode.

  • sources – The source paths.

  • targets – The target paths.

  • errorMessage – The optional validation error message.

inline Dependency(const DependencyMode mode, const std::initializer_list<NamePathLike> sources, const std::initializer_list<NamePathLike> targets, text::String errorMessage = {})

Creates a dependency relation from path lists.

Parameters:
  • mode – The dependency mode.

  • sources – The source paths.

  • targets – The target paths.

  • errorMessage – The optional validation error message.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class Description : public erbsland::conf::vr::builder::Attribute

Sets the descriptive text of a rule.

Public Functions

inline explicit Description(text::String description)

Set descriptive text for a rule.

Parameters:

description – The text to move into the attribute.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class IsOptional : public erbsland::conf::vr::builder::Attribute

Marks a rule as optional or required.

Public Functions

inline explicit IsOptional(const bool isOptional = true)

Set whether a rule is optional.

Parameters:

isOptionaltrue to mark the rule optional.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class IsSecret : public erbsland::conf::vr::builder::Attribute

Marks a rule value as secret.

Public Functions

inline explicit IsSecret(const bool isSecret = true)

Set whether a rule value is secret.

Parameters:

isSecrettrue to mark the value secret.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class KeyIndex : public erbsland::conf::vr::builder::Attribute

Defines an index of key paths that can be referenced by key constraints.

Public Functions

inline explicit KeyIndex(std::vector<NamePathLike> keyPaths, const text::CaseSensitivity caseSensitivity = text::CaseSensitivity::CaseInsensitive)

Creates an unnamed key index.

Parameters:
  • keyPaths – The indexed key paths.

  • caseSensitivity – The key comparison case sensitivity.

inline KeyIndex(Name name, std::vector<NamePathLike> keyPaths, const text::CaseSensitivity caseSensitivity = text::CaseSensitivity::CaseInsensitive)

Creates a named key index.

Parameters:
  • name – The index name.

  • keyPaths – The indexed key paths.

  • caseSensitivity – The key comparison case sensitivity.

inline KeyIndex(const text::String &name, std::vector<NamePathLike> keyPaths, const text::CaseSensitivity caseSensitivity = text::CaseSensitivity::CaseInsensitive)

Creates a named key index from text.

Parameters:
  • name – The regular index name.

  • keyPaths – The indexed key paths.

  • caseSensitivity – The key comparison case sensitivity.

inline explicit KeyIndex(const NamePathLike &keyPath)

Creates an unnamed key index for one path.

Parameters:

keyPath – The indexed key path.

inline KeyIndex(Name name, const NamePathLike &keyPath, const text::CaseSensitivity caseSensitivity = text::CaseSensitivity::CaseInsensitive)

Creates a named key index for one path.

Parameters:
  • name – The index name.

  • keyPath – The indexed key path.

  • caseSensitivity – The key comparison case sensitivity.

inline KeyIndex(const text::String &name, const NamePathLike &keyPath, const text::CaseSensitivity caseSensitivity = text::CaseSensitivity::CaseInsensitive)

Creates a named key index for one path from text.

Parameters:
  • name – The regular index name.

  • keyPath – The indexed key path.

  • caseSensitivity – The key comparison case sensitivity.

inline explicit KeyIndex(const std::initializer_list<NamePathLike> keyPaths, const text::CaseSensitivity caseSensitivity = text::CaseSensitivity::CaseInsensitive)

Creates an unnamed key index from a path list.

Parameters:
  • keyPaths – The indexed key paths.

  • caseSensitivity – The key comparison case sensitivity.

inline KeyIndex(Name name, const std::initializer_list<NamePathLike> keyPaths, const text::CaseSensitivity caseSensitivity = text::CaseSensitivity::CaseInsensitive)

Creates a named key index from a path list.

Parameters:
  • name – The index name.

  • keyPaths – The indexed key paths.

  • caseSensitivity – The key comparison case sensitivity.

inline KeyIndex(const text::String &name, const std::initializer_list<NamePathLike> keyPaths, const text::CaseSensitivity caseSensitivity = text::CaseSensitivity::CaseInsensitive)

Creates a named key index from text and a path list.

Parameters:
  • name – The regular index name.

  • keyPaths – The indexed key paths.

  • caseSensitivity – The key comparison case sensitivity.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class MaximumVersion : public erbsland::conf::vr::builder::Attribute

Restricts a rule to versions smaller than or equal to a maximum.

Public Functions

inline explicit MaximumVersion(const Integer version, const bool isNegated = false)

Set the maximum permitted version.

Parameters:
  • version – The version bound.

  • isNegated – Whether to negate the version condition.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class MinimumVersion : public erbsland::conf::vr::builder::Attribute

Restricts a rule to versions greater than or equal to a minimum.

Public Functions

inline explicit MinimumVersion(const Integer version, const bool isNegated = false)

Set the minimum permitted version.

Parameters:
  • version – The version bound.

  • isNegated – Whether to negate the version condition.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class Title : public erbsland::conf::vr::builder::Attribute

Sets the user-facing title of a rule.

Public Functions

inline explicit Title(text::String title)

Set the user-facing rule title.

Parameters:

title – The title to move into the attribute.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class Type : public erbsland::conf::vr::builder::Attribute

Sets the rule type.

Public Functions

inline explicit Type(const RuleType type)

Set the rule value type.

Parameters:

type – The value type to set.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class Chars : public erbsland::conf::vr::builder::ConstraintAttribute

Adds a character-set constraint for text values.

Public Functions

inline explicit Chars(text::StringList values, ConstraintOptions options = {})

Creates a character-set constraint from allowed characters.

Parameters:
  • values – The allowed characters.

  • options – Additional constraint options.

inline explicit Chars(const text::String &value, ConstraintOptions options = {})

Creates a character-set constraint from one allowed character.

Parameters:
  • value – The allowed character.

  • options – Additional constraint options.

inline explicit Chars(const std::initializer_list<text::String> values, ConstraintOptions options = {})

Creates a character-set constraint from allowed characters.

Parameters:
  • values – The allowed characters.

  • options – Additional constraint options.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class ConfKey : public erbsland::conf::vr::builder::ConstraintAttribute

Adds a key-reference constraint to a named key index.

Public Functions

inline explicit ConfKey(const NamePathLike &reference, ConstraintOptions options = {})

Creates a key-reference constraint for one index path.

Parameters:
  • reference – The referenced index path.

  • options – Additional constraint options.

inline explicit ConfKey(std::vector<NamePathLike> references, ConstraintOptions options = {})

Creates a key-reference constraint for index paths.

Parameters:
  • references – The referenced index paths.

  • options – Additional constraint options.

inline explicit ConfKey(const std::initializer_list<NamePathLike> references, ConstraintOptions options = {})

Creates a key-reference constraint for index paths.

Parameters:
  • references – The referenced index paths.

  • options – Additional constraint options.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class ConstraintAttribute : public erbsland::conf::vr::builder::Attribute

Base interface for builder constraints with common validation helpers.

Subclassed by erbsland::conf::vr::builder::Chars, erbsland::conf::vr::builder::ConfKey, erbsland::conf::vr::builder::Equals, erbsland::conf::vr::builder::In, erbsland::conf::vr::builder::Matches, erbsland::conf::vr::builder::Maximum, erbsland::conf::vr::builder::Minimum, erbsland::conf::vr::builder::Multiple, erbsland::conf::vr::builder::StringPartConstraint

class ConstraintOptions

Optional behavior shared by all builder constraints.

Public Functions

text::String prefixedConstraintName(const text::String &constraintName) const

Return the constraint name including its negation prefix when configured.

void addToRule(RuleDefinition &rule, const vr::ConstraintPtr &constraint, const text::String &constraintName) const

Add a configured constraint to a rule.

class Contains : public erbsland::conf::vr::builder::StringPartConstraint

Adds a contains text constraint.

Public Functions

inline explicit Contains(text::StringList values, ConstraintOptions options = {})

Creates a contains constraint from expected text parts.

Parameters:
  • values – The expected text parts.

  • options – Additional constraint options.

inline explicit Contains(const text::String &value, ConstraintOptions options = {})

Creates a contains constraint from one expected text part.

Parameters:
  • value – The expected text part.

  • options – Additional constraint options.

inline explicit Contains(const std::initializer_list<text::String> values, ConstraintOptions options = {})

Creates a contains constraint from expected text parts.

Parameters:
  • values – The expected text parts.

  • options – Additional constraint options.

class Ends : public erbsland::conf::vr::builder::StringPartConstraint

Adds an ends-with text constraint.

Public Functions

inline explicit Ends(text::StringList values, ConstraintOptions options = {})

Creates an ends-with constraint from expected suffixes.

Parameters:
  • values – The expected suffixes.

  • options – Additional constraint options.

inline explicit Ends(const text::String &value, ConstraintOptions options = {})

Creates an ends-with constraint from one expected suffix.

Parameters:
  • value – The expected suffix.

  • options – Additional constraint options.

inline explicit Ends(const std::initializer_list<text::String> values, ConstraintOptions options = {})

Creates an ends-with constraint from expected suffixes.

Parameters:
  • values – The expected suffixes.

  • options – Additional constraint options.

class Equals : public erbsland::conf::vr::builder::ConstraintAttribute

Adds an equality constraint for scalar values or matrix size.

Public Functions

template<typename TValue>
inline explicit Equals(const TValue value, ConstraintOptions options = {})

Creates an integer equality constraint.

Template Parameters:

TValue – An integer type.

Parameters:
  • value – The expected value.

  • options – Additional constraint options.

inline explicit Equals(const bool value, ConstraintOptions options = {})

Creates a Boolean equality constraint.

Parameters:
  • value – The expected value.

  • options – Additional constraint options.

template<typename TValue>
inline explicit Equals(const TValue value, ConstraintOptions options = {})

Creates a floating-point equality constraint.

Template Parameters:

TValue – A floating-point type.

Parameters:
  • value – The expected value.

  • options – Additional constraint options.

inline explicit Equals(const text::String &value, ConstraintOptions options = {})

Creates a text equality constraint.

Parameters:
  • value – The expected value.

  • options – Additional constraint options.

inline explicit Equals(const mem::ByteBlock &value, ConstraintOptions options = {})

Creates a byte-block equality constraint.

Parameters:
  • value – The expected value.

  • options – Additional constraint options.

inline explicit Equals(const std::pair<Integer, Integer> value, ConstraintOptions options = {})

Creates a matrix-size equality constraint.

Parameters:
  • value – The expected row and column counts.

  • options – Additional constraint options.

inline Equals(const Integer first, const Integer second, ConstraintOptions options = {})

Creates a matrix-size equality constraint.

Parameters:
  • first – The expected first dimension.

  • second – The expected second dimension.

  • options – Additional constraint options.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class In : public erbsland::conf::vr::builder::ConstraintAttribute

Adds an inclusion constraint for a list of values.

Public Functions

inline explicit In(std::vector<Integer> values, ConstraintOptions options = {})

Creates an integer inclusion constraint.

Parameters:
  • values – The allowed integer values.

  • options – Additional constraint options.

inline explicit In(std::vector<Float> values, ConstraintOptions options = {})

Creates a floating-point inclusion constraint.

Parameters:
  • values – The allowed floating-point values.

  • options – Additional constraint options.

inline explicit In(text::StringList values, ConstraintOptions options = {})

Creates a string inclusion constraint.

Parameters:
  • values – The allowed strings.

  • options – Additional constraint options.

inline explicit In(std::vector<mem::ByteBlock> values, ConstraintOptions options = {})

Creates a byte-block inclusion constraint.

Parameters:
  • values – The allowed byte blocks.

  • options – Additional constraint options.

inline explicit In(const std::initializer_list<Integer> values, ConstraintOptions options = {})

Creates an integer inclusion constraint.

Parameters:
  • values – The allowed integer values.

  • options – Additional constraint options.

inline explicit In(const std::initializer_list<Float> values, ConstraintOptions options = {})

Creates a floating-point inclusion constraint.

Parameters:
  • values – The allowed floating-point values.

  • options – Additional constraint options.

inline explicit In(const std::initializer_list<text::String> values, ConstraintOptions options = {})

Creates a string inclusion constraint.

Parameters:
  • values – The allowed strings.

  • options – Additional constraint options.

inline explicit In(const std::initializer_list<mem::ByteBlock> values, ConstraintOptions options = {})

Creates a byte-block inclusion constraint.

Parameters:
  • values – The allowed byte blocks.

  • options – Additional constraint options.

template<typename TValue>
inline explicit In(const TValue value, ConstraintOptions options = {})

Creates an integer inclusion constraint.

Parameters:
  • value – The allowed integer value.

  • options – Additional constraint options.

template<typename TValue>
inline explicit In(const TValue value, ConstraintOptions options = {})

Creates a floating-point inclusion constraint.

Parameters:
  • value – The allowed floating-point value.

  • options – Additional constraint options.

inline explicit In(const text::String &value, ConstraintOptions options = {})

Creates a string inclusion constraint.

Parameters:
  • value – The allowed string.

  • options – Additional constraint options.

inline explicit In(const mem::ByteBlock &value, ConstraintOptions options = {})

Creates a byte-block inclusion constraint.

Parameters:
  • value – The allowed byte block.

  • options – Additional constraint options.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class Matches : public erbsland::conf::vr::builder::ConstraintAttribute

Adds a regular-expression constraint for text values.

Public Functions

inline explicit Matches(const text::String &pattern, const bool isVerbose = false, ConstraintOptions options = {})

Creates a regular-expression constraint from a pattern.

Parameters:
  • pattern – The regular-expression pattern.

  • isVerbosetrue to enable verbose pattern syntax.

  • options – Additional constraint options.

inline explicit Matches(re::RegExPtr pattern, ConstraintOptions options = {})

Creates a regular-expression constraint from a compiled expression.

Parameters:
  • pattern – The compiled regular expression.

  • options – Additional constraint options.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class Maximum : public erbsland::conf::vr::builder::ConstraintAttribute

Adds a maximum boundary constraint for numeric or temporal values.

Public Functions

template<typename TValue>
inline explicit Maximum(const TValue value, ConstraintOptions options = {})

Creates an integer maximum constraint.

Template Parameters:

TValue – An integer type.

Parameters:
  • value – The maximum value.

  • options – Additional constraint options.

template<typename TValue>
inline explicit Maximum(const TValue value, ConstraintOptions options = {})

Creates a floating-point maximum constraint.

Template Parameters:

TValue – A floating-point type.

Parameters:
  • value – The maximum value.

  • options – Additional constraint options.

inline explicit Maximum(const time::Date &value, ConstraintOptions options = {})

Creates a date maximum constraint.

Parameters:
  • value – The maximum date.

  • options – Additional constraint options.

inline explicit Maximum(const time::DateTime &value, ConstraintOptions options = {})

Creates a date-time maximum constraint.

Parameters:
  • value – The maximum date and time.

  • options – Additional constraint options.

inline explicit Maximum(const std::pair<Integer, Integer> value, ConstraintOptions options = {})

Creates a matrix-size maximum constraint.

Parameters:
  • value – The maximum row and column counts.

  • options – Additional constraint options.

inline Maximum(const Integer first, const Integer second, ConstraintOptions options = {})

Creates a matrix-size maximum constraint.

Parameters:
  • first – The maximum first dimension.

  • second – The maximum second dimension.

  • options – Additional constraint options.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class Minimum : public erbsland::conf::vr::builder::ConstraintAttribute

Adds a minimum boundary constraint for numeric or temporal values.

Public Functions

template<typename TValue>
inline explicit Minimum(const TValue value, ConstraintOptions options = {})

Creates an integer minimum constraint.

Template Parameters:

TValue – An integer type.

Parameters:
  • value – The minimum value.

  • options – Additional constraint options.

template<typename TValue>
inline explicit Minimum(const TValue value, ConstraintOptions options = {})

Creates a floating-point minimum constraint.

Template Parameters:

TValue – A floating-point type.

Parameters:
  • value – The minimum value.

  • options – Additional constraint options.

inline explicit Minimum(const time::Date &value, ConstraintOptions options = {})

Creates a date minimum constraint.

Parameters:
  • value – The minimum date.

  • options – Additional constraint options.

inline explicit Minimum(const time::DateTime &value, ConstraintOptions options = {})

Creates a date-time minimum constraint.

Parameters:
  • value – The minimum date and time.

  • options – Additional constraint options.

inline explicit Minimum(const std::pair<Integer, Integer> value, ConstraintOptions options = {})

Creates a matrix-size minimum constraint.

Parameters:
  • value – The minimum row and column counts.

  • options – Additional constraint options.

inline Minimum(const Integer first, const Integer second, ConstraintOptions options = {})

Creates a matrix-size minimum constraint.

Parameters:
  • first – The minimum first dimension.

  • second – The minimum second dimension.

  • options – Additional constraint options.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class Multiple : public erbsland::conf::vr::builder::ConstraintAttribute

Adds a multiple-of constraint for scalar values or matrix size.

Public Functions

template<typename TValue>
inline explicit Multiple(const TValue value, ConstraintOptions options = {})

Creates an integer multiple-of constraint.

Template Parameters:

TValue – An integer type.

Parameters:
  • value – The required divisor.

  • options – Additional constraint options.

template<typename TValue>
inline explicit Multiple(const TValue value, ConstraintOptions options = {})

Creates a floating-point multiple-of constraint.

Template Parameters:

TValue – A floating-point type.

Parameters:
  • value – The required divisor.

  • options – Additional constraint options.

inline explicit Multiple(const std::pair<Integer, Integer> value, ConstraintOptions options = {})

Creates a matrix-dimension multiple-of constraint.

Parameters:
  • value – The required row and column divisors.

  • options – Additional constraint options.

inline Multiple(const Integer rows, const Integer columns, ConstraintOptions options = {})

Creates a matrix-dimension multiple-of constraint.

Parameters:
  • rows – The required row divisor.

  • columns – The required column divisor.

  • options – Additional constraint options.

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class Starts : public erbsland::conf::vr::builder::StringPartConstraint

Adds a starts-with text constraint.

Public Functions

inline explicit Starts(text::StringList values, ConstraintOptions options = {})

Creates a starts-with constraint from expected prefixes.

Parameters:
  • values – The expected prefixes.

  • options – Additional constraint options.

inline explicit Starts(const text::String &value, ConstraintOptions options = {})

Creates a starts-with constraint from one expected prefix.

Parameters:
  • value – The expected prefix.

  • options – Additional constraint options.

inline explicit Starts(const std::initializer_list<text::String> values, ConstraintOptions options = {})

Creates a starts-with constraint from expected prefixes.

Parameters:
  • values – The expected prefixes.

  • options – Additional constraint options.

class StringPartConstraint : public erbsland::conf::vr::builder::ConstraintAttribute

Shared value storage for string-part constraint attributes.

Subclassed by erbsland::conf::vr::builder::Contains, erbsland::conf::vr::builder::Ends, erbsland::conf::vr::builder::Starts

Public Functions

virtual void apply(RuleDefinition &rule) const override

Apply this attribute to a rule under construction.

Parameters:

rule – The rule definition to modify.

class RuleDefinition

Stable mutation interface used while a validation rule is being built.

Instances are owned by RulesBuilder; attributes may only modify the rule passed to Attribute::apply().

Subclassed by erbsland::conf::impl::Rule

Public Functions

virtual RuleType type() const = 0

Get the configured rule type.

virtual text::CaseSensitivity caseSensitivity() const = 0

Get the configured case sensitivity.

virtual void setType(RuleType type) = 0

Set the configured rule type.

Parameters:

type – The new rule type.

virtual void setTitle(text::String title) = 0

Set the user-facing title.

Parameters:

title – The new title.

virtual void setDescription(text::String description) = 0

Set the descriptive text.

Parameters:

description – The new description.

virtual void setErrorMessage(text::String errorMessage) = 0

Set the custom validation error message.

Parameters:

errorMessage – The new error message.

virtual void setOptional(bool isOptional) = 0

Set whether the validated value is optional.

Parameters:

isOptionaltrue if the value may be omitted.

virtual void setCaseSensitivity(text::CaseSensitivity caseSensitivity) = 0

Set how text constraints compare characters.

Parameters:

caseSensitivity – The comparison mode.

virtual void setSecret(bool isSecret) = 0

Set whether the validated value contains secret data.

Parameters:

isSecrettrue if diagnostics must protect the value.

virtual void setDefaultValue(const ValuePtr &value) = 0

Set the default value.

Parameters:

value – The default configuration value.

virtual void addConstraint(const ConstraintPtr &constraint, text::String name, bool isNegated, text::String errorMessage) = 0

Add a constraint, replacing an existing constraint of the same type.

Parameters:
  • constraint – The constraint implementation created by a builder attribute.

  • name – The public constraint name without a negation prefix.

  • isNegated – Whether to negate the constraint.

  • errorMessage – An optional custom validation error.

virtual void addDependency(DependencyMode mode, const std::vector<NamePathLike> &sources, const std::vector<NamePathLike> &targets, text::String errorMessage) = 0

Add a dependency relation to this rule.

Parameters:
  • mode – The relation between sources and targets.

  • sources – The source paths relative to this rule.

  • targets – The target paths relative to this rule.

  • errorMessage – An optional custom validation error.

virtual void addKeyIndex(const Name &name, const std::vector<NamePathLike> &keyPaths, text::CaseSensitivity caseSensitivity) = 0

Add a key index to this rule.

Parameters:
  • name – The optional index name.

  • keyPaths – The indexed paths relative to this rule.

  • caseSensitivity – The key comparison mode.

virtual void limitVersions(const std::vector<Integer> &versions, bool isNegated) = 0

Restrict this rule to the listed versions or their complement.

Parameters:
  • versions – The configuration versions to select.

  • isNegatedtrue to select the complement.

virtual void limitMinimumVersion(Integer version, bool isNegated) = 0

Restrict this rule to versions at or above the boundary, or its complement.

Parameters:
  • version – The inclusive lower boundary.

  • isNegatedtrue to select versions below the boundary.

virtual void limitMaximumVersion(Integer version, bool isNegated) = 0

Restrict this rule to versions at or below the boundary, or its complement.

Parameters:
  • version – The inclusive upper boundary.

  • isNegatedtrue to select versions above the boundary.

class Constraint

A constraint for a validation-rule.

Subclassed by erbsland::conf::impl::Constraint

Public Functions

virtual text::String name() const = 0

The name.

virtual ConstraintType type() const = 0

The type.

virtual bool hasCustomError() const = 0

Test if a custom error message set.

virtual text::String customError() const = 0

The custom error message.

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 const Location &location() const noexcept = 0

Get the location info.

virtual void setLocation(const Location &newLocation) noexcept = 0

Set the location info.

class ConstraintType

Value object representing a constraint type.

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.

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

const text::String &toText() const noexcept

Convert this type into text.

inline constexpr Enum raw() const noexcept

Access the underlying enum value.

Public Static Functions

static ConstraintType fromText(const text::String &text) noexcept

Create a validation type from a given text.

Returns:

The validation type or Undefined if the text does not match any valid type.

static inline const std::array<ConstraintType, 15> &all() noexcept

Get an array with all value types.

class DependencyMode

The relationship enforced between source and target values of a dependency.

Public Functions

DependencyMode() = default

Create an undefined dependency mode.

inline DependencyMode(const Enum value)

Create a dependency mode from an enum value.

Parameters:

value – The enum value.

inline DependencyMode &operator=(const Enum value) noexcept

Assign an enum value.

bool isValid(bool hasSource, bool hasTarget) const noexcept

Test whether a source/target presence combination satisfies this mode.

Parameters:
  • hasSourcetrue if at least one source value exists.

  • hasTargettrue if at least one target value exists.

Returns:

true if the combination is accepted.

const text::String &toText() const noexcept

Convert this mode into its ELCL identifier.

inline constexpr Enum raw() const noexcept

Access the underlying enum value.

Public Static Functions

static DependencyMode fromText(const text::String &text) noexcept

Parse an ELCL dependency-mode identifier.

Parameters:

text – The identifier to parse.

Returns:

The parsed mode, or Undefined for unsupported input.

class Rule

Base interface for a validation rule.

Subclassed by erbsland::conf::impl::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 RuleType type() const = 0

The type of the rule.

virtual text::String title() const = 0

An optional title.

virtual text::String description() const = 0

An optional description.

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 text::String customError() const = 0

A custom error message for the rule.

virtual std::vector<ConstraintPtr> constraints() const = 0

A list of constraints.

virtual bool isOptional() const = 0

If this rule is optional.

virtual text::CaseSensitivity caseSensitivity() const = 0

If constraints are tested case-sensitive.

virtual bool isSecret() const = 0

If the validated value is a secret.

virtual std::vector<RulePtr> children() const = 0

A list of child rules.

virtual bool hasLocation() const noexcept = 0

Test if there is location info.

virtual const Location &location() const noexcept = 0

Get the location info.

virtual void setLocation(const Location &newLocation) noexcept = 0

Set the location info.

class Rules

A set of validation rules.

Subclassed by erbsland::conf::impl::Rules

Public Functions

virtual void validate(const ValuePtr &value, Integer version) = 0

Validate a document or document branch against these rules.

Validation of the values also assigns additional meta-data to the values. Missing values with defaults are added to the validated branch.

Parameters:
  • value – The value or document to validate.

  • version – The version of the document to validate.

Throws:

ConfError – (Validation) On any validation error.

Public Static Functions

static RulesPtr createFromDocument(const DocumentPtr &document)

Create and validate rules from a rules-definition document.

This reads all rules from the given document and validates the resulting rules definition. If the document contains any errors, an exception is thrown.

Parameters:

document – The document to read rules from.

Throws:

ConfError – (Validation) on any error found in the document or rule definition.

Returns:

The finalized rules definition.

class RulesBuilder

A builder to create validation rules programmatically.

Public Functions

RulesBuilder()

Create an empty validation-rule builder.

~RulesBuilder()

Destroy the private builder implementation.

template<typename ...Attributes>
inline void configureRoot(Attributes... attributes)

Configure attributes of the implicit root section rule.

Template Parameters:

Attributes – Builder-attribute types.

Parameters:

attributes – All attributes for the root rule definition.

template<typename ...Attributes>
inline void addRule(const NamePathLike &namePath, const RuleType ruleType, Attributes... attributes)

Add a rule to the document.

Template Parameters:

Attributes – Builder-attribute types.

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.

Template Parameters:

Attributes – Builder-attribute types.

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:

ConfError – (Validation) on any logical error found. E.g. missing key references.

Returns:

The finalized rules document.

class RuleType

Represents the type accepted by a validation rule.

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.

Operators

inline RuleType &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.

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.

bool matchesValueType(ValueType valueType) const noexcept

Test if this rule type matches a value type.

Public Functions

const text::String &toText() const noexcept

Convert this type into text.

ValueType toValueType() const noexcept

Convert this type into a value type.

const text::String &expectedValueTypeText() const noexcept

Get the expected type text for this rule type.

inline constexpr Enum raw() const noexcept

Access the underlying enum value.

Public Static Functions

static RuleType fromText(const text::String &text) noexcept

Create a validation type from a given text.

Returns:

The validation type or Undefined if the text does not match any valid type.

static const std::array<RuleType, 19> &all() noexcept

Get an array with all value types.