File indexing completed on 2024-06-23 05:08:43
0001 /* 0002 SPDX-FileCopyrightText: 2021-2022 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #ifndef KANDROIDEXTRAS_JNIARGUMENTVALUE_H 0007 #define KANDROIDEXTRAS_JNIARGUMENTVALUE_H 0008 0009 #include "jniobject.h" 0010 #include "jnitypetraits.h" 0011 0012 namespace KAndroidExtras { 0013 namespace Jni { 0014 template <typename T> class Array; 0015 } 0016 0017 ///@cond internal 0018 namespace Internal { 0019 /** Call argument wrapper. */ 0020 template <typename T, typename = std::void_t<>> 0021 struct argument { 0022 static_assert(!is_invalid_primitive_type<T>::value, "Using an incompatible primitive type!"); 0023 typedef std::conditional_t<Jni::is_primitive_type<T>::value, T, const Jni::Object<T>&> type; 0024 static inline constexpr auto toCallArgument(type value) 0025 { 0026 if constexpr (Jni::is_primitive_type<T>::value) { 0027 return primitive_value<T>::toJni(value); 0028 } else { 0029 return value.jniHandle().object(); 0030 } 0031 } 0032 }; 0033 template <typename T> 0034 struct argument<T, std::void_t<typename T::_jni_ThisType>> { 0035 typedef const T &type; 0036 static inline auto toCallArgument(const T &value) 0037 { 0038 return Jni::handle(value).object(); 0039 } 0040 }; 0041 template <typename T> 0042 struct argument<Jni::Array<T>> { 0043 typedef const Jni::Array<T>& type; 0044 static inline auto toCallArgument(const Jni::Array<T> &value) 0045 { 0046 return value.jniHandle().object(); 0047 } 0048 }; 0049 } 0050 ///@endcond 0051 } 0052 0053 #endif 0054