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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/clhep/include/CLHEP/Evaluator/Evaluator.h (Version 11.3.0) and /externals/clhep/include/CLHEP/Evaluator/Evaluator.h (Version 10.6.p2)


  1 // -*- C++ -*-                                      1 // -*- C++ -*-
  2 // -------------------------------------------      2 // ---------------------------------------------------------------------------
  3                                                     3 
  4 #ifndef HEP_EVALUATOR_H                             4 #ifndef HEP_EVALUATOR_H
  5 #define HEP_EVALUATOR_H                             5 #define HEP_EVALUATOR_H
  6                                                     6 
  7 #include <string>                                   7 #include <string>
  8                                                     8 
  9 namespace HepTool {                                 9 namespace HepTool {
 10                                                    10 
 11 /**                                                11 /**
 12  * Evaluator of arithmetic expressions with an     12  * Evaluator of arithmetic expressions with an extendable dictionary.
 13  * Example:                                        13  * Example:
 14  * @code                                           14  * @code
 15  *   #include "CLHEP/Evaluator/Evaluator.h"        15  *   #include "CLHEP/Evaluator/Evaluator.h"
 16  *   HepTool::Evaluator eval;                      16  *   HepTool::Evaluator eval;
 17  *   eval.setStdMath();                            17  *   eval.setStdMath();
 18  *   double res = eval.evaluate("sin(30*degree     18  *   double res = eval.evaluate("sin(30*degree)");
 19  *   if (eval.status() != HepTool::Evaluator::     19  *   if (eval.status() != HepTool::Evaluator::OK) eval.print_error();
 20  * @endcode                                        20  * @endcode
 21  *                                                 21  *
 22  * @author Evgeni Chernyaev <Evgueni.Tcherniae     22  * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
 23  * @ingroup evaluator                              23  * @ingroup evaluator
 24  */                                                24  */
 25 class Evaluator {                                  25 class Evaluator {
 26  public:                                           26  public: 
 27                                                    27 
 28   /**                                              28   /**
 29    * List of possible statuses.                    29    * List of possible statuses.
 30    * Status of the last operation can be obtai     30    * Status of the last operation can be obtained with status().
 31    * In case if status() is an ERROR the corre     31    * In case if status() is an ERROR the corresponding error message
 32    * can be printed with print_error().            32    * can be printed with print_error().
 33    *                                               33    * 
 34    * @see status                                   34    * @see status
 35    * @see error_position                           35    * @see error_position
 36    * @see print_error                              36    * @see print_error
 37    */                                              37    */
 38   enum {                                           38   enum {
 39     OK,                         /**< Everythin     39     OK,                         /**< Everything OK */
 40     WARNING_EXISTING_VARIABLE,  /**< Redefinit     40     WARNING_EXISTING_VARIABLE,  /**< Redefinition of existing variable */
 41     WARNING_EXISTING_FUNCTION,  /**< Redefinit     41     WARNING_EXISTING_FUNCTION,  /**< Redefinition of existing function */
 42     WARNING_BLANK_STRING,       /**< Empty inp     42     WARNING_BLANK_STRING,       /**< Empty input string */
 43     ERROR_NOT_A_NAME,           /**< Not allow     43     ERROR_NOT_A_NAME,           /**< Not allowed sysmbol in the name of variable or function */
 44     ERROR_SYNTAX_ERROR,         /**< Systax er     44     ERROR_SYNTAX_ERROR,         /**< Systax error */
 45     ERROR_UNPAIRED_PARENTHESIS, /**< Unpaired      45     ERROR_UNPAIRED_PARENTHESIS, /**< Unpaired parenthesis */
 46     ERROR_UNEXPECTED_SYMBOL,    /**< Unexpecte     46     ERROR_UNEXPECTED_SYMBOL,    /**< Unexpected sysbol */
 47     ERROR_UNKNOWN_VARIABLE,     /**< Non-exist     47     ERROR_UNKNOWN_VARIABLE,     /**< Non-existing variable */
 48     ERROR_UNKNOWN_FUNCTION,     /**< Non-exist     48     ERROR_UNKNOWN_FUNCTION,     /**< Non-existing function */
 49     ERROR_EMPTY_PARAMETER,      /**< Function      49     ERROR_EMPTY_PARAMETER,      /**< Function call has empty parameter */
 50     ERROR_CALCULATION_ERROR     /**< Error dur     50     ERROR_CALCULATION_ERROR     /**< Error during calculation */
 51   };                                               51   };
 52                                                    52 
 53   /**                                              53   /**
 54    * Constructor.                                  54    * Constructor.
 55    */                                              55    */
 56   Evaluator();                                     56   Evaluator();
 57                                                    57 
 58   /**                                              58   /**
 59    * Destructor.                                   59    * Destructor.
 60    */                                              60    */
 61   ~Evaluator();                                    61   ~Evaluator(); 
 62                                                    62 
 63   /**                                              63   /**
 64    * Evaluates the arithmetic expression given     64    * Evaluates the arithmetic expression given as character string. 
 65    * The expression may consist of numbers, va     65    * The expression may consist of numbers, variables and functions
 66    * separated by arithmetic (+, - , /, *, ^,      66    * separated by arithmetic (+, - , /, *, ^, **) and logical
 67    * operators (==, !=, >, >=, <, <=, &&, ||).     67    * operators (==, !=, >, >=, <, <=, &&, ||).
 68    *                                               68    *
 69    * @param  expression input expression.          69    * @param  expression input expression.
 70    * @return result of the evaluation.             70    * @return result of the evaluation.
 71    * @see status                                   71    * @see status
 72    * @see error_position                           72    * @see error_position
 73    * @see print_error                              73    * @see print_error
 74    */                                              74    */
 75   double evaluate(const char * expression);        75   double evaluate(const char * expression);
 76                                                    76 
 77   /**                                              77   /**
 78    * Returns status of the last operation with     78    * Returns status of the last operation with the evaluator.
 79    */                                              79    */
 80   int status() const;                              80   int status() const;
 81                                                    81 
 82   /**                                              82   /**
 83    * Returns position in the input string wher     83    * Returns position in the input string where the problem occured.
 84    */                                              84    */
 85   int error_position() const;                      85   int error_position() const; 
 86                                                    86 
 87   /**                                              87   /**
 88    * Prints error message if status() is an ER     88    * Prints error message if status() is an ERROR.
 89    */                                              89    */
 90   void print_error() const;                        90   void print_error() const;
 91   /**                                              91   /**
 92    * get a string defining the error name          92    * get a string defining the error name
 93    */                                              93    */
 94   std::string error_name() const;                  94   std::string error_name() const;
 95                                                    95 
 96   /**                                              96   /**
 97    * Adds to the dictionary a variable with gi     97    * Adds to the dictionary a variable with given value. 
 98    * If a variable with such a name already ex     98    * If a variable with such a name already exist in the dictionary,
 99    * then status will be set to WARNING_EXISTI     99    * then status will be set to WARNING_EXISTING_VARIABLE.
100    *                                              100    *
101    * @param name name of the variable.            101    * @param name name of the variable.
102    * @param value value assigned to the variab    102    * @param value value assigned to the variable.
103    */                                             103    */
104   void setVariable(const char * name, double v    104   void setVariable(const char * name, double value);
105                                                   105 
106   /**                                             106   /**
107    * Adds to the dictionary a variable with an    107    * Adds to the dictionary a variable with an arithmetic expression
108    * assigned to it.                              108    * assigned to it.
109    * If a variable with such a name already ex    109    * If a variable with such a name already exist in the dictionary,
110    * then status will be set to WARNING_EXISTI    110    * then status will be set to WARNING_EXISTING_VARIABLE.
111    *                                              111    *
112    * @param name name of the variable.            112    * @param name name of the variable.
113    * @param expression arithmetic expression.     113    * @param expression arithmetic expression.
114    */                                             114    */
115   void setVariable(const char * name, const ch    115   void setVariable(const char * name, const char * expression);
116                                                   116 
117   /**                                             117   /**
118    * Adds to the dictionary a function without    118    * Adds to the dictionary a function without parameters.
119    * If such a function already exist in the d    119    * If such a function already exist in the dictionary,
120    * then status will be set to WARNING_EXISTI    120    * then status will be set to WARNING_EXISTING_FUNCTION.
121    *                                              121    *
122    * @param name function name.                   122    * @param name function name.
123    * @param fun pointer to the real function i    123    * @param fun pointer to the real function in the user code. 
124    */                                             124    */
125   void setFunction(const char * name, double (    125   void setFunction(const char * name, double (*fun)());
126                                                   126 
127   /**                                             127   /**
128    * Adds to the dictionary a function with on    128    * Adds to the dictionary a function with one parameter.
129    * If such a function already exist in the d    129    * If such a function already exist in the dictionary,
130    * then status will be set to WARNING_EXISTI    130    * then status will be set to WARNING_EXISTING_FUNCTION.
131    *                                              131    *
132    * @param name function name.                   132    * @param name function name.
133    * @param fun pointer to the real function i    133    * @param fun pointer to the real function in the user code. 
134    */                                             134    */
135   void setFunction(const char * name, double (    135   void setFunction(const char * name, double (*fun)(double));
136                                                   136 
137   /**                                             137   /**
138    * Adds to the dictionary a function with tw    138    * Adds to the dictionary a function with two parameters.
139    * If such a function already exist in the d    139    * If such a function already exist in the dictionary,
140    * then status will be set to WARNING_EXISTI    140    * then status will be set to WARNING_EXISTING_FUNCTION.
141    *                                              141    *
142    * @param name function name.                   142    * @param name function name.
143    * @param fun pointer to the real function i    143    * @param fun pointer to the real function in the user code. 
144    */                                             144    */
145   void setFunction(const char * name, double (    145   void setFunction(const char * name, double (*fun)(double,double));
146                                                   146 
147   /**                                             147   /**
148    * Adds to the dictionary a function with th    148    * Adds to the dictionary a function with three parameters.
149    * If such a function already exist in the d    149    * If such a function already exist in the dictionary,
150    * then status will be set to WARNING_EXISTI    150    * then status will be set to WARNING_EXISTING_FUNCTION.
151    *                                              151    *
152    * @param name function name.                   152    * @param name function name.
153    * @param fun pointer to the real function i    153    * @param fun pointer to the real function in the user code. 
154    */                                             154    */
155   void setFunction(const char * name, double (    155   void setFunction(const char * name, double (*fun)(double,double,double));
156                                                   156 
157   /**                                             157   /**
158    * Adds to the dictionary a function with fo    158    * Adds to the dictionary a function with four parameters.
159    * If such a function already exist in the d    159    * If such a function already exist in the dictionary,
160    * then status will be set to WARNING_EXISTI    160    * then status will be set to WARNING_EXISTING_FUNCTION.
161    *                                              161    *
162    * @param name function name.                   162    * @param name function name.
163    * @param fun pointer to the real function i    163    * @param fun pointer to the real function in the user code. 
164    */                                             164    */
165   void setFunction(const char * name,             165   void setFunction(const char * name,
166        double (*fun)(double,double,double,doub    166        double (*fun)(double,double,double,double));
167                                                   167 
168   /**                                             168   /**
169    * Adds to the dictionary a function with fi    169    * Adds to the dictionary a function with five parameters.
170    * If such a function already exist in the d    170    * If such a function already exist in the dictionary,
171    * then status will be set to WARNING_EXISTI    171    * then status will be set to WARNING_EXISTING_FUNCTION.
172    *                                              172    *
173    * @param name function name.                   173    * @param name function name.
174    * @param fun pointer to the real function i    174    * @param fun pointer to the real function in the user code. 
175    */                                             175    */
176   void setFunction(const char * name,             176   void setFunction(const char * name,
177                    double (*fun)(double,double    177                    double (*fun)(double,double,double,double,double));
178                                                   178 
179   /**                                             179   /**
180    * Finds the variable in the dictionary.        180    * Finds the variable in the dictionary.
181    *                                              181    * 
182    * @param  name name of the variable.           182    * @param  name name of the variable.
183    * @return true if such a variable exists, f    183    * @return true if such a variable exists, false otherwise.
184    */                                             184    */
185   bool findVariable(const char * name) const;     185   bool findVariable(const char * name) const;
186                                                   186 
187   /**                                             187   /**
188    * Finds the function in the dictionary.        188    * Finds the function in the dictionary.
189    *                                              189    * 
190    * @param  name name of the function to be u    190    * @param  name name of the function to be unset.
191    * @param  npar number of parameters of the     191    * @param  npar number of parameters of the function.  
192    * @return true if such a function exists, f    192    * @return true if such a function exists, false otherwise.
193    */                                             193    */
194   bool findFunction(const char * name, int npa    194   bool findFunction(const char * name, int npar) const;
195                                                   195 
196   /**                                             196   /**
197    * Removes the variable from the dictionary.    197    * Removes the variable from the dictionary.
198    *                                              198    * 
199    * @param name name of the variable.            199    * @param name name of the variable.
200    */                                             200    */
201   void removeVariable(const char * name);         201   void removeVariable(const char * name);
202                                                   202 
203   /**                                             203   /**
204    * Removes the function from the dictionary.    204    * Removes the function from the dictionary.
205    *                                              205    * 
206    * @param name name of the function to be un    206    * @param name name of the function to be unset.
207    * @param npar number of parameters of the f    207    * @param npar number of parameters of the function.  
208    */                                             208    */
209   void removeFunction(const char * name, int n    209   void removeFunction(const char * name, int npar);
210                                                   210 
211   /**                                             211   /**
212    * Clear all settings.                          212    * Clear all settings.
213    */                                             213    */
214   void clear();                                   214   void clear();
215                                                   215 
216   /**                                             216   /**
217    * Sets standard mathematical functions and     217    * Sets standard mathematical functions and constants.
218    */                                             218    */
219   void setStdMath();                              219   void setStdMath();
220                                                   220 
221   /**                                             221   /**
222    * Sets system of units. Default is the SI s    222    * Sets system of units. Default is the SI system of units.
223    * To set the CGS (Centimeter-Gram-Second) s    223    * To set the CGS (Centimeter-Gram-Second) system of units
224    * one should call:                             224    * one should call:
225    *   setSystemOfUnits(100., 1000., 1.0, 1.0,    225    *   setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0);
226    *                                              226    *
227    * To set system of units accepted in the GE    227    * To set system of units accepted in the GEANT4 simulation toolkit
228    * one should call:                             228    * one should call:
229    * @code                                        229    * @code
230    *   setSystemOfUnits(1.e+3, 1./1.60217733e-    230    *   setSystemOfUnits(1.e+3, 1./1.60217733e-25, 1.e+9, 1./1.60217733e-10,
231    *                    1.0, 1.0, 1.0);           231    *                    1.0, 1.0, 1.0);
232    * @endcode                                     232    * @endcode
233    *                                              233    *
234    * The basic units in GEANT4 are:               234    * The basic units in GEANT4 are:
235    * @code                                        235    * @code
236    *   millimeter              (millimeter = 1    236    *   millimeter              (millimeter = 1.)
237    *   nanosecond              (nanosecond = 1    237    *   nanosecond              (nanosecond = 1.)
238    *   Mega electron Volt      (MeV        = 1    238    *   Mega electron Volt      (MeV        = 1.)
239    *   positron charge         (eplus      = 1    239    *   positron charge         (eplus      = 1.)
240    *   degree Kelvin           (kelvin     = 1    240    *   degree Kelvin           (kelvin     = 1.)
241    *   the amount of substance (mole       = 1    241    *   the amount of substance (mole       = 1.)
242    *   luminous intensity      (candela    = 1    242    *   luminous intensity      (candela    = 1.)
243    *   radian                  (radian     = 1    243    *   radian                  (radian     = 1.)
244    *   steradian               (steradian  = 1    244    *   steradian               (steradian  = 1.)
245    * @endcode                                     245    * @endcode
246    */                                             246    */
247   void setSystemOfUnits(double meter    = 1.0,    247   void setSystemOfUnits(double meter    = 1.0,
248                         double kilogram = 1.0,    248                         double kilogram = 1.0,
249                         double second   = 1.0,    249                         double second   = 1.0,
250                         double ampere   = 1.0,    250                         double ampere   = 1.0,
251                         double kelvin   = 1.0,    251                         double kelvin   = 1.0,
252                         double mole     = 1.0,    252                         double mole     = 1.0,
253                         double candela  = 1.0)    253                         double candela  = 1.0);
254                                                   254 
255 private:                                          255 private: 
256   void * p;                                 //    256   void * p;                                 // private data 
257   Evaluator(const Evaluator &);             //    257   Evaluator(const Evaluator &);             // copy constructor is not allowed
258   Evaluator & operator=(const Evaluator &); //    258   Evaluator & operator=(const Evaluator &); // assignment is not allowed
259 };                                                259 };
260                                                   260 
261 } // namespace HepTool                            261 } // namespace HepTool
262                                                   262 
263 #endif /* HEP_EVALUATOR_H */                      263 #endif /* HEP_EVALUATOR_H */
264                                                   264