OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
PythonWrapper.h
Go to the documentation of this file.
1/*****************************************************************/
9#pragma once
10#define PY_SSIZE_T_CLEAN // #
11#include <Python.h>
12#include <string>
13#include <vector>
14#include <list>
16#include "CPythonObjectNew.h"
17#include "PythonException.h"
18
21public:
23 PythonWrapper(const PythonWrapper& other) = delete;
24 PythonWrapper& operator=(const PythonWrapper& other) = delete;
25 PythonWrapper(const PythonWrapper&& other) = delete;
26 PythonWrapper& operator=(const PythonWrapper&& other) = delete;
27
28
30
32 void ResetSysPath();
33 void AddToSysPath(const std::string& newPathComponent);
35
36 CPythonObjectNew execute(const std::string& _executionCommand, const std::string& _moduleName = "__main__");
37
38 CPythonObjectNew ExecuteFunction(const std::string& functionName, CPythonObject& parameter, const std::string& moduleName = "__main__");
39
40 CPythonObjectBorrowed GetGlobalVariable(const std::string& varName, const std::string& moduleName);
41
42 CPythonObjectBorrowed GetGlobalDictionary(const std::string& moduleName);
43 CPythonObjectNew GetFunction(const std::string& functionName, const std::string& moduleName = "__main__");
44
45private:
46 std::list<std::string> _pythonPath;
47 std::string _pythonRoot;
48 std::string _defaultSitePackagesPath;
49 bool _interpreterSuccessfullyInitialized = false;
50
51 int initiateNumpy();
52 std::string checkNumpyVersion();
53 std::string DeterminePythonRootDirectory();
54 std::string determineMandatoryPythonSitePackageDirectory();
55 void addOptionalUserPythonSitePackageDirectory();
56
57 static void signalHandlerAbort(int sig);
58
59 CPythonObjectNew GetModule(const std::string& moduleName);
60
61};
Wrapper around a PyObject* that is a borrowed reference. This increments the reference count on const...
Wrapper around a PyObject* that is a new reference. This owns the reference so does not increment it ...
Embedded python functions don't throw exceptions. If the return value holds an error code that says t...
Definition CPythonObjectBorrowed.h:15
Definition CPythonObject.h:13
Definition CPythonObjectNew.h:14
Definition FixturePythonWrapper.h:7
Definition PythonWrapper.h:19
void InitializePythonInterpreter()
Definition PythonWrapper.cpp:54
PythonWrapper(const PythonWrapper &&other)=delete
PythonWrapper(const PythonWrapper &other)=delete
CPythonObjectBorrowed GetGlobalDictionary(const std::string &moduleName)
Definition PythonWrapper.cpp:205
CPythonObjectNew GetFunction(const std::string &functionName, const std::string &moduleName="__main__")
Definition PythonWrapper.cpp:210
void ResetSysPath()
Definition PythonWrapper.cpp:95
PythonWrapper & operator=(const PythonWrapper &other)=delete
PythonWrapper()
Definition PythonWrapper.cpp:13
void AddToSysPath(const std::string &newPathComponent)
Definition PythonWrapper.cpp:105
CPythonObjectNew ExecuteFunction(const std::string &functionName, CPythonObject &parameter, const std::string &moduleName="__main__")
Definition PythonWrapper.cpp:183
PythonWrapper & operator=(const PythonWrapper &&other)=delete
CPythonObjectNew execute(const std::string &_executionCommand, const std::string &_moduleName="__main__")
Definition PythonWrapper.cpp:172
~PythonWrapper()
Definition PythonWrapper.cpp:41
void ClosePythonInterpreter()
Definition PythonWrapper.cpp:47
CPythonObjectBorrowed GetGlobalVariable(const std::string &varName, const std::string &moduleName)
Definition PythonWrapper.cpp:194