source: Sophya/trunk/SophyaLib/SysTools/cexpre.h@ 2520

Last change on this file since 2520 was 2512, checked in by ansari, 22 years ago

Correction bugs ds CExpression/RPNExpression et adaptation classe Commander avec utilisation classe CExpressionEvaluator - Reza 16 Mars 2004

File size: 2.0 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2// Evaluateur d'expression C - R. Ansari 03/2004
3// LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
4
5#ifndef CEXPREVAL_SEEN
6#define CEXPREVAL_SEEN
7
8#include "machdefs.h"
9#include <iostream>
10#include <string>
11#include "pexceptions.h"
12
13using namespace std;
14namespace SOPHYA {
15
16//! Exception class used by CExpressionEvaluator
17class CExprException : public PException {
18 public:
19 explicit CExprException(const char * m) : PException(m) {}
20 explicit CExprException(const string& m) : PException(m) {}
21};
22
23//--------------------------------------------------------------------
24//! Base class for arithmetic expressions used by CExpressionEvaluator
25class CExprBase {
26public:
27 explicit CExprBase();
28 virtual ~CExprBase();
29 virtual double Evaluate() const = 0;
30 virtual bool CheckE(string& errmsg) const { return true; }
31 virtual void CheckThrow(const char * msg) const;
32 inline void CheckThrow(string const & msg) const { CheckThrow(msg.c_str()); }
33 virtual void Print(ostream& os) const = 0;
34 static long NbCreate() { return totnexp_create; }
35 static long NbDelete() { return totnexp_delete; }
36protected:
37 static long totnexp_create;
38 static long totnexp_delete;
39};
40
41inline ostream& operator << (ostream& s, CExprBase const & ex)
42 { ex.Print(s); return(s); }
43
44class CE_BinExp;
45class CE_FuncExp;
46//---------------------------------------------------------
47//! Class for evaluation of arithmetic expressions with C-like syntax
48class CExpressionEvaluator : public CExprBase {
49public:
50 CExpressionEvaluator(string const & sex);
51 virtual ~CExpressionEvaluator();
52 virtual double Evaluate() const;
53 inline double Value() const { return Evaluate(); }
54 virtual void Print(ostream& os) const;
55
56protected:
57 CExprBase* ParseString(int extype, string fname, string const & sex,
58 size_t off, size_t& stop, string& errmsg);
59
60 CExprBase * _exp;
61};
62
63} // End of namespace SOPHYA
64
65/* end of ifdef CEXPREVAL_SEEN */
66#endif
Note: See TracBrowser for help on using the repository browser.