HepTool::Evaluator is an evaluator of arithmetic expressions
with an extendable dictionary.
Author
Evgueni Tcherniaev
Declaration
#include "CLHEP/Evaluator/Evaluator.h"
namespace HepTool
class Evaluator
Public Member Functions
- Constructor
- Evaluator()
- Copy constructor
- Copy constructor is disabled.
- Destructor
- ~Evaluator()
- =
- Assignment is disabled.
- clear
- void clear()
- Clear all settings.
- error_position
- int error_position() const
- Returns position in the input string where the problem occured.
- evaluate
- double 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 (==, !=, > >=, <, <=, &&, ||).
- findFunction
- HepBoolean findFunction(const char * name, int npar) const
- Finds the function in the dictionary.
- findVariable
- HepBoolean findVariable(const char * name) const
- Finds the variable in the dictionary.
- print_error
- void print_error() const
- Prints error message if status() is an ERROR.
- setFunction
- void setFunction(const char * name, double (*fun)())
- Adds to the dictionary the function without parameters.
- If such a function already exist in the dictionary,
then status will be set to WARNING_EXISTING_FUNCTION.
- void setFunction(const char * name, double (*fun)(double))
- Adds to the dictionary the function with one parameter.
- If such a function already exist in the dictionary,
then status will be set to WARNING_EXISTING_FUNCTION.
- void setFunction(const char * name, double (*fun)(double,double))
- Adds to the dictionary the function with two parameters.
- If such a function already exist in the dictionary,
then status will be set to WARNING_EXISTING_FUNCTION.
- void setFunction(const char * name, double (*fun)(double,double,double))
- Adds to the dictionary the function with three parameters.
- If such a function already exist in the dictionary,
then status will be set to WARNING_EXISTING_FUNCTION.
- void setFunction(const char * name, double (*fun)(double,double,double,double))
- Adds to the dictionary the function with four parameters.
- If such a function already exist in the dictionary,
then status will be set to WARNING_EXISTING_FUNCTION.
- void setFunction(const char * name, double (*fun)(double,double,double,double,double))
- Adds to the dictionary the function with five parameters.
- If such a function already exist in the dictionary,
then status will be set to WARNING_EXISTING_FUNCTION.
- setStdMath
- void setStdMath()
- Sets standard mathematical functions and constants.
- setSystemOfUnits
- 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. 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.)
- setVariable
- void 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.
- void 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.
- status
- int status() const
- Returns status of the last operation with the evaluator.
In case if status() is an ERROR the
corresponding error message can be printed with print_error().
- List of possible statuses:
- 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
- }
- removeVariable
- void removeVariable(const char * name)
- Removes the variable from the dictionary.
- removeFunction
- void removeFunction(const char * name, int npar)
- Removes the function from the dictionary.
Example
CLHEP/test/testEvaluator.cc
is an example of a scientific calculator based on the
HepTool::Evaluator class.
18 Oct 2000
EVC