Skip to content

Validator

class Validator

@brief The Validator valididates configurations against Schemata

The Validator class validates configurations stored in a Hash against a Schema describing the Hash. If the schema defines default values these are inserted into the Hash, depending on the assignment policy. Validation will either be successful, if the configuration Hash fullfils the requirements specified in the schema, or fail.

Types

Name Description
ValidationRules ValidationRules specify the behavior of the Validator if it encounters differences between the input Hash and the Schema defining it.

Functions

Name Description
Validator Construct a Validator with default, i.e. least-restrictive ValidationRules
Validator Copy constructor will just take over other's validation rules other :
Validator Construct a Validator with given rules rules :
setValidationRules Set the ValidationRules for this Validator rules :
getValidationRules Get the currrent ValidationRules for this Validator Return :
validate Validate an unvalidated input against a schema and write the validated output to a reference.
hasReconfigurableParameter Check if reconfigurable parameters exist in the last provided Schema Return :

Function Details

Validator

Validator()

Construct a Validator with default, i.e. least-restrictive ValidationRules

Validator(const Validator& other)

Copy constructor will just take over other's validation rules

other :

Validator(const ValidationRules rules)

Construct a Validator with given rules

rules :

getValidationRules

Validator::ValidationRules getValidationRules() const

Get the currrent ValidationRules for this Validator

Return :

hasReconfigurableParameter

bool hasReconfigurableParameter() const

Check if reconfigurable parameters exist in the last provided Schema

Return :

setValidationRules

void setValidationRules(const Validator::ValidationRules& rules)

Set the ValidationRules for this Validator

rules :

validate

std::pair<bool, std::string> validate(const Schema& schema, const Hash& unvalidatedInput, Hash& validatedOutput, const Timestamp& timestamp = Timestamp())

Validate an unvalidated input against a schema and write the validated output to a reference. If the rules define to inject timestamp inject the current timestamp or the provided one

schema : against which to validate

unvalidatedInput : which should be validated

validatedOutput : validated and altered according to current ValidationRules

timestamp :

Return : a std::pair where the first entry is a Boolean indicating if validation was successful (true), and the second entry contains a string identifying the first validation failure encountered if validation has failed.

During validation the following input is checked to fulfill the following characteristics

  • all elements as defined by the Schema are present, if the validation rules do not allow for default injection missing keys. In the first case validation of a missing element only passes if a default value for the element has been defined in the schema

  • no elements in addition to those defined by the Schema are present, if the rules define that no additional keys are allowed

  • that the root element of the input Hash stands alone and represents the class id of a factorizable class if an unrooted configuration is not allowed by the validation rules

In addition for the above "sanity" checks, the Validator performs the following tasks:

  • for sequence values validate that they fulfill their minimum and maximum size requirements if defined by the Schema

  • inject timestamps for leaf elements of validatedOutput - details depending on ValidationRules:

  • if injectTimestamps is false: no injection, but timestamp attributes present in unvalidatedInput are transferred to validatedOutput
  • if injectTimestamps is true and forceInjectedTimestamp is false: timestamp is injected, but timestamp attributes present in unvalidatedInput are not overwritten, but are transferred to validatedOutput
  • if injectTimestamps and forceInjectedTimestamp are both true: timestamp is injected even if another timestamp is in attributes of unvalidatedInput