How to use:
When an expression is passed to LoadFromEpression the list of variables is
being initialised with variable names. Before the Evaluate is called the array of
IVariables has to being initialised with the values of the variables. Use
Variables->IndexOf(VarName) to identify the index of variables. The Functions
have to be predefined. If no variables is expected when the constructor can be
called as TSOperatio(NULL, NULL, Function, NULL). If the functions are not in the
expression call TSOperatio(NULL, NULL, NULL, NULL).
Note that the variables list is in the upper case.
const short // operators
fPlus = 1,
fMinus = 2,
fMultiply = 3,
fDivide = 4,
fFunction = 5,
fExt = 6;
const short // functions
fNone = 0,
fAbs = 1,
fCos = 2,
fSin = 3,
fDefined = 4; // defined by an external program
typedef double (*TEvaluate)(double P1, double P2); //an external function
{
protected:
TSOperation *ToCalc; // if evaluable == true the these are in
use
TSOperation *Left, *Right;
short Function;
double Value;
void Calculate();
void SSCalculate();
void MDCalculate();
int VariableIndex;
TSOperation *Parent;
TEString FExp;
public:
double *IVariables;
TEStringList *Variables, *Functions;
TSOperation(TSOperation *P,
TEStringList *Vars,
TEStringList
*Funcs, double *IVariables);
~TSOperation();
TEvaluate *Evaluator;
bool Expandable;
TEString Func, Param;
short Operation;
double P1, P2;
double Evaluate();
int LoadFromExpression(const TEString &Exp);
};
©
Oleg V. Dolomanov, 2004
Last Updated 2004.04.01