From 25037b693981e0541f818b9aa44e1c20c507e284 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 27 Jan 2022 07:40:07 +0100 Subject: helper_jni: Add convert_instance_to_jobject(..) with given jclass, different from T::java_class() --- include/jau/jni/helper_jni.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include/jau/jni') 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 @@ -350,6 +350,22 @@ namespace jau { return object; } + template + jobject convert_instance_to_jobject(JNIEnv *env, jclass clazz, + const char *ctor_prototype, std::function ctor, T *elem) + { + jmethodID clazz_ctor = search_method(env, clazz, "", 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 jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, T& array) { -- cgit v1.2.3