openDAQ
Open data acquisition platform
CoercerPtr Class Reference

Used by openDAQ properties to coerce a value to match the restrictions imposed by the Property. More...

Inherits ObjectPtr< ICoercer >.

Detailed Description

Used by openDAQ properties to coerce a value to match the restrictions imposed by the Property.

Whenever a value is set to on a Property object, if the corresponding Property has a coercer configured, the value will be evaluated and modified to fit the restrictions imposed by the coercer. For example, a coercer can enforce lower-than, greater-than, equality, or other number relations on written values.

The coercion conditions are configured with an evaluation string when the coercer 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 coerce function call. For example, coercers created with the string "if(value > 5, 5, value)" would enforce that the property value is always equal to or lower than 5.

Public Member Functions

daq::BaseObjectPtr coerce (const daq::BaseObjectPtr &propObj, const daq::BaseObjectPtr &value) const
 Coerces value to match the coercion restrictions and outputs the result. More...
 
daq::StringPtr getEval () const
 Gets the string expression used when creating the coercer. More...
 

Member Function Documentation

◆ coerce()

daq::BaseObjectPtr coerce ( const daq::BaseObjectPtr &  propObj,
const daq::BaseObjectPtr &  value 
) const
inline

Coerces value to match the coercion restrictions and outputs the result.

Parameters
propObjOptional property object parameter required if the coercion depends on other properties of the Property object.
valueThe value to be coerced to fit the restrictions.
Returns
The coercer output containing the modified value.
Exceptions
OpendaqErrExceptionif value cannot be coerced to fit the restrictions.
Return values
OPENDAQ_SUCCESSIf the value either already fits the restrictions, or was successfully modified to do so.

◆ getEval()

daq::StringPtr getEval ( ) const
inline

Gets the string expression used when creating the coercer.

Returns
The coercion expression.