Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / InitializationPlugin / InitializationPlugin_PyInterp.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2 /*
3  * InitializationPlugin_PyInterp.h
4  *
5  *  Created on: Apr 2, 2015
6  *      Author: sbh
7  */
8
9 #ifndef INITIALIZATIONPLUGIN_PYINTERP_H_
10 #define INITIALIZATIONPLUGIN_PYINTERP_H_
11
12 #include <PyInterp_Interp.h>
13 #include <InitializationPlugin.h>
14
15 #include <list>
16 #include <string>
17 #include <utility>
18
19 /**
20  * \class InitializationPlugin_PyInterp
21  * \ingroup Plugins
22  * \brief Helper class for using Python interpreter.
23  */
24 class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_PyInterp : public PyInterp_Interp
25 {
26  public:
27   InitializationPlugin_PyInterp();
28   virtual ~InitializationPlugin_PyInterp();
29
30   /// Returns a list of positions for theName in theExpression.
31   std::list<std::pair<int, int> > positions(const std::string& theExpression,
32                                             const std::string& theName);
33   /// Compiles theExpression and returns a list of parameters used in theExpression.
34   std::list<std::string> compile(const std::string& theExpression);
35   /// Extends local context with the list of parameters.
36   void extendLocalContext(const std::list<std::string>& theParameters);
37   /// Clears local context.
38   void clearLocalContext();
39   /// Evaluates theExpression and returns its value.
40   double evaluate(const std::string& theExpression, std::string& theError);
41
42  protected:
43   /// Returns error message.
44   std::string errorMessage();
45   /// Overrides PyInterp_Interp.
46   virtual bool initContext();
47   /// Reimplemented from PyInterp_Interp::closeContext().
48   virtual void closeContext();
49 };
50
51 #endif /* INITIALIZATIONPLUGIN_PYINTERP_H_ */