cExpression Class Reference

API: cExpression Class Reference
API
cExpression Class Referenceabstract
Inheritance diagram for cExpression:
[legend]

Classes

class  Context
 Contextual information for evaluating the expression. More...

Public Member Functions

Constructors, destructor, assignment.
 cExpression ()
 cExpression (const cExpression &other)=default
virtual ~cExpression ()
cExpressionoperator= (const cExpression &other)
virtual cExpressiondup () const =0
virtual std::string str () const
Evaluator methods.
virtual cValue evaluate (Context *context) const =0
virtual bool boolValue (Context *context) const =0
virtual intval_t intValue (Context *context, const char *expectedUnit=nullptr) const =0
virtual double doubleValue (Context *context, const char *expectedUnit=nullptr) const =0
virtual std::string stringValue (Context *context) const =0
virtual cXMLElementxmlValue (Context *context) const =0
virtual cValue evaluate (cComponent *contextComponent=nullptr) const
virtual bool boolValue (cComponent *contextComponent=nullptr) const
virtual intval_t intValue (cComponent *contextComponent=nullptr, const char *expectedUnit=nullptr) const
virtual double doubleValue (cComponent *contextComponent=nullptr, const char *expectedUnit=nullptr) const
virtual std::string stringValue (cComponent *contextComponent=nullptr) const
virtual cXMLElementxmlValue (cComponent *contextComponent=nullptr) const
Miscellaneous utility functions.
virtual void parse (const char *text)=0
virtual int compare (const cExpression *other) const =0
virtual bool isAConstant () const
virtual std::string getSourceLocation () const =0

Description

Abstract base class for expression evaluators.

See also
cPar

Constructor & Destructor Documentation

◆ cExpression() [1/2]

◆ cExpression() [2/2]

cExpression ( const cExpression & other)
default

Copy constructor.

References cExpression().

◆ ~cExpression()

virtual ~cExpression ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ operator=()

cExpression & operator= ( const cExpression & other)
inline

Assignment operator.

References cExpression().

◆ dup()

virtual cExpression * dup ( ) const
pure virtual

Duplication.

Implemented in cDynamicExpression, and cOwnedDynamicExpression.

References cExpression().

◆ str()

virtual std::string str ( ) const
inlinevirtual

Converts the expression to string.

Reimplemented in cDynamicExpression, and cOwnedDynamicExpression.

◆ evaluate() [1/2]

virtual cValue evaluate ( Context * context) const
pure virtual

Evaluate the expression and return the result in a cValue. The context parameter cannot be nullptr.

Implemented in cDynamicExpression.

Referenced by cDynamicExpression::xmlValue().

◆ boolValue() [1/2]

virtual bool boolValue ( Context * context) const
pure virtual

Evaluate the expression and convert the result to bool if possible; throw an error if conversion from that type is not supported.

Implemented in cDynamicExpression.

Referenced by cDynamicExpression::xmlValue().

◆ intValue() [1/2]

virtual intval_t intValue ( Context * context,
const char * expectedUnit = nullptr ) const
pure virtual

Evaluate the expression and convert the result to intval_t if possible; throw an error if conversion from that type is not supported. Also throws an error if the actual unit does not match the expected unit.

Implemented in cDynamicExpression.

Referenced by cDynamicExpression::xmlValue().

◆ doubleValue() [1/2]

virtual double doubleValue ( Context * context,
const char * expectedUnit = nullptr ) const
pure virtual

Evaluate the expression and convert the result to double if possible; throw an error if conversion from that type is not supported. Also throws an error if the actual unit does not match the expected unit.

Implemented in cDynamicExpression.

Referenced by cDynamicExpression::xmlValue().

◆ stringValue() [1/2]

virtual std::string stringValue ( Context * context) const
pure virtual

Evaluate the expression and convert the result to string if possible; throw an error if conversion from that type is not supported.

Implemented in cDynamicExpression.

Referenced by cDynamicExpression::xmlValue().

◆ xmlValue() [1/2]

virtual cXMLElement * xmlValue ( Context * context) const
pure virtual

Evaluate the expression and convert the result to an XML tree if possible; throw an error if conversion from that type is not supported.

Implemented in cDynamicExpression.

Referenced by cDynamicExpression::xmlValue().

◆ evaluate() [2/2]

virtual cValue evaluate ( cComponent * contextComponent = nullptr) const
virtual

Evaluate the expression and return the result in a cValue. This method creates a Context from contextComponent, and delegates to evaluate(Context*).

Reimplemented in cDynamicExpression.

◆ boolValue() [2/2]

virtual bool boolValue ( cComponent * contextComponent = nullptr) const
virtual

Evaluate the expression and convert the result to bool if possible; throw an error if conversion from that type is not supported. This method creates a Context from contextComponent, and delegates to boolValue(Context*).

Reimplemented in cDynamicExpression.

◆ intValue() [2/2]

virtual intval_t intValue ( cComponent * contextComponent = nullptr,
const char * expectedUnit = nullptr ) const
virtual

Evaluate the expression and convert the result to intval_t if possible; throw an error if conversion from that type is not supported. Also throws an error if the actual unit does not match the expected unit. This method creates a Context from contextComponent, and delegates to intValue(Context*,const char*).

Reimplemented in cDynamicExpression.

◆ doubleValue() [2/2]

virtual double doubleValue ( cComponent * contextComponent = nullptr,
const char * expectedUnit = nullptr ) const
virtual

Evaluate the expression and convert the result to double if possible; throw an error if conversion from that type is not supported. Also throws an error if the actual unit does not match the expected unit. This method creates a Context from contextComponent, and delegates to doubleValue(Context*,const char*).

Reimplemented in cDynamicExpression.

◆ stringValue() [2/2]

virtual std::string stringValue ( cComponent * contextComponent = nullptr) const
virtual

Evaluate the expression and convert the result to string if possible; throw an error if conversion from that type is not supported. This method creates a Context from contextComponent, and delegates to stringValue(Context*).

Reimplemented in cDynamicExpression.

◆ xmlValue() [2/2]

virtual cXMLElement * xmlValue ( cComponent * contextComponent = nullptr) const
virtual

Evaluate the expression and convert the result to an XML tree if possible; throw an error if conversion from that type is not supported. This method creates a Context from contextComponent, and delegates to xmlValue(Context*).

Reimplemented in cDynamicExpression.

◆ parse()

virtual void parse ( const char * text)
pure virtual

Interprets the string as an expression, and store it. If the text cannot be parsed, an exception is thrown, which can be caught as std::runtime_error& if necessary. An exception is also thrown if the particular cExpression subclass does not support parsing.

Implemented in cDynamicExpression.

◆ compare()

virtual int compare ( const cExpression * other) const
pure virtual

Compares two expressions. Makes it possible to use cExpression as (part of) a key in std::map or std::set.

Implemented in cDynamicExpression.

References cExpression().

◆ isAConstant()

virtual bool isAConstant ( ) const
inlinevirtual

Returns true if the expression is just a literal (or equivalent to one, like "2+2"). This can be used for optimization.

Reimplemented in cDynamicExpression.

◆ getSourceLocation()

virtual std::string getSourceLocation ( ) const
pure virtual

Returns the file:line info where this expression was parsed from. Returns empty string if such info is not available.

Implemented in cDynamicExpression.