diff options
author | Sven Gothel <[email protected]> | 2021-11-15 05:25:17 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-11-15 05:25:17 +0100 |
commit | 58df1168f75ab5a3ce7dd9d42e22e7c6a7e80c6d (patch) | |
tree | 220605681d3d48995ca61478bc463b74d61540ba | |
parent | 3e80634725f566391992a230edfe37c0f6a042aa (diff) |
helper_jni: Add checkAndGetObject(..)
-rw-r--r-- | include/jau/jni/helper_jni.hpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/jau/jni/helper_jni.hpp b/include/jau/jni/helper_jni.hpp index 452b462..9a60895 100644 --- a/include/jau/jni/helper_jni.hpp +++ b/include/jau/jni/helper_jni.hpp @@ -153,6 +153,19 @@ namespace jau { throw RuntimeException("JavaGlobalObj::check: Null object", file, line); } } + static inline jobject checkAndGetObject(const std::shared_ptr<JavaAnon> & shref, const char* file, int line) { + if( nullptr == shref ) { + throw RuntimeException("JavaGlobalObj::check: Null shared-JavaAnonObj", file, line); + } + if( 0 == shref.use_count() ) { // safe-guard for concurrent dtor + throw RuntimeException("JavaGlobalObj::check: Empty shared-JavaAnonObj", file, line); + } + const jobject obj = static_cast<const JavaGlobalObj*>(shref.get())->getObject(); + if( nullptr == obj ) { + throw RuntimeException("JavaGlobalObj::check: Null object", file, line); + } + return obj; + } static bool isValid(const std::shared_ptr<JavaAnon> & shref) noexcept { if( nullptr == shref || 0 == shref.use_count() ) { return false; |