]> SALOME platform Git repositories - modules/med.git/blob - src/MEDCalculator/Swig/SPythonInterpreter.hxx
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDCalculator / Swig / SPythonInterpreter.hxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __SPYTHONINTERPRETER_HXX__
21 #define __SPYTHONINTERPRETER_HXX__
22
23 // rnv: avoid compilation warning on Linux : "_POSIX_C_SOURCE" and "_XOPEN_SOURCE" are redefined
24 #ifdef _POSIX_C_SOURCE
25 #undef _POSIX_C_SOURCE
26 #endif 
27
28 #ifdef _XOPEN_SOURCE
29 #undef _XOPEN_SOURCE
30 #endif 
31
32 #include <Python.h>
33
34 #include "MedCalculatorSPythonDefines.hxx"
35
36 #include <string>
37 #include <vector>
38 #include <set>
39
40 namespace ParaMEDMEM
41 {
42   class MEDCALCULATORSPYTHON_EXPORT SPythonInterpreter
43   {
44   public:
45     SPythonInterpreter(PyObject *globals, PyObject *locals);
46     void initialize();
47     bool run(const char *str, bool& isSPython);
48     bool finishSession();
49   private:
50     bool checkIndentCoherency(const std::string& s, std::size_t p);
51     void checkPythonInterp(PyObject *r);
52     bool isIndenter(const std::string& s, std::size_t p);
53     bool isSPythonExpression(const std::string& s);
54     bool isSPythonExpressionLev1(const std::string& s, std::string& result);
55   public:
56     static std::string strip(const std::string& s);
57     static bool isSpythonManipulationNeeded(const std::string& s, std::string& pythonLines);
58     static bool isCandidateParenthesis(const std::string& s, std::size_t p1, std::size_t& n);
59   public:
60     static const int NB_OF_INDENT=7;
61     static const char *INDENT_TOKEN[];
62     static const char NUMBERS[];
63   private:
64     std::string _cmd;
65     std::set<int> _indent_pos;
66     bool _indent_must_change;
67     PyObject *_glob;
68     PyObject *_loc;
69   };
70 }
71
72 #endif