Back to index

salome-med  6.5.0
SPythonInterpreter.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef __SPYTHONINTERPRETER_HXX__
00021 #define __SPYTHONINTERPRETER_HXX__
00022 
00023 // rnv: avoid compilation warning on Linux : "_POSIX_C_SOURCE" and "_XOPEN_SOURCE" are redefined
00024 #ifdef _POSIX_C_SOURCE
00025 #undef _POSIX_C_SOURCE
00026 #endif 
00027 
00028 #ifdef _XOPEN_SOURCE
00029 #undef _XOPEN_SOURCE
00030 #endif 
00031 
00032 #include <Python.h>
00033 
00034 #include "MedCalculatorSPythonDefines.hxx"
00035 
00036 #include <string>
00037 #include <vector>
00038 #include <set>
00039 
00040 namespace ParaMEDMEM
00041 {
00042   class MEDCALCULATORSPYTHON_EXPORT SPythonInterpreter
00043   {
00044   public:
00045     SPythonInterpreter(PyObject *globals, PyObject *locals);
00046     void initialize();
00047     bool run(const char *str, bool& isSPython);
00048     bool finishSession();
00049   private:
00050     bool checkIndentCoherency(const std::string& s, std::size_t p);
00051     void checkPythonInterp(PyObject *r);
00052     bool isIndenter(const std::string& s, std::size_t p);
00053     bool isSPythonExpression(const std::string& s);
00054     bool isSPythonExpressionLev1(const std::string& s, std::string& result);
00055   public:
00056     static std::string strip(const std::string& s);
00057     static bool isSpythonManipulationNeeded(const std::string& s, std::string& pythonLines);
00058     static bool isCandidateParenthesis(const std::string& s, std::size_t p1, std::size_t& n);
00059   public:
00060     static const int NB_OF_INDENT=7;
00061     static const char *INDENT_TOKEN[];
00062     static const char NUMBERS[];
00063   private:
00064     std::string _cmd;
00065     std::set<int> _indent_pos;
00066     bool _indent_must_change;
00067     PyObject *_glob;
00068     PyObject *_loc;
00069   };
00070 }
00071 
00072 #endif