aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-01-04 19:26:49 +0100
committerSven Gothel <[email protected]>2022-01-04 19:26:49 +0100
commit0aaacdea88915710e8d773192ae957f4f594d7af (patch)
tree6ce187ec519e9748f8c43878c3baab841713dd3f
parent68e85b1bb97838f73ad932fcb85da6ba0445df8a (diff)
Add helper_jni.hpp: convert_vector_uniqueptr_to_jarraylist(..) variant ...v0.7.6
... without passing java class type nor ctor name, just relying on ctor code.
-rw-r--r--include/jau/jni/helper_jni.hpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/include/jau/jni/helper_jni.hpp b/include/jau/jni/helper_jni.hpp
index 9a60895..20b66d7 100644
--- a/include/jau/jni/helper_jni.hpp
+++ b/include/jau/jni/helper_jni.hpp
@@ -464,6 +464,60 @@ namespace jau {
return result;
}
+ template <typename T, typename U>
+ jobject convert_vector_uniqueptr_to_jarraylist(JNIEnv *env, T& array, std::function<jobject(JNIEnv*, U*)> ctor)
+ {
+ unsigned int array_size = array.size();
+
+ jmethodID arraylist_add;
+ jobject result = get_new_arraylist(env, array_size, &arraylist_add);
+
+ if (array_size == 0)
+ {
+ return result;
+ }
+
+ for (unsigned int i = 0; i < array_size; ++i)
+ {
+ U *elem = array[i].release();
+ jobject object = ctor(env, elem);
+ if (!object)
+ {
+ throw jau::RuntimeException("Cannot create instance of class", E_FILE_LINE);
+ }
+ env->CallBooleanMethod(result, arraylist_add, object);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ }
+ return result;
+ }
+
+ template <typename T, typename U>
+ jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, T& array, std::function<jobject(JNIEnv*, U*)> ctor)
+ {
+ unsigned int array_size = array.size();
+
+ jmethodID arraylist_add;
+ jobject result = get_new_arraylist(env, array_size, &arraylist_add);
+
+ if (array_size == 0)
+ {
+ return result;
+ }
+
+ for (unsigned int i = 0; i < array_size; ++i)
+ {
+ U *elem = array[i].get();
+ jobject object = ctor(env, elem);
+ if (!object)
+ {
+ throw jau::RuntimeException("Cannot create instance of class", E_FILE_LINE);
+ }
+ env->CallBooleanMethod(result, arraylist_add, object);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ }
+ return result;
+ }
+
} // namespace direct_bt
#endif /* JAU_HELPER_JNI_HPP_ */