cDynamicExpression Class Reference
[Simulation core classes]

#include <cdynamicexpression.h>

Inheritance diagram for cDynamicExpression:

cExpression cObject

List of all members.


Detailed Description

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

NOTE: Experimental class -- API is subject to change.

Miscellaneous utility functions.

virtual std::string str () const
virtual void parse (const char *text)
virtual int compare (const cExpression *other) const
virtual bool isAConstant () const
virtual bool containsConstSubexpressions () const
virtual void evaluateConstSubexpressions (cComponent *context)
static double convertUnit (double d, const char *unit, const char *targetUnit)

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
virtual std::string info () const
Setter and evaluator methods.
virtual void setExpression (Elem e[], int size)
virtual cNEDValue evaluate (cComponent *context) const
virtual bool boolValue (cComponent *context)
virtual long longValue (cComponent *context, const char *expectedUnit=NULL)
virtual double doubleValue (cComponent *context, const char *expectedUnit=NULL)
virtual std::string stringValue (cComponent *context)
virtual cXMLElementxmlValue (cComponent *context)

Classes

class  Elem
 One element in a (reverse Polish) expression. More...
class  Functor
 Function object base class. More...


Member Enumeration Documentation

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::cDynamicExpression (  )  [explicit]

Constructor.

cDynamicExpression::cDynamicExpression ( const cDynamicExpression other  )  [inline]

Copy constructor.

virtual cDynamicExpression::~cDynamicExpression (  )  [virtual]

Destructor.


Member Function Documentation

cDynamicExpression& cDynamicExpression::operator= ( const cDynamicExpression other  ) 

Assignment operator.

virtual cDynamicExpression* cDynamicExpression::dup (  )  const [inline, virtual]

Creates and returns an exact copy of this object.

Reimplemented from cExpression.

virtual std::string cDynamicExpression::info (  )  const [virtual]

Produces a one-line description of the object's contents.

See cObject for more details.

Reimplemented from cExpression.

virtual void cDynamicExpression::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.

virtual cNEDValue cDynamicExpression::evaluate ( cComponent context  )  const [virtual]

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

virtual bool cDynamicExpression::boolValue ( cComponent context  )  [virtual]

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

Implements cExpression.

Referenced by cNEDValue::operator bool().

virtual long cDynamicExpression::longValue ( cComponent context,
const char *  expectedUnit = NULL 
) [virtual]

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

Implements cExpression.

Referenced by cNEDValue::operator char(), cNEDValue::operator int(), cNEDValue::operator long(), cNEDValue::operator short(), cNEDValue::operator unsigned char(), cNEDValue::operator unsigned int(), cNEDValue::operator unsigned long(), and cNEDValue::operator unsigned short().

virtual double cDynamicExpression::doubleValue ( cComponent context,
const char *  expectedUnit = NULL 
) [virtual]

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

Implements cExpression.

Referenced by cNEDValue::operator double(), and cNEDValue::operator long double().

virtual std::string cDynamicExpression::stringValue ( cComponent context  )  [virtual]

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

Implements cExpression.

Referenced by cNEDValue::operator const char *().

virtual cXMLElement* cDynamicExpression::xmlValue ( cComponent context  )  [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.

Implements cExpression.

Referenced by cNEDValue::operator cXMLElement *().

virtual std::string cDynamicExpression::str (  )  const [virtual]

Converts the expression to string.

Implements cExpression.

virtual void cDynamicExpression::parse ( const char *  text  )  [virtual]

Interprets the string as an expression, and stores it.

Implements cExpression.

virtual int cDynamicExpression::compare ( const cExpression other  )  const [virtual]

Compares two expressions.

Implements cExpression.

virtual bool cDynamicExpression::isAConstant (  )  const [virtual]

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

virtual bool cDynamicExpression::containsConstSubexpressions (  )  const [virtual]

Returns true if this expression contains const subexpressions.

Implements cExpression.

virtual void cDynamicExpression::evaluateConstSubexpressions ( cComponent context  )  [virtual]

Evaluates const subexpressions, and replaces them with their values.

See cDynamicExpression::Elem::CONSTSUBEXPR.

Implements cExpression.

static double cDynamicExpression::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).

Referenced by cNEDValue::doubleValueInUnit().


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

Generated on Wed Apr 3 14:40:28 2013 for OMNeT++ Simulation Library by  doxygen 1.5.5