From a3f7838669a9e4667285813d150f020e0cc27f6b Mon Sep 17 00:00:00 2001 From: Igor Tarasov Date: Tue, 30 Jun 2020 15:30:27 +0300 Subject: [PATCH] RegisterNativePeer() without finalizer. Needed for custom, non `finalize()`, memory management. --- include/jni/native_method.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/jni/native_method.hpp b/include/jni/native_method.hpp index 192e301..3e41140 100644 --- a/include/jni/native_method.hpp +++ b/include/jni/native_method.hpp @@ -371,6 +371,22 @@ namespace jni methods.template operator()(field)...); } + template < class Peer, class TagType, class Initializer, class... Methods > + void RegisterNativePeer(JNIEnv& env, const Class& clazz, const char* fieldName, + Initializer initialize, + const char* initializeMethodName, + Methods&&... methods) + { + static Field field { env, clazz, fieldName }; + + using InitializerMethodType = typename NativeMethodTraits::Type; + NativePeerHelper helper; + + RegisterNatives(env, *clazz, + helper.MakeInitializer(field, initializeMethodName, initialize), + methods.template operator()(field)...); + } + // Like std::make_unique, but with non-universal reference arguments, so it can be // explicitly specialized (jni::MakePeer). template < class Peer, class... Args >