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 = createContextImpl();
\r
13 public void close() {
\r
14 long id = contextID;
\r
16 if (id != 0) deleteContextImpl(id);
\r
20 protected void finalize() throws Throwable {
\r
25 public void executePythonStatement(String statement) {
\r
26 executePythonStatementImpl( contextID, statement );
\r
31 public void setPythonIntegerVariable(String variableName, int value) {
\r
32 setPythonIntegerVariableImpl(contextID, variableName, value);
\r
34 public void setPythonDoubleVariable(String variableName, double value) {
\r
35 setPythonDoubleVariableImpl(contextID, variableName, value);
\r
37 public void setPythonStringVariable(String variableName, String value) {
\r
38 setPythonStringVariableImpl(contextID, variableName, value);
\r
41 public void setPythonIntegerArrayVariable(String variableName, int[] value) {
\r
42 setPythonIntegerArrayVariableImpl(contextID, variableName, value);
\r
44 public void setPythonDoubleArrayVariable(String variableName, double[] value) {
\r
45 setPythonDoubleArrayVariableImpl(contextID, variableName, value);
\r
47 public void setPythonStringArrayVariable(String variableName, String[] value) {
\r
48 setPythonStringArrayVariableImpl(contextID, variableName, value);
\r
53 public int getPythonIntegerVariable(String variableName) {
\r
54 return getPythonIntegerVariableImpl(contextID, variableName);
\r
56 public double getPythonDoubleVariable(String variableName) {
\r
57 return getPythonDoubleVariableImpl(contextID, variableName);
\r
59 public String getPythonStringVariable(String variableName) {
\r
60 return getPythonStringVariableImpl(contextID, variableName);
\r
63 public int[] getPythonIntegerArrayVariable(String variableName) {
\r
64 return getPythonIntegerArrayVariableImpl(contextID, variableName);
\r
66 public double[] getPythonDoubleArrayVariable(String variableName) {
\r
67 return getPythonDoubleArrayVariableImpl(contextID, variableName);
\r
69 public String[] getPythonStringArrayVariable(String variableName) {
\r
70 return getPythonStringArrayVariableImpl(contextID, variableName);
\r
73 public void setPythonNDArrayVariable(String variableName, NDArray value) {
\r
74 setPythonNDArrayVariableImpl(contextID, variableName, value);
\r
76 public NDArray getPythonNDArrayVariable(String variableName) {
\r
77 return getPythonNDArrayVariableImpl(contextID, variableName);
\r
80 // Native function declarations
\r
81 private static native long createContextImpl();
\r
82 private static native void deleteContextImpl(long contextID);
\r
84 private static native int executePythonStatementImpl(long contextID, String statement);
\r
86 private static native void setPythonIntegerVariableImpl(long contextID, String variableName, int value);
\r
87 private static native void setPythonDoubleVariableImpl(long contextID, String variableName, double value);
\r
88 private static native void setPythonStringVariableImpl(long contextID, String variableName, String value);
\r
90 private static native void setPythonIntegerArrayVariableImpl(long contextID, String variableName, int[] value);
\r
91 private static native void setPythonDoubleArrayVariableImpl(long contextID, String variableName, double[] value);
\r
92 private static native void setPythonStringArrayVariableImpl(long contextID, String variableName, String[] value);
\r
94 private static native int getPythonIntegerVariableImpl(long contextID, String variableName);
\r
95 private static native double getPythonDoubleVariableImpl(long contextID, String variableName);
\r
96 private static native String getPythonStringVariableImpl(long contextID, String variableName);
\r
98 private static native int[] getPythonIntegerArrayVariableImpl(long contextID, String variableName);
\r
99 private static native double[] getPythonDoubleArrayVariableImpl(long contextID, String variableName);
\r
100 private static native String[] getPythonStringArrayVariableImpl(long contextID, String variableName);
\r
102 private static native void setPythonNDArrayVariableImpl(long contextID, String variableName, NDArray value);
\r
103 private static native NDArray getPythonNDArrayVariableImpl(long contextID, String variableName);
\r