OMNeT++ Simulation Library  6.0.3
cDynamicExpression Class Reference

#include <cdynamicexpression.h>

Description

A stack-based expression evaluator class, for dynamically created expressions.

Inheritance diagram for cDynamicExpression:
cExpression cOwnedDynamicExpression

Classes

class  IResolver
 
class  SymbolTable
 

Public Member Functions

Constructors, destructor, assignment.
 cDynamicExpression ()
 
 cDynamicExpression (const cDynamicExpression &other)
 
virtual ~cDynamicExpression ()
 
cDynamicExpressionoperator= (const cDynamicExpression &other)
 
virtual cDynamicExpressiondup () const override
 
virtual std::string str () const override
 
Setter and evaluator methods.
virtual void parse (const char *text) override
 
virtual void parse (const char *text, IResolver *resolver)
 
virtual void parse (const char *text, const std::map< std::string, cValue > &symbolTable)
 
virtual void setResolver (IResolver *resolver)
 
virtual IResolvergetResolver () const
 
virtual void parseNedExpr (const char *text)
 
virtual cValue evaluate (Context *context) const override
 
virtual bool boolValue (Context *context) const override
 
virtual intval_t intValue (Context *context, const char *expectedUnit=nullptr) const override
 
virtual double doubleValue (Context *context, const char *expectedUnit=nullptr) const override
 
virtual std::string stringValue (Context *context) const override
 
virtual cXMLElementxmlValue (Context *context) const override
 
virtual cValue evaluate (Context *context) const=0
 
virtual cValue evaluate (cComponent *contextComponent=nullptr) const
 
virtual bool boolValue (Context *context) const=0
 
virtual bool boolValue (cComponent *contextComponent=nullptr) const
 
virtual intval_t intValue (Context *context, const char *expectedUnit=nullptr) const=0
 
virtual intval_t intValue (cComponent *contextComponent=nullptr, const char *expectedUnit=nullptr) const
 
virtual double doubleValue (Context *context, const char *expectedUnit=nullptr) const=0
 
virtual double doubleValue (cComponent *contextComponent=nullptr, const char *expectedUnit=nullptr) const
 
virtual std::string stringValue (Context *context) const=0
 
virtual std::string stringValue (cComponent *contextComponent=nullptr) const
 
virtual cXMLElementxmlValue (Context *context) const=0
 
virtual cXMLElementxmlValue (cComponent *contextComponent=nullptr) const
 
- Public Member Functions inherited from cExpression
 cExpression ()
 
 cExpression (const cExpression &other)=default
 
virtual ~cExpression ()
 
cExpressionoperator= (const cExpression &other)
 
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 int compare (const cExpression *other) const override
 
virtual bool isAConstant () const override
 
void setSourceLocation (FileLine loc)
 
virtual std::string getSourceLocation () const override
 
static double convertUnit (double d, const char *unit, const char *targetUnit)
 

Constructor & Destructor Documentation

◆ cDynamicExpression() [1/2]

cDynamicExpression ( )
explicit

Constructor.

◆ cDynamicExpression() [2/2]

cDynamicExpression ( const cDynamicExpression other)
inline

Copy constructor.

◆ ~cDynamicExpression()

virtual ~cDynamicExpression ( )
virtual

Destructor.

Member Function Documentation

◆ operator=()

cDynamicExpression& operator= ( const cDynamicExpression other)

Assignment operator.

◆ dup()

virtual cDynamicExpression* dup ( ) const
inlineoverridevirtual

Creates and returns an exact copy of this object.

Implements cExpression.

Reimplemented in cOwnedDynamicExpression.

◆ str()

virtual std::string str ( ) const
overridevirtual

Converts the expression to string. See cObject for more details.

Reimplemented from cExpression.

Reimplemented in cOwnedDynamicExpression.

Referenced by cOwnedDynamicExpression::str().

◆ parse() [1/3]

virtual void parse ( const char *  text)
overridevirtual

Interprets the string as a generic expression, and stores it.

Implements cExpression.

◆ parse() [2/3]

virtual void parse ( const char *  text,
IResolver resolver 
)
inlinevirtual

Interprets the string as a generic expression, and stores it. The resolver object allows variables, member accesses, function calls and method calls to be handled in a custom way. The expression object will take ownership of the resolver object.

References cDynamicExpression::parse().

Referenced by cDynamicExpression::parse().

◆ parse() [3/3]

virtual void parse ( const char *  text,
const std::map< std::string, cValue > &  symbolTable 
)
inlinevirtual

Interprets the string as a generic expression, and stores it. Values for variables used in the expression can be passed in the symbolTable argument. This method is simply delegates to parse(const char *text, IResolver *resolver) while using cDynamicExpression::SymbolTable as resolver.

References cDynamicExpression::parse().

Referenced by cDynamicExpression::parse().

◆ setResolver()

virtual void setResolver ( IResolver resolver)
virtual

Allows changing the resolver after a parse() call.

◆ getResolver()

virtual IResolver* getResolver ( ) const
inlinevirtual

Returns the resolver.

◆ parseNedExpr()

virtual void parseNedExpr ( const char *  text)
virtual

Interprets the string as a NED expression, and stores it.

◆ evaluate() [1/3]

virtual cValue evaluate ( Context context) const
overridevirtual

Evaluate the expression, and return the results as a cValue. Evaluation errors result in exceptions.

Implements cExpression.

◆ boolValue() [1/3]

virtual bool boolValue ( Context context) const
overridevirtual

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

Implements cExpression.

◆ intValue() [1/3]

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

Evaluate the expression and convert the result to intval_t if possible; throw an error if conversion from that type is not supported, or the value of out of the range of intval_t.

Implements cExpression.

◆ doubleValue() [1/3]

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

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

Implements cExpression.

◆ stringValue() [1/3]

virtual std::string stringValue ( Context context) const
overridevirtual

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

Implements cExpression.

◆ xmlValue() [1/3]

virtual cXMLElement* xmlValue ( Context context) const
overridevirtual

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

Implements cExpression.

◆ compare()

virtual int compare ( const cExpression other) const
overridevirtual

Compares two expressions.

Implements cExpression.

◆ isAConstant()

virtual bool isAConstant ( ) const
overridevirtual

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

Reimplemented from cExpression.

◆ setSourceLocation()

void setSourceLocation ( FileLine  loc)
inline

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

◆ getSourceLocation()

virtual std::string getSourceLocation ( ) const
inlineoverridevirtual

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

Implements cExpression.

◆ convertUnit()

static double convertUnit ( double  d,
const char *  unit,
const char *  targetUnit 
)
static

Convert the given number into the target unit (e.g. milliwatt to watt). Throws an exception if conversion is not possible (unknown/unrelated units).

◆ evaluate() [2/3]

virtual cValue evaluate

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

◆ evaluate() [3/3]

virtual cValue evaluate

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

◆ boolValue() [2/3]

virtual bool boolValue

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

◆ boolValue() [3/3]

virtual bool boolValue

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*).

◆ intValue() [2/3]

virtual intval_t intValue

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.

◆ intValue() [3/3]

virtual intval_t intValue

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*).

◆ doubleValue() [2/3]

virtual double doubleValue

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.

◆ doubleValue() [3/3]

virtual double doubleValue

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*).

◆ stringValue() [2/3]

virtual std::string stringValue

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

◆ stringValue() [3/3]

virtual std::string stringValue

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*).

◆ xmlValue() [2/3]

virtual cXMLElement* xmlValue

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

◆ xmlValue() [3/3]

virtual cXMLElement* xmlValue

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*).


The documentation for this class was generated from the following file: