#include <Evaluator.h>
Public Types | |
| OK | |
| Everything OK. | |
| WARNING_EXISTING_VARIABLE | |
| Redefinition of existing variable. | |
| WARNING_EXISTING_FUNCTION | |
| Redefinition of existing function. | |
| WARNING_BLANK_STRING | |
| Empty input string. | |
| ERROR_NOT_A_NAME | |
| Not allowed sysmbol in the name of variable or function. | |
| ERROR_SYNTAX_ERROR | |
| Systax error. | |
| ERROR_UNPAIRED_PARENTHESIS | |
| Unpaired parenthesis. | |
| ERROR_UNEXPECTED_SYMBOL | |
| Unexpected sysbol. | |
| ERROR_UNKNOWN_VARIABLE | |
| Non-existing variable. | |
| ERROR_UNKNOWN_FUNCTION | |
| Non-existing function. | |
| ERROR_EMPTY_PARAMETER | |
| Function call has empty parameter. | |
| ERROR_CALCULATION_ERROR | |
| Error during calculation. | |
| enum | { OK, WARNING_EXISTING_VARIABLE, WARNING_EXISTING_FUNCTION, WARNING_BLANK_STRING, ERROR_NOT_A_NAME, ERROR_SYNTAX_ERROR, ERROR_UNPAIRED_PARENTHESIS, ERROR_UNEXPECTED_SYMBOL, ERROR_UNKNOWN_VARIABLE, ERROR_UNKNOWN_FUNCTION, ERROR_EMPTY_PARAMETER, ERROR_CALCULATION_ERROR } |
| List of possible statuses. More... | |
Public Member Functions | |
| Evaluator () | |
| Constructor. | |
| ~Evaluator () | |
| Destructor. | |
| double | evaluate (const char *expression) |
| Evaluates the arithmetic expression given as character string. | |
| int | status () const |
| Returns status of the last operation with the evaluator. | |
| int | error_position () const |
| Returns position in the input string where the problem occured. | |
| void | print_error () const |
| Prints error message if status() is an ERROR. | |
| void | setVariable (const char *name, double value) |
| Adds to the dictionary a variable with given value. | |
| void | setVariable (const char *name, const char *expression) |
| Adds to the dictionary a variable with an arithmetic expression assigned to it. | |
| void | setFunction (const char *name, double(*fun)()) |
| Adds to the dictionary a function without parameters. | |
| void | setFunction (const char *name, double(*fun)(double)) |
| Adds to the dictionary a function with one parameter. | |
| void | setFunction (const char *name, double(*fun)(double, double)) |
| Adds to the dictionary a function with two parameters. | |
| void | setFunction (const char *name, double(*fun)(double, double, double)) |
| Adds to the dictionary a function with three parameters. | |
| void | setFunction (const char *name, double(*fun)(double, double, double, double)) |
| Adds to the dictionary a function with four parameters. | |
| void | setFunction (const char *name, double(*fun)(double, double, double, double, double)) |
| Adds to the dictionary a function with five parameters. | |
| bool | findVariable (const char *name) const |
| Finds the variable in the dictionary. | |
| bool | findFunction (const char *name, int npar) const |
| Finds the function in the dictionary. | |
| void | removeVariable (const char *name) |
| Removes the variable from the dictionary. | |
| void | removeFunction (const char *name, int npar) |
| Removes the function from the dictionary. | |
| void | clear () |
| Clear all settings. | |
| void | setStdMath () |
| Sets standard mathematical functions and constants. | |
| void | setSystemOfUnits (double meter=1.0, double kilogram=1.0, double second=1.0, double ampere=1.0, double kelvin=1.0, double mole=1.0, double candela=1.0) |
| Sets system of units. | |
Private Member Functions | |
| Evaluator (const Evaluator &) | |
| Evaluator & | operator= (const Evaluator &) |
Private Attributes | |
| void * | p |
Taken from CLHEP 1.9.2.1
Example:
#include "XmlTools/Evaluator.h" XmlTools::Evaluator eval; eval.setStdMath(); double res = eval.evaluate("sin(30*degree)"); if (eval.status() != XmlTools::Evaluator::OK) eval.print_error();
Definition at line 27 of file Evaluator.h.
| anonymous enum |
List of possible statuses.
Status of the last operation can be obtained with status(). In case if status() is an ERROR the corresponding error message can be printed with print_error().
Definition at line 40 of file Evaluator.h.
00040 { 00041 OK, 00042 WARNING_EXISTING_VARIABLE, 00043 WARNING_EXISTING_FUNCTION, 00044 WARNING_BLANK_STRING, 00045 ERROR_NOT_A_NAME, 00046 ERROR_SYNTAX_ERROR, 00047 ERROR_UNPAIRED_PARENTHESIS, 00048 ERROR_UNEXPECTED_SYMBOL, 00049 ERROR_UNKNOWN_VARIABLE, 00050 ERROR_UNKNOWN_FUNCTION, 00051 ERROR_EMPTY_PARAMETER, 00052 ERROR_CALCULATION_ERROR 00053 };
| XmlTools::Evaluator::Evaluator | ( | ) |
Constructor.
| XmlTools::Evaluator::~Evaluator | ( | ) |
Destructor.
| XmlTools::Evaluator::Evaluator | ( | const Evaluator & | ) | [private] |
| double XmlTools::Evaluator::evaluate | ( | const char * | expression | ) |
Evaluates the arithmetic expression given as character string.
The expression may consist of numbers, variables and functions separated by arithmetic (+, - , /, *, ^, **) and logical operators (==, !=, >, >=, <, <=, &&, ||).
| expression | input expression. |
| int XmlTools::Evaluator::status | ( | ) | const |
Returns status of the last operation with the evaluator.
| int XmlTools::Evaluator::error_position | ( | ) | const |
Returns position in the input string where the problem occured.
| void XmlTools::Evaluator::print_error | ( | ) | const |
Prints error message if status() is an ERROR.
| void XmlTools::Evaluator::setVariable | ( | const char * | name, | |
| double | value | |||
| ) |
Adds to the dictionary a variable with given value.
If a variable with such a name already exist in the dictionary, then status will be set to WARNING_EXISTING_VARIABLE.
| name | name of the variable. | |
| value | value assigned to the variable. |
| void XmlTools::Evaluator::setVariable | ( | const char * | name, | |
| const char * | expression | |||
| ) |
Adds to the dictionary a variable with an arithmetic expression assigned to it.
If a variable with such a name already exist in the dictionary, then status will be set to WARNING_EXISTING_VARIABLE.
| name | name of the variable. | |
| expression | arithmetic expression. |
| void XmlTools::Evaluator::setFunction | ( | const char * | name, | |
| double(*)() | fun | |||
| ) |
Adds to the dictionary a function without parameters.
If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.
| name | function name. | |
| fun | pointer to the real function in the user code. |
| void XmlTools::Evaluator::setFunction | ( | const char * | name, | |
| double(*)(double) | fun | |||
| ) |
Adds to the dictionary a function with one parameter.
If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.
| name | function name. | |
| fun | pointer to the real function in the user code. |
| void XmlTools::Evaluator::setFunction | ( | const char * | name, | |
| double(*)(double, double) | fun | |||
| ) |
Adds to the dictionary a function with two parameters.
If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.
| name | function name. | |
| fun | pointer to the real function in the user code. |
| void XmlTools::Evaluator::setFunction | ( | const char * | name, | |
| double(*)(double, double, double) | fun | |||
| ) |
Adds to the dictionary a function with three parameters.
If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.
| name | function name. | |
| fun | pointer to the real function in the user code. |
| void XmlTools::Evaluator::setFunction | ( | const char * | name, | |
| double(*)(double, double, double, double) | fun | |||
| ) |
Adds to the dictionary a function with four parameters.
If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.
| name | function name. | |
| fun | pointer to the real function in the user code. |
| void XmlTools::Evaluator::setFunction | ( | const char * | name, | |
| double(*)(double, double, double, double, double) | fun | |||
| ) |
Adds to the dictionary a function with five parameters.
If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.
| name | function name. | |
| fun | pointer to the real function in the user code. |
| bool XmlTools::Evaluator::findVariable | ( | const char * | name | ) | const |
Finds the variable in the dictionary.
| name | name of the variable. |
| bool XmlTools::Evaluator::findFunction | ( | const char * | name, | |
| int | npar | |||
| ) | const |
Finds the function in the dictionary.
| name | name of the function to be unset. | |
| npar | number of parameters of the function. |
| void XmlTools::Evaluator::removeVariable | ( | const char * | name | ) |
Removes the variable from the dictionary.
| name | name of the variable. |
| void XmlTools::Evaluator::removeFunction | ( | const char * | name, | |
| int | npar | |||
| ) |
Removes the function from the dictionary.
| name | name of the function to be unset. | |
| npar | number of parameters of the function. |
| void XmlTools::Evaluator::clear | ( | ) |
Clear all settings.
| void XmlTools::Evaluator::setStdMath | ( | ) |
Sets standard mathematical functions and constants.
| void XmlTools::Evaluator::setSystemOfUnits | ( | double | meter = 1.0, |
|
| double | kilogram = 1.0, |
|||
| double | second = 1.0, |
|||
| double | ampere = 1.0, |
|||
| double | kelvin = 1.0, |
|||
| double | mole = 1.0, |
|||
| double | candela = 1.0 | |||
| ) |
Sets system of units.
Default is the SI system of units. To set the CGS (Centimeter-Gram-Second) system of units one should call: setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0);
To set system of units accepted in the GEANT4 simulation toolkit one should call:
setSystemOfUnits(1.e+3, 1./1.60217733e-25, 1.e+9, 1./1.60217733e-10, 1.0, 1.0, 1.0);
The basic units in GEANT4 are:
millimeter (millimeter = 1.) nanosecond (nanosecond = 1.) Mega electron Volt (MeV = 1.) positron charge (eplus = 1.) degree Kelvin (kelvin = 1.) the amount of substance (mole = 1.) luminous intensity (candela = 1.) radian (radian = 1.) steradian (steradian = 1.)
void* XmlTools::Evaluator::p [private] |
Definition at line 254 of file Evaluator.h.
1.4.7