Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::ariel::Expression Class Reference

#include <Expression.h>

Inheritance diagram for util::ariel::Expression:

util::Object List of all members.

Detailed Description

Expression is a class for calculating dynamically created arithmetic expressions run-time.


Public Methods

 Expression ()
 Create an expression without a string to be parsed.

 Expression (std::string expression)
 Create an expression with a string to be parsed.

void setExpression (std::string expression)
std::string getExpression ()
Computableparse (std::string expression) throw (ParseException&, ComputationException&)
 Parse an expression.

Computableparse () throw (ParseException&, ComputationException&)
 Parse a stored expression.

virtual Computableevaluate () throw (ComputationException&)
 Evaluate a parsed expression.

ComputablegetValue ()
 Get the current value of the expression.

 operator Computable & ()
 Typecast to Computable.


Static Public Methods

void init ()
 Initialize the expression evaluator.

void setVariableManager (VariableManager *mgr)
VariableManagergetVariableManager (VariableManager *mgr)

Protected Methods

 Expression (SmartPtr< Computable > value, List< UnaryFunction * > funcs) throw (ComputationException&)
 Expression (Expression *value)

Protected Attributes

SmartPtr< Computable_currentValue

Static Protected Attributes

VariableManager_pVariableManager = NULL

Friends

class Variable


Member Function Documentation

Computable & util::ariel::Expression::evaluate   throw (ComputationException&) [virtual]
 

Evaluate a parsed expression.

The prebuild evaluation tree is evaluated recursively, and the result value is returned. This method is needed when variable values have changed but the expression itself has not.

Computable& util::ariel::Expression::getValue   [inline]
 

Get the current value of the expression.

Neither parsing nor evaluation will occur, but the last evaluated value is returned.

void util::ariel::Expression::init   [static]
 

Initialize the expression evaluator.

The init() method needs to be called only once per session (though it makes no harm to call it many times). It initializes the operator table.

util::ariel::Expression::operator Computable &   [inline]
 

Typecast to Computable.

This operator allows the use of an expression within arithmetic expressions containing Computable objects. The effect is same as that of the evaluate() call.

Computable & util::ariel::Expression::parse std::string    expression throw (ParseException&, ComputationException&)
 

Parse an expression.

The given expression string is parsed, and a calculation tree is built into memory for fast access afterwards. The expression string is a composition of numbers, strings, variables, function calls and operators. One may use (almost) any valid C statements. There are also certain enhancements as shown by the following examples.

<th>Expression</th><th>Result</th>
1+23
c = 1+23
(0,1,2)[1]1
d = (a=1) * get_func("sum_and_mean")(1,2,3)[1]2
((1,2,3) + 2) * 2(4,6,8)
"foo" + (1,2,3)("foo1","foo2","foo3")
(("foo","bar")[1]*2 + ".foo")/"."("barbar","foo")
2 <= 3true
"foo" == "bar" || 1 > 2 || sum(1,2) == 4false

The return value is a reference to an object derived from Computable. It may be a number, a string or a list storing other computable objects.


The documentation for this class was generated from the following files:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.