--- /dev/null
+package org.simantics.pythonlink;\r
+\r
+import java.io.Closeable;\r
+\r
+public class PythonContext implements Closeable {\r
+ private long contextID;\r
+ \r
+ PythonContext() {\r
+ contextID = openPythonContextImpl();\r
+ }\r
+ \r
+ @Override\r
+ public void close() {\r
+ long id = contextID;\r
+ contextID = 0;\r
+ closePythonContextImpl(id);\r
+ }\r
+ \r
+ public void executePythonStatement(String statement) {\r
+ executePythonStatementImpl( contextID, statement );\r
+ }\r
+ \r
+ public void setPythonIntegerVariable(String variableName, int value) {\r
+ setPythonIntegerVariableImpl(contextID, variableName, value);\r
+ }\r
+ public void setPythonDoubleVariable(String variableName, double value) {\r
+ setPythonDoubleVariableImpl(contextID, variableName, value);\r
+ }\r
+ public void setPythonStringVariable(String variableName, String value) {\r
+ setPythonStringVariableImpl(contextID, variableName, value);\r
+ }\r
+ \r
+ public void setPythonIntegerArrayVariable(String variableName, int[] value) {\r
+ setPythonIntegerArrayVariableImpl(contextID, variableName, value);\r
+ }\r
+ public void setPythonDoubleArrayVariable(String variableName, double[] value) {\r
+ setPythonDoubleArrayVariableImpl(contextID, variableName, value);\r
+ }\r
+ public void setPythonStringArrayVariable(String variableName, String[] value) {\r
+ setPythonStringArrayVariableImpl(contextID, variableName, value);\r
+ }\r
+ \r
+ public int getPythonIntegerVariable(String variableName) {\r
+ return getPythonIntegerVariableImpl(contextID, variableName);\r
+ }\r
+ public double getPythonDoubleVariable(String variableName) {\r
+ return getPythonDoubleVariableImpl(contextID, variableName);\r
+ }\r
+ public String getPythonStringVariable(String variableName) {\r
+ return getPythonStringVariableImpl(contextID, variableName);\r
+ }\r
+ \r
+ public int[] getPythonIntegerArrayVariable(String variableName) {\r
+ return getPythonIntegerArrayVariableImpl(contextID, variableName);\r
+ }\r
+ public double[] getPythonDoubleArrayVariable(String variableName) {\r
+ return getPythonDoubleArrayVariableImpl(contextID, variableName);\r
+ }\r
+ public String[] getPythonStringArrayVariable(String variableName) {\r
+ return getPythonStringArrayVariableImpl(contextID, variableName);\r
+ }\r
+ \r
+ public void setPythonNDArrayVariable(String variableName, NDArray value) {\r
+ setPythonNDArrayVariableImpl(contextID, variableName, value);\r
+ }\r
+ public NDArray getPythonNDArrayVariable(String variableName) {\r
+ return getPythonNDArrayVariableImpl(contextID, variableName);\r
+ }\r
+\r
+ // Native function declarations\r
+ private static native long openPythonContextImpl();\r
+ private static native void closePythonContextImpl(long contextID);\r
+ \r
+ private static native void executePythonStatementImpl(long contextID, String statement);\r
+ \r
+ private static native void setPythonIntegerVariableImpl(long contextID, String variableName, int value);\r
+ private static native void setPythonDoubleVariableImpl(long contextID, String variableName, double value);\r
+ private static native void setPythonStringVariableImpl(long contextID, String variableName, String value);\r
+ \r
+ private static native void setPythonIntegerArrayVariableImpl(long contextID, String variableName, int[] value);\r
+ private static native void setPythonDoubleArrayVariableImpl(long contextID, String variableName, double[] value);\r
+ private static native void setPythonStringArrayVariableImpl(long contextID, String variableName, String[] value);\r
+ \r
+ private static native int getPythonIntegerVariableImpl(long contextID, String variableName);\r
+ private static native double getPythonDoubleVariableImpl(long contextID, String variableName);\r
+ private static native String getPythonStringVariableImpl(long contextID, String variableName);\r
+ \r
+ private static native int[] getPythonIntegerArrayVariableImpl(long contextID, String variableName);\r
+ private static native double[] getPythonDoubleArrayVariableImpl(long contextID, String variableName);\r
+ private static native String[] getPythonStringArrayVariableImpl(long contextID, String variableName);\r
+ \r
+ private static native void setPythonNDArrayVariableImpl(long contextID, String variableName, NDArray value);\r
+ private static native NDArray getPythonNDArrayVariableImpl(long contextID, String variableName);\r
+}\r