openDAQ
Open data acquisition platform
ValidatorPtr Class Reference

Used by openDAQ properties to validate whether a value fits the value restrictions of the Property. More...

Inherits ObjectPtr< IValidator >.

Detailed Description

Used by openDAQ properties to validate whether a value fits the value restrictions of the Property.

Whenever a value is set to on a Property object, if the corresponding Property has a validator configured, the value will be validated, throwing a validation error, if the value is not compliant with the validation restrictions. For example, a validator can check the written value for lower-than, greater-than, equality, or other number relations.

The validation conditions are configured with an evaluation string when the validator is constructed. The string constructs an Eval value that replaces any instance of the keyword "value" or "val" with the value being set. The result of the Eval value evaluation is the output of the validate function call. For example, validators created with the string "value == 5" would reject any value that is not equal to 5.

Public Member Functions

void validate (const daq::BaseObjectPtr &propObj, const daq::BaseObjectPtr &value) const
 Checks whether value adheres to the validity conditions of the validator. More...
 
daq::StringPtr getEval () const
 Gets the string expression used when creating the validator. More...
 

Member Function Documentation

◆ getEval()

daq::StringPtr getEval ( ) const
inline

Gets the string expression used when creating the validator.

Returns
The validation expression.

◆ validate()

void validate ( const daq::BaseObjectPtr &  propObj,
const daq::BaseObjectPtr &  value 
) const
inline

Checks whether value adheres to the validity conditions of the validator.

Parameters
propObjOptional property object parameter required if the validation depends on other properties of the Property object.
valueThe value to be checked for whether it is valid or not.
Exceptions
ValidateFailedExceptionif value is invalid.
Return values
OPENDAQ_SUCCESSif value is valid.