Version: 6.3.1

src/MEDCalculator/Swig/SPythonParser.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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 __SPYTHONPARSER_HXX__
00021 #define __SPYTHONPARSER_HXX__
00022 
00023 #include "Python.h"
00024 
00025 #include <string>
00026 #include <vector>
00027 
00028 namespace ParaMEDMEM
00029 {
00030   typedef enum
00031     {
00032       EMPTY_TYPE=0,
00033       FLOAT_TYPE=2,
00034       INT_TYPE=3,
00035       FIELDDB_TYPE=4,
00036       FUNC_TYPE=5,
00037       UNKNOWN_TYPE=6,
00038       IDENTITY_TYPE=7
00039     } TypeOfEntity;
00040 
00041   class SPythonParser;
00042 
00043   class SPythonPredParser
00044   {
00045   public:
00046     SPythonPredParser();
00047     TypeOfEntity getType() const { return _type; }
00048     void assign(const std::string& s, PyObject *glob, PyObject *loc);
00049     std::string getRepr() const;
00050     bool empty() const;
00051     static TypeOfEntity getTypeOfVar(const std::string& var, PyObject *glob, PyObject *loc);
00052   public:
00053     static const char FIELD_TYPE_STR[];
00054   private:
00055     std::string _var;
00056     std::string _method;
00057     TypeOfEntity _type;
00058   };
00059 
00063   class SPythonParser
00064   {
00065   public:
00066     SPythonParser();
00067     TypeOfEntity getType() const { return _type; }
00068     bool parseWithoutEqual(const std::string& s, int parLev, PyObject *glob, PyObject *loc, std::vector<SPythonParser>& alreadyParsed);
00069     TypeOfEntity getTypeOfElt(const std::string& elt, PyObject *glob, PyObject *loc, const std::vector<SPythonParser>& alreadyParsed) const;
00070     TypeOfEntity combineType(TypeOfEntity t1, TypeOfEntity t2) const;
00071     std::string getRepr(const std::vector<SPythonParser>& v) const;
00072     std::string replaceByCompacted(const std::string& s, int parLev, int id) const;
00073     std::string substitute(const std::vector<SPythonParser>& v) const;
00074     TypeOfEntity analyzeType(PyObject *glob, PyObject *loc, const std::vector<SPythonParser>& alreadyParsed);
00075     void keepSelectedLevOfPar(const std::string& s, int parLev, PyObject *glob, PyObject *loc);
00076     static std::vector<int> levOfParenthesis(const std::string& s);
00077     //
00078     static void replaceFromCompacted(std::string& ret,const std::vector<SPythonParser>& v);
00079     static bool isAlreadyControledParenthesis(const std::string& s);
00080     static bool isParenthesisMatching(const std::string& s, std::string& res);
00081     static bool isElementInParenthesisMatching(const std::string& s, std::string& result, bool& isNumber);
00082   public:
00083     static const char NUMBERS[];
00084   private:
00085     TypeOfEntity _type;
00086     SPythonPredParser _pred;
00087     std::string _content;
00088     std::string _content_py;
00089   };
00090 
00095   class SPythonParserHL
00096   {
00097   public:
00098     SPythonParserHL(PyObject *glob, PyObject *loc);
00099     bool parse(const std::string& s, std::string& result);
00100     static std::vector<std::string> splitBetweenEqualChar(const std::string &s);
00101   private:
00102     bool parseWithoutEqual(const std::string& s, TypeOfEntity& type, std::string& result);
00103   private:
00104     PyObject *_glob;
00105     PyObject *_loc;
00106   };
00107 }
00108 
00109 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS