OMNeT++ Simulation Library  5.6.1
cDynamicExpression Class Reference

#include <cdynamicexpression.h>

Description

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

Inheritance diagram for cDynamicExpression:
cExpression cObject

Classes

class  Elem
 One element in a (reverse Polish) expression. More...
 
class  Functor
 Function object base class. We use function objects to handle NED parameter references, "index" and "sizeof" operators, and references to NED "for" loop variables. More...
 

Public Types

enum  OpType
 

Public Member Functions

Constructors, destructor, assignment.
 cDynamicExpression ()
 
 cDynamicExpression (const cDynamicExpression &other)
 
virtual ~cDynamicExpression ()
 
cDynamicExpressionoperator= (const cDynamicExpression &other)
 
Redefined cObject functions
virtual cDynamicExpressiondup () const override
 
virtual std::string str () const override
 
Setter and evaluator methods.
virtual void setExpression (Elem e[], int size)
 
virtual cNedValue evaluate (Context *context) const override
 
virtual bool boolValue (Context *context) const override
 
virtual intpar_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
 
- Public Member Functions inherited from cExpression
 cExpression ()
 
 cExpression (const cExpression &other)
 
virtual ~cExpression ()
 
cExpressionoperator= (const cExpression &other)
 
virtual void parsimPack (cCommBuffer *buffer) const override
 
virtual void parsimUnpack (cCommBuffer *buffer) override
 
virtual cNedValue evaluate (cComponent *contextComponent=nullptr) const
 
virtual bool boolValue (cComponent *contextComponent=nullptr) const
 
virtual intpar_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
 
- Public Member Functions inherited from cObject
 cObject ()
 
 cObject (const cObject &other)
 
virtual ~cObject ()
 
virtual const char * getClassName () const
 
virtual const char * getName () const
 
bool isName (const char *s) const
 
virtual const char * getFullName () const
 
virtual std::string getFullPath () const
 
const cObjectgetThisPtr () const
 
virtual _OPPDEPRECATED std::string info () const
 
virtual _OPPDEPRECATED std::string detailedInfo () const
 
virtual cObjectgetOwner () const
 
virtual bool isOwnedObject () const
 
virtual void forEachChild (cVisitor *v)
 
cObjectfindObject (const char *name, bool deep=true)
 
void copyNotSupported () const
 

Miscellaneous utility functions.

virtual void parse (const char *text) override
 
virtual int compare (const cExpression *other) const override
 
virtual bool isAConstant () const
 
virtual bool containsConstSubexpressions () const override
 
virtual void evaluateConstSubexpressions (Context *context) override
 
static double convertUnit (double d, const char *unit, const char *targetUnit)
 

Additional Inherited Members

- Protected Member Functions inherited from cObject
virtual void take (cOwnedObject *obj)
 
virtual void drop (cOwnedObject *obj)
 
void dropAndDelete (cOwnedObject *obj)
 

Member Enumeration Documentation

◆ OpType

enum OpType

Operations supported by this class:

  • add, subtract, multiply, divide ("+" is also string concatenation)
  • modulo, power of, negation (-1)
  • equal, not equal, greater, greater or equal, less, less or equal
  • inline if (the C/C++ ?: operator)
  • logical and, or, xor, not
  • bitwise and, or, xor, not (1's complement)
  • left shift, right shift

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

◆ str()

virtual std::string str ( ) const
overridevirtual

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

Reimplemented from cExpression.

◆ setExpression()

virtual void setExpression ( Elem  e[],
int  size 
)
virtual

Sets the Reverse Polish expression to evaluate. The array must be a dynamically allocated one, and will be deleted by this object. No verification is performed on the expression at this time.

◆ evaluate()

virtual cNedValue evaluate ( Context context) const
overridevirtual

Evaluate the expression, and return the results as a cNedValue. Throws an error if the expression has some problem (i.e. stack overflow/underflow, "cannot cast", "function not found", etc.)

Implements cExpression.

◆ boolValue()

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()

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

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

Implements cExpression.

◆ doubleValue()

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()

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()

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.

◆ parse()

virtual void parse ( const char *  text)
overridevirtual

Interprets the string as an expression, and stores it.

Implements cExpression.

◆ compare()

virtual int compare ( const cExpression other) const
overridevirtual

Compares two expressions.

Implements cExpression.

◆ isAConstant()

virtual bool isAConstant ( ) const
virtual

Returns true if the expression is just a literal (or equivalent to one, like "2+2").

◆ containsConstSubexpressions()

virtual bool containsConstSubexpressions ( ) const
overridevirtual

Returns true if this expression contains const subexpressions.

Implements cExpression.

◆ evaluateConstSubexpressions()

virtual void evaluateConstSubexpressions ( Context context)
overridevirtual

Evaluates const subexpressions, and replaces them with their values. See cDynamicExpression::Elem::CONSTSUBEXPR.

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


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