diff options
author | Sven Gothel <[email protected]> | 2022-01-27 07:40:07 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-01-27 07:40:07 +0100 |
commit | 25037b693981e0541f818b9aa44e1c20c507e284 (patch) | |
tree | bdd57eab7e1bec8b02e9c55b34a8414ee3c7f162 /include/jau/jni | |
parent | 0c27e84c454bb9bf1bc33430093a143f0c47f272 (diff) |
helper_jni: Add convert_instance_to_jobject(..) with given jclass, different from T::java_class()
Diffstat (limited to 'include/jau/jni')
-rw-r--r-- | include/jau/jni/helper_jni.hpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/jau/jni/helper_jni.hpp b/include/jau/jni/helper_jni.hpp index 20b66d7..e8807e1 100644 --- a/include/jau/jni/helper_jni.hpp +++ b/include/jau/jni/helper_jni.hpp @@ -351,6 +351,22 @@ namespace jau { } template <typename T> + jobject convert_instance_to_jobject(JNIEnv *env, jclass clazz, + const char *ctor_prototype, std::function<jobject(JNIEnv*, jclass, jmethodID, T*)> ctor, T *elem) + { + jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false); + + jobject object = ctor(env, clazz, clazz_ctor, elem); + if (!object) + { + throw jau::RuntimeException("Cannot create instance of class", E_FILE_LINE); + } + java_exception_check_and_throw(env, E_FILE_LINE); + + return object; + } + + template <typename T> jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, T& array) { nsize_t array_size = array.size(); |