• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - Automation
  • Evaluate
  • 5.0.0

Evaluate Class

(Automation::Evaluate)

A mathematical expression evaluation operator. More...

Header: #include <Evaluate>
Inherits: CDPOperator<T>
  • List of all members, including inherited members

Public Functions

Evaluate(const CDPPropertyBase &in)
virtual ~Evaluate()

Reimplemented Public Functions

virtual bool AddChild(const std::string &name, const std::string &typeName, const std::string &configuration) override
virtual void Configure(XMLPrimitive *operatorXML) override
virtual void Create(const char *shortName, CDPBaseObject *pParent) override
virtual unsigned int Process() override
virtual bool RemoveChild(const std::string &name) override
  • 18 public functions inherited from CDPOperator
  • 17 public functions inherited from CDPOperatorBase
  • 49 public functions inherited from CDPBaseObject
  • 27 public functions inherited from CDP::StudioAPI::CDPNode
  • 22 public functions inherited from CDP::StudioAPI::ICDPNode

Additional Inherited Members

  • 1 public variable inherited from CDPOperatorBase
  • 1 static public member inherited from CDPBaseObject
  • 1 protected function inherited from CDP::StudioAPI::CDPNode
  • 8 protected variables inherited from CDPOperator
  • 5 protected variables inherited from CDPOperatorBase
  • 10 protected variables inherited from CDPBaseObject

Detailed Description

A mathematical expression evaluation operator.

This CDP operator can be used to modify input value based on complex mathematical expressions with unlimited number of arguments.

Properties

PropertyDescription
ExpressionMathematical expression to evaluate. 13 mathematical operators, ternary operator and 25 different functions are supported.

Arguments

ArgumentDescription
InputThe default input value.
OutThe default output value.
Unlimited number of arguments with any name except "Input"Arguments to use in calculation. Argument with name "Input" is reserved and can be used to include in expression with default input value before evaluation.

Evaluate operator arguments can be routed from another signal, parameter or property.

The power of the Evaluate operator

The Evaluate operator is a very powerful and flexible operator that can be used to do complex signal arithmetic without any C++ programming. Just add the named arguments to the Evaluate operator (values to the arguments can be routed from signals, properties or parameters) and specify the mathematical expression to calculate the output value. In every processing cycle this evaluation expression (that can refer to any of the named arguments in any combination) is used, and output value is calculated based on that.

Just to illustrate the power of Evaluate operator, below are examples how it can be used instead of many other, specialized CDP operators:

CDP operatorEvaluate operator Expression that can be used instead
AddOperatorInput + Argument1 + Argument2 + Argument3
SubOperatorInput - Argument1 - Argument2 - Argument3
MulOperatorInput * Argument1 * Argument2 * Argument3
DivOperatorInput / Argument1 / Argument2 / Argument3
ForceOperatorForceActive ? ForceValue : Input
InvertOperator<bool>Input == 0 ? 1 : 0
MinMaxLimitermax(min(Input, Max), Min)
or
Input > Max ? Max : ( Input < Min ? Min : Input )
NormalPositionOperator<bool>NormalPosition==0 ? Input : (Input==0 ? 1 : 0)

Note: The power and flexibility of the Evaluate operator does not come without cost. The Evaluate operator requires much more computing power than other specialized operators. Consider using specialized operators instead of the Evaluate operator if your system CPU power is very limited. Or alternatively, you can create your own custom operator (via Library->Add New Operator wizard) and program needed functionality in C++.

Example

Below is an example plot with Sine signal (cyan) and the same signal with Evaluate operator with property parameters:

ArgumentValue
A-0.1
B2
Evaluate ExpressionInput >A ? Input + 0.2 : (Input - 0.1) ^ B

Mathematical operators supported by Evaluate

OperatorDescriptionPriority
&&logical and1
||logical or2
<=less or equal4
>=greater or equal4
!=not equal4
==equal4
<less than4
>greater than4
+addition5
-subtraction5
*multiplication6
/division6
^raise x to the power of y7

Ternary Operator

Evaluate supports the "if then else" operator. It uses lazy evaluation in order to make sure only the necessary branch of the expression is evaluated.

OperatorDescriptionRemarks
?:if then else operatorC++ style syntax

Mathematical functions supported by Evaluate

Function# of argumentsExplanation
sin1sine function
cos1cosine function
tan1tangens function
asin1arcus sine function
acos1arcus cosine function
atan1arcus tangens function
sinh1hyperbolic sine function
cosh1hyperbolic cosine
tanh1hyperbolic tangens function
asinh1hyperbolic arcus sine function
acosh1hyperbolic arcus tangens function
atanh1hyperbolic arcus tangens function
log21logarithm to the base 2
log101logarithm to the base 10
log1logarithm to base e (2.71828...)
ln1logarithm to base e (2.71828...)
exp1e raised to the power of x
sqrt1square root of a value
sign1sign function -1 if < 0; 1 if > 0
rint1round to nearest integer
abs1absolute value
minunlimitedmin of all arguments
maxunlimitedmax of all arguments
sumunlimitedsum of all arguments
avgunlimitedmean value of all arguments
_pi0the value of PI (3.141592653589793238462643)
_e0Euler's number (2.718281828459045235360287)

When operator is used inside a signal its default input is automatically tied to signal's InternalValue or previous operator's output. Its default output is automatically tied to next operator's input or to signal's Value. See also CDP Operator Usage In CDP Signals.

Actual Processing Code of the Evaluate

unsigned int Evaluate<T>::Process()
{
  if (m->parserOk)
  {
    try
    {
      m->inputVal = static_cast<double>(m_input);
      for (size_t i=0; i < m_arguments.size(); i++)
        m->argVals[i] = static_cast<double>(*m_arguments[i]);
      m_output = m->mp.Eval();
    }
    catch (Parser::exception_type &e)
    {
      GetParent()->ReportConfigurationFault(this, "Can not evaluate expression '" + e.GetExpr() + "': " + e.GetMsg());
      m->faultReported = true;
      return STATUS_SIGNAL_FAULT;
    }
    if (m->faultReported)
    {
      GetParent()->ClearConfigurationFault(this);
      m->faultReported = false;
    }
    return STATUS_OK;
  }
  return STATUS_SIGNAL_FAULT;
}

See also Argument.

Member Function Documentation

Evaluate::Evaluate(const CDPPropertyBase &in)

Constructs a Evaluate with input in.

[virtual] Evaluate::~Evaluate()

Destructs the Evaluate operator

[override virtual] bool Evaluate::AddChild(const std::string &name, const std::string &typeName, const std::string &configuration)

[override virtual] void Evaluate::Configure(XMLPrimitive *operatorXML)

Reimplemented from CDPBaseObject::Configure().

Configure arguments and then create muParser variable array based on them and also "Input" variable Do this once in Configure() instead of Process() for speed (as argument count and names can not change at runtime).

[override virtual] void Evaluate::Create(const char *shortName, CDPBaseObject *pParent)

Reimplemented from CDPBaseObject::Create().

[override virtual] unsigned int Evaluate::Process()

Reimplemented from CDPOperatorBase::Process().

Value "Input" variable and all arguments, expression string and then let muParser calculate the output value. Also catch muParser evaluation errors and report them to parent component.

[override virtual] bool Evaluate::RemoveChild(const std::string &name)

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top