BALL  1.5.0
pyInterpreter.h
Go to the documentation of this file.
1 #ifndef BALL_PYTHON_PYINTERPRETER_H
2 #define BALL_PYTHON_PYINTERPRETER_H
3 
4 // This has to be included before Python.h to prevent macro redefinition clashes in macOS Python...
5 #include <BALL/SYSTEM/path.h>
6 
7 #include <BALL/PYTHON/pyKernel.h>
8 #include <BALL/PYTHON/pyServer.h>
9 
10 #include <memory>
11 #include <vector>
12 
13 #include <QtCore/QList>
14 #include <QtCore/QPair>
15 #include <QtCore/QString>
16 
17 namespace BALL
18 {
26  {
27  private:
28  // We don't want anybody to instantiate this!
29  PyInterpreter() = default;
30  ~PyInterpreter() = default;
31 
32  public:
35  using PathStrings = std::vector<String>;
38 
41 
50  static void initialize();
51 
56  static void finalize();
57 
61  static bool isInitialized() { return kernel_ && kernel_->isStarted(); }
62 
67  BALL_DEPRECATED static void setSysPath(const PathStrings& path_strings) { sys_path_ = path_strings; }
68 
73  BALL_DEPRECATED static const PathStrings& getSysPath() { return sys_path_; }
74 
76  BALL_DEPRECATED static bool isValid() { return isInitialized(); }
77 
79  BALL_DEPRECATED static String getStartupLog() { return String(); }
80 
82 
83 
91  static std::pair<bool, std::string> run(const std::string& s);
92 
94  BALL_DEPRECATED static String run(const String& s, bool& result);
95 
101  BALL_DEPRECATED static String runFile(const String& filename);
102 
111  static bool execute(const std::string& module, const std::string& func, const PyKernel::KeyValArgs& params);
112 
118  static std::string getErrorMessage();
119 
121  BALL_DEPRECATED static bool execute(const QString& module, const QString& func, const QList<QPair<QString, QString> >& params);
123 
124 
127 
132  static void startServer();
133 
137  static void stopServer();
138 
144  static bool serverIsRunning() { return bool(server_); }
146 
147  protected:
148  static std::unique_ptr<PyKernel> kernel_;
149  static std::unique_ptr<PyServer> server_;
151  };
152 
153 } // namespace BALL
154 
155 #endif // BALL_PYTHON_PYINTERPRETER_H
BALL_EXPORT
#define BALL_EXPORT
Definition: COMMON/global.h:50
BALL::PyInterpreter::run
static BALL_DEPRECATED String run(const String &s, bool &result)
BALL::PyInterpreter::initialize
static void initialize()
pyKernel.h
BALL::PyInterpreter::isInitialized
static bool isInitialized()
Definition: pyInterpreter.h:61
BALL::PyInterpreter::isValid
static BALL_DEPRECATED bool isValid()
Definition: pyInterpreter.h:76
BALL::PyInterpreter::getErrorMessage
static std::string getErrorMessage()
BALL::String
Definition: string.h:57
BALL::PyKernel::KeyValArgs
std::map< std::string, std::string > KeyValArgs
Definition: pyKernel.h:17
BALL
Definition: constants.h:13
BALL::PyInterpreter::serverIsRunning
static bool serverIsRunning()
Definition: pyInterpreter.h:144
BALL::PyInterpreter::PathStrings
std::vector< String > PathStrings
Used to encode the individual paths appended to sys.path for dynamic loading of modules.
Definition: pyInterpreter.h:36
BALL::PyInterpreter::stopServer
static void stopServer()
BALL::PyInterpreter::runFile
static BALL_DEPRECATED String runFile(const String &filename)
BALL::PyInterpreter
Definition: pyInterpreter.h:26
BALL::PyInterpreter::getSysPath
static BALL_DEPRECATED const PathStrings & getSysPath()
Definition: pyInterpreter.h:73
BALL::PyInterpreter::run
static std::pair< bool, std::string > run(const std::string &s)
pyServer.h
BALL::PyInterpreter::setSysPath
static BALL_DEPRECATED void setSysPath(const PathStrings &path_strings)
Definition: pyInterpreter.h:67
BALL::PyInterpreter::startServer
static void startServer()
BALL::PyInterpreter::execute
static BALL_DEPRECATED bool execute(const QString &module, const QString &func, const QList< QPair< QString, QString > > &params)
BALL::PyInterpreter::execute
static bool execute(const std::string &module, const std::string &func, const PyKernel::KeyValArgs &params)
BALL::PyInterpreter::server_
static std::unique_ptr< PyServer > server_
Definition: pyInterpreter.h:149
path.h
BALL::PyInterpreter::kernel_
static std::unique_ptr< PyKernel > kernel_
Definition: pyInterpreter.h:148
BALL::PyInterpreter::finalize
static void finalize()
BALL::PyInterpreter::getStartupLog
static BALL_DEPRECATED String getStartupLog()
Definition: pyInterpreter.h:79
BALL_DEPRECATED
#define BALL_DEPRECATED
Definition: COMMON/global.h:64
bool
BALL::PyInterpreter::sys_path_
static PathStrings sys_path_
Definition: pyInterpreter.h:150