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

Last change on this file since 4044 was 3586, checked in by ansari, 17 years ago

Adaptation suite modif exceptions SOPHYA heritant de std::exception , Reza 05/03/2009

File size: 2.3 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/*!
17 \ingroup SysTools
18 \brief Exception class used by CExpressionEvaluator
19*/
20class CExprException : public PException {
21 public:
22 explicit CExprException(const char * m) throw() : PException(m) {}
23 explicit CExprException(const string& m) throw() : PException(m) {}
24};
25
26//--------------------------------------------------------------------
27/*!
28 \ingroup SysTools
29 \brief Base class for arithmetic expressions used by CExpressionEvaluator
30 \sa CExpressionEvaluator
31*/
32class CExprBase {
33public:
34 explicit CExprBase();
35 virtual ~CExprBase();
36 virtual double Evaluate() const = 0;
37 virtual bool CheckE(string& errmsg) const { return true; }
38 virtual void CheckThrow(const char * msg) const;
39 inline void CheckThrow(string const & msg) const { CheckThrow(msg.c_str()); }
40 virtual void Print(ostream& os) const = 0;
41 static long NbCreate() { return totnexp_create; }
42 static long NbDelete() { return totnexp_delete; }
43protected:
44 static long totnexp_create;
45 static long totnexp_delete;
46};
47
48/*!
49 \ingroup SysTools
50 \brief For formatted write (print) of expressions in a stream
51*/
52inline ostream& operator << (ostream& s, CExprBase const & ex)
53 { ex.Print(s); return(s); }
54
55class CE_BinExp;
56class CE_FuncExp;
57//---------------------------------------------------------
58class CExpressionEvaluator : public CExprBase {
59public:
60 CExpressionEvaluator(string const & sex);
61 virtual ~CExpressionEvaluator();
62//! Evaluate the expression and returns the corresponding value.
63 virtual double Evaluate() const;
64//! Alias for Evaluate()
65 inline double Value() const { return Evaluate(); }
66//! Formatted output on a stream
67 virtual void Print(ostream& os) const;
68
69protected:
70//! Does the parsing and builds an CExprBase object.
71 CExprBase* ParseString(int extype, string fname, string const & sex,
72 size_t off, size_t& stop, string& errmsg);
73
74 CExprBase * _exp;
75};
76
77} // End of namespace SOPHYA
78
79/* end of ifdef CEXPREVAL_SEEN */
80#endif
Note: See TracBrowser for help on using the repository browser.