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

Last change on this file since 2779 was 2598, checked in by ansari, 21 years ago

Documentation (ajoutee ou completee) pour les classes du module SysTools - Reza 11 Aout 2004

File size: 2.3 KB
RevLine 
[2510]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
[2598]16/*!
17 \ingroup SysTools
18 \brief Exception class used by CExpressionEvaluator
19*/
[2512]20class CExprException : public PException {
[2510]21 public:
22 explicit CExprException(const char * m) : PException(m) {}
23 explicit CExprException(const string& m) : PException(m) {}
24};
25
26//--------------------------------------------------------------------
[2598]27/*!
28 \ingroup SysTools
29 \brief Base class for arithmetic expressions used by CExpressionEvaluator
30 \sa CExpressionEvaluator
31*/
[2510]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
[2598]48/*!
49 \ingroup SysTools
50 \brief For formatted write (print) of expressions in a stream
51*/
[2510]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();
[2598]62//! Evaluate the expression and returns the corresponding value.
[2510]63 virtual double Evaluate() const;
[2598]64//! Alias for Evaluate()
[2510]65 inline double Value() const { return Evaluate(); }
[2598]66//! Formatted output on a stream
[2510]67 virtual void Print(ostream& os) const;
68
69protected:
[2598]70//! Does the parsing and builds an CExprBase object.
[2510]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.