1 package org.simantics.pythonlink;
\r
3 import java.io.Closeable;
\r
5 public class PythonContext implements Closeable {
\r
6 private long contextID;
\r
9 contextID = openPythonContextImpl();
\r
13 public void close() {
\r
14 long id = contextID;
\r
16 closePythonContextImpl(id);
\r
19 public void executePythonStatement(String statement) {
\r
20 executePythonStatementImpl( contextID, statement );
\r
23 public void setPythonIntegerVariable(String variableName, int value) {
\r
24 setPythonIntegerVariableImpl(contextID, variableName, value);
\r
26 public void setPythonDoubleVariable(String variableName, double value) {
\r
27 setPythonDoubleVariableImpl(contextID, variableName, value);
\r
29 public void setPythonStringVariable(String variableName, String value) {
\r
30 setPythonStringVariableImpl(contextID, variableName, value);
\r
33 public void setPythonIntegerArrayVariable(String variableName, int[] value) {
\r
34 setPythonIntegerArrayVariableImpl(contextID, variableName, value);
\r
36 public void setPythonDoubleArrayVariable(String variableName, double[] value) {
\r
37 setPythonDoubleArrayVariableImpl(contextID, variableName, value);
\r
39 public void setPythonStringArrayVariable(String variableName, String[] value) {
\r
40 setPythonStringArrayVariableImpl(contextID, variableName, value);
\r
43 public int getPythonIntegerVariable(String variableName) {
\r
44 return getPythonIntegerVariableImpl(contextID, variableName);
\r
46 public double getPythonDoubleVariable(String variableName) {
\r
47 return getPythonDoubleVariableImpl(contextID, variableName);
\r
49 public String getPythonStringVariable(String variableName) {
\r
50 return getPythonStringVariableImpl(contextID, variableName);
\r
53 public int[] getPythonIntegerArrayVariable(String variableName) {
\r
54 return getPythonIntegerArrayVariableImpl(contextID, variableName);
\r
56 public double[] getPythonDoubleArrayVariable(String variableName) {
\r
57 return getPythonDoubleArrayVariableImpl(contextID, variableName);
\r
59 public String[] getPythonStringArrayVariable(String variableName) {
\r
60 return getPythonStringArrayVariableImpl(contextID, variableName);
\r
63 public void setPythonNDArrayVariable(String variableName, NDArray value) {
\r
64 setPythonNDArrayVariableImpl(contextID, variableName, value);
\r
66 public NDArray getPythonNDArrayVariable(String variableName) {
\r
67 return getPythonNDArrayVariableImpl(contextID, variableName);
\r
70 // Native function declarations
\r
71 private static native long openPythonContextImpl();
\r
72 private static native void closePythonContextImpl(long contextID);
\r
74 private static native void executePythonStatementImpl(long contextID, String statement);
\r
76 private static native void setPythonIntegerVariableImpl(long contextID, String variableName, int value);
\r
77 private static native void setPythonDoubleVariableImpl(long contextID, String variableName, double value);
\r
78 private static native void setPythonStringVariableImpl(long contextID, String variableName, String value);
\r
80 private static native void setPythonIntegerArrayVariableImpl(long contextID, String variableName, int[] value);
\r
81 private static native void setPythonDoubleArrayVariableImpl(long contextID, String variableName, double[] value);
\r
82 private static native void setPythonStringArrayVariableImpl(long contextID, String variableName, String[] value);
\r
84 private static native int getPythonIntegerVariableImpl(long contextID, String variableName);
\r
85 private static native double getPythonDoubleVariableImpl(long contextID, String variableName);
\r
86 private static native String getPythonStringVariableImpl(long contextID, String variableName);
\r
88 private static native int[] getPythonIntegerArrayVariableImpl(long contextID, String variableName);
\r
89 private static native double[] getPythonDoubleArrayVariableImpl(long contextID, String variableName);
\r
90 private static native String[] getPythonStringArrayVariableImpl(long contextID, String variableName);
\r
92 private static native void setPythonNDArrayVariableImpl(long contextID, String variableName, NDArray value);
\r
93 private static native NDArray getPythonNDArrayVariableImpl(long contextID, String variableName);
\r