CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

testEvaluator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: testEvaluator.cc,v 1.1 2003/07/16 21:47:28 garren Exp $
3 // ---------------------------------------------------------------------------
4 //
5 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
6 //
7 // This is a test for the Evaluator class.
8 // It can be also used as a scientific caculator.
9 //
10 
12 #include <iostream>
13 #include <string.h>
14 #include <assert.h>
15 
16 int main() {
17  char exp[240];
19 
20  eval.setVariable(" dummy ", 0.); // these three lines have been
21  assert( eval.findVariable(" dummy ") ); // included just for test
22  eval.clear(); // ===========================
23 
24  eval.setStdMath(); // set standard constants and functions
25  eval.setSystemOfUnits(); // set SI units
26  std::cout.precision(15);
27  for(;;) {
28  std::cout << "CALC> ";
29 
30  // In principle, next two lines could be replaced with just
31  // std::cin.getline(exp, 240); but that does not work on DEC
32  // because of bug in the cxx V6.1-027 compiler.
33  std::cin.get(exp, 240);
34  std::cin.ignore();
35  if ( !std::cin || strcmp(exp,"exit") == 0 || strcmp(exp,"quit") == 0) {
36  std::cout << std::endl;
37  break; // exit
38  }
39  double value = eval.evaluate(exp);
40  switch(eval.status()) {
42  std::cout << value << std::endl;
43  break;
45  continue;
46  default:
47  std::cout << "------";
48  for (int i=0; i<eval.error_position(); i++) std::cout << "-";
49  std::cout << "^" << std::endl;
50  eval.print_error();
51  }
52  std::cout << std::endl;
53  }
54  return 0;
55 }
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)
int main()
int error_position() const
Definition: Evaluator.cc:637
int status() const
Definition: Evaluator.cc:632
void setVariable(const char *name, double value)
Definition: Evaluator.cc:688
double eval(std::string expr, int &numbad, std::ofstream &os)
Definition: testBug66214.cc:11
double evaluate(const char *expression)
Definition: Evaluator.cc:612
bool findVariable(const char *name) const
Definition: Evaluator.cc:722
void print_error() const
Definition: Evaluator.cc:642