Salome HOME
6868fb2eaf7d82085dd7a153269a6d51b7c19d27
[modules/shaper.git] / src / InitializationPlugin / InitializationPlugin_PyInterp.h
1 // Copyright (C) 2014-2017  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, or (at your option) any later version.
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<mailto:webmaster.salome@opencascade.com>
18 //
19
20 /*
21  * InitializationPlugin_PyInterp.h
22  *
23  *  Created on: Apr 2, 2015
24  *      Author: sbh
25  */
26
27 #ifndef INITIALIZATIONPLUGIN_PYINTERP_H_
28 #define INITIALIZATIONPLUGIN_PYINTERP_H_
29
30 #include <PyInterp_Interp.h>
31 #include <InitializationPlugin.h>
32
33 #include <list>
34 #include <string>
35 #include <utility>
36
37 /**
38  * \class InitializationPlugin_PyInterp
39  * \ingroup Plugins
40  * \brief Helper class for using Python interpreter.
41  */
42 class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_PyInterp : public PyInterp_Interp
43 {
44  public:
45   InitializationPlugin_PyInterp();
46   virtual ~InitializationPlugin_PyInterp();
47
48   /// Returns a list of positions for theName in theExpression.
49   std::list<std::pair<int, int> > positions(const std::string& theExpression,
50                                             const std::string& theName);
51   /// Compiles theExpression and returns a list of parameters used in theExpression.
52   std::list<std::string> compile(const std::string& theExpression);
53   /// Extends local context with the list of parameters.
54   void extendLocalContext(const std::list<std::string>& theParameters);
55   /// Clears local context.
56   void clearLocalContext();
57   /// Evaluates theExpression and returns its value.
58   double evaluate(const std::string& theExpression, std::string& theError);
59
60  protected:
61   /// Returns error message.
62   std::string errorMessage();
63   /// Overrides PyInterp_Interp.
64   virtual bool initContext();
65   /// Reimplemented from PyInterp_Interp::closeContext().
66   virtual void closeContext();
67 };
68
69 #endif /* INITIALIZATIONPLUGIN_PYINTERP_H_ */