Debian Codegraph @

src/main/c/jpy_conv.h

raw symbols SCIP
1 /*
2 * Copyright 2015 Brockmann Consult GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef JPY_CONV_H
18 #define JPY_CONV_H
19
20 #include "jpy_compat.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #define JPy_AS_JBOOLEAN(pyArg) (jboolean) (pyArg == Py_True ? 1 : (pyArg == Py_False || pyArg == Py_None) ? 0 : PyObject_IsTrue(pyArg))
27 #define JPy_AS_JCHAR(pyArg) (jchar) (pyArg == Py_None ? 0 : JPy_AS_CLONG(pyArg))
28 #define JPy_AS_JBYTE(pyArg) (jbyte) (pyArg == Py_None ? 0 : JPy_AS_CLONG(pyArg))
29 #define JPy_AS_JSHORT(pyArg) (jshort) (pyArg == Py_None ? 0 : JPy_AS_CLONG(pyArg))
30 #define JPy_AS_JINT(pyArg) (jint) (pyArg == Py_None ? 0 : JPy_AS_CLONG(pyArg))
31 #define JPy_AS_JLONG(pyArg) (jlong) (pyArg == Py_None ? 0 : JPy_AS_CLONGLONG(pyArg))
32 #define JPy_AS_JFLOAT(pyArg) (jfloat) (pyArg == Py_None ? 0 : PyFloat_AsDouble(pyArg))
33 #define JPy_AS_JDOUBLE(pyArg) (jdouble) (pyArg == Py_None ? 0 : PyFloat_AsDouble(pyArg))
34 #define JPy_FROM_JBOOLEAN(jArg) PyBool_FromLong(jArg)
35 #define JPy_FROM_JCHAR(jArg) PyLong_FromLong(jArg)
36 #define JPy_FROM_JBYTE(jArg) PyLong_FromLong(jArg)
37 #define JPy_FROM_JSHORT(jArg) PyLong_FromLong(jArg)
38 #define JPy_FROM_JINT(jArg) PyLong_FromLong(jArg)
39 #define JPy_FROM_JLONG(jArg) PyLong_FromLongLong(jArg)
40 #define JPy_FROM_JFLOAT(jArg) PyFloat_FromDouble(jArg)
41 #define JPy_FROM_JDOUBLE(jArg) PyFloat_FromDouble(jArg)
42
43 #define JPy_PY_NONE() Py_BuildValue("") // Builds a Python 'None' object
44 #define JPy_FROM_JVOID() JPy_PY_NONE()
45 #define JPy_FROM_JNULL() JPy_PY_NONE()
46
47
48 /**
49 * Convert Java string to Python string/unicode object.
50 */
51 PyObject* JPy_FromJString(JNIEnv* jenv, jstring stringRef);
52
53 /**
54 * Convert any Java Object to Python Object.
55 */
56 PyObject* JPy_FromJObject(JNIEnv* jenv, jobject objectRef);
57
58 /**
59 * Convert any Java Object of known type to Python Object.
60 */
61 PyObject* JPy_FromJObjectWithType(JNIEnv* jenv, jobject objectRef, JPy_JType* type);
62
63 /**
64 * Convert Python unicode object to Java String.
65 */
66 int JPy_AsJString(JNIEnv* jenv, PyObject* pyObj, jstring* stringRef);
67
68 /**
69 * Convert any Python objects to Java object.
70 *
71 * @param allowObjectWrapping if true, may return a PyObject for unrecognized object types
72 */
73 int JPy_AsJObject(JNIEnv* jenv, PyObject* pyObj, jobject* objectRef, jboolean allowObjectWrapping);
74
75 /**
76 * Convert Python objects to Java object with known type.
77 */
78 int JPy_AsJObjectWithType(JNIEnv* jenv, PyObject* pyObj, jobject* objectRef, JPy_JType* type);
79
80 /**
81 * Convert Python objects to Java object with known type.
82 */
83 int JPy_AsJObjectWithClass(JNIEnv* jenv, PyObject* pyObj, jobject* objectRef, jclass classRef);
84
85
86 /**
87 * Creates a Python unicode object representing the name of the given class.
88 * Returns a new reference.
89 */
90 PyObject* JPy_FromTypeName(JNIEnv* jenv, jclass classRef);
91
92 /**
93 * Gets the UTF8-encoded name of the given Java type.
94 * Caller is responsible for freeing the returned string using PyMem_Del().
95 */
96 char* JPy_GetTypeName(JNIEnv* jenv, jclass classRef);
97
98
99 #ifdef __cplusplus
100 } /* extern "C" */
101 #endif
102
103 #endif /* !JPY_CONV_H */