JNI: refactor code to use _v and _t helpers
As a drive-by, fix style by adding a whitespace after flow-control keywords `if constexpr`. Change-Id: I4e1153edc6f9ee903c7620772c12c411c33e90c6 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>bb10
parent
fe182c1541
commit
9250481384
|
|
@ -73,7 +73,7 @@ public:
|
|||
QJniEnvironment env;
|
||||
jmethodID id = getCachedMethodID(env.jniEnv(), methodName, signature);
|
||||
if (id) {
|
||||
if constexpr (std::is_same<Ret, void>::value) {
|
||||
if constexpr (std::is_same_v<Ret, void>) {
|
||||
callVoidMethodV(env.jniEnv(), id, std::forward<Args>(args)...);
|
||||
env.checkAndClearExceptions();
|
||||
} else {
|
||||
|
|
@ -84,7 +84,7 @@ public:
|
|||
return res;
|
||||
}
|
||||
}
|
||||
if constexpr (!std::is_same<Ret, void>::value)
|
||||
if constexpr (!std::is_same_v<Ret, void>)
|
||||
return Ret{};
|
||||
}
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ public:
|
|||
auto callMethod(const char *methodName, Args &&...args) const
|
||||
{
|
||||
constexpr auto signature = QtJniTypes::methodSignature<Ret, Args...>();
|
||||
if constexpr (std::is_same<Ret, void>::value) {
|
||||
if constexpr (std::is_same_v<Ret, void>) {
|
||||
callMethod<void>(methodName, signature.data(), std::forward<Args>(args)...);
|
||||
} else {
|
||||
return callMethod<Ret>(methodName, signature.data(), std::forward<Args>(args)...);
|
||||
|
|
@ -135,7 +135,7 @@ public:
|
|||
QtJniTypes::assertPrimitiveType<Ret>();
|
||||
QJniEnvironment env;
|
||||
if (clazz && methodId) {
|
||||
if constexpr (std::is_same<Ret, void>::value) {
|
||||
if constexpr (std::is_same_v<Ret, void>) {
|
||||
callStaticMethodForVoid(env.jniEnv(), clazz, methodId, std::forward<Args>(args)...);
|
||||
env.checkAndClearExceptions();
|
||||
} else {
|
||||
|
|
@ -146,7 +146,7 @@ public:
|
|||
return res;
|
||||
}
|
||||
}
|
||||
if constexpr (!std::is_same<Ret, void>::value)
|
||||
if constexpr (!std::is_same_v<Ret, void>)
|
||||
return Ret{};
|
||||
}
|
||||
}
|
||||
|
|
@ -452,21 +452,21 @@ private:
|
|||
va_list args = {};
|
||||
va_start(args, id);
|
||||
|
||||
if constexpr(std::is_same<T, jboolean>::value)
|
||||
if constexpr (std::is_same_v<T, jboolean>)
|
||||
res = env->CallBooleanMethodV(obj, id, args);
|
||||
else if constexpr(std::is_same<T, jbyte>::value)
|
||||
else if constexpr (std::is_same_v<T, jbyte>)
|
||||
res = env->CallByteMethodV(obj, id, args);
|
||||
else if constexpr(std::is_same<T, jchar>::value)
|
||||
else if constexpr (std::is_same_v<T, jchar>)
|
||||
res = env->CallCharMethodV(obj, id, args);
|
||||
else if constexpr(std::is_same<T, jshort>::value)
|
||||
else if constexpr (std::is_same_v<T, jshort>)
|
||||
res = env->CallShortMethodV(obj, id, args);
|
||||
else if constexpr(std::is_same<T, jint>::value)
|
||||
else if constexpr (std::is_same_v<T, jint>)
|
||||
res = env->CallIntMethodV(obj, id, args);
|
||||
else if constexpr(std::is_same<T, jlong>::value)
|
||||
else if constexpr (std::is_same_v<T, jlong>)
|
||||
res = env->CallLongMethodV(obj, id, args);
|
||||
else if constexpr(std::is_same<T, jfloat>::value)
|
||||
else if constexpr (std::is_same_v<T, jfloat>)
|
||||
res = env->CallFloatMethodV(obj, id, args);
|
||||
else if constexpr(std::is_same<T, jdouble>::value)
|
||||
else if constexpr (std::is_same_v<T, jdouble>)
|
||||
res = env->CallDoubleMethodV(obj, id, args);
|
||||
else
|
||||
QtJniTypes::staticAssertTypeMismatch();
|
||||
|
|
@ -479,21 +479,21 @@ private:
|
|||
{
|
||||
va_list args = {};
|
||||
va_start(args, id);
|
||||
if constexpr(std::is_same<T, jboolean>::value)
|
||||
if constexpr (std::is_same_v<T, jboolean>)
|
||||
res = env->CallStaticBooleanMethodV(clazz, id, args);
|
||||
else if constexpr(std::is_same<T, jbyte>::value)
|
||||
else if constexpr (std::is_same_v<T, jbyte>)
|
||||
res = env->CallStaticByteMethodV(clazz, id, args);
|
||||
else if constexpr(std::is_same<T, jchar>::value)
|
||||
else if constexpr (std::is_same_v<T, jchar>)
|
||||
res = env->CallStaticCharMethodV(clazz, id, args);
|
||||
else if constexpr(std::is_same<T, jshort>::value)
|
||||
else if constexpr (std::is_same_v<T, jshort>)
|
||||
res = env->CallStaticShortMethodV(clazz, id, args);
|
||||
else if constexpr(std::is_same<T, jint>::value)
|
||||
else if constexpr (std::is_same_v<T, jint>)
|
||||
res = env->CallStaticIntMethodV(clazz, id, args);
|
||||
else if constexpr(std::is_same<T, jlong>::value)
|
||||
else if constexpr (std::is_same_v<T, jlong>)
|
||||
res = env->CallStaticLongMethodV(clazz, id, args);
|
||||
else if constexpr(std::is_same<T, jfloat>::value)
|
||||
else if constexpr (std::is_same_v<T, jfloat>)
|
||||
res = env->CallStaticFloatMethodV(clazz, id, args);
|
||||
else if constexpr(std::is_same<T, jdouble>::value)
|
||||
else if constexpr (std::is_same_v<T, jdouble>)
|
||||
res = env->CallStaticDoubleMethodV(clazz, id, args);
|
||||
else
|
||||
QtJniTypes::staticAssertTypeMismatch();
|
||||
|
|
@ -513,21 +513,21 @@ private:
|
|||
static constexpr void getFieldForType(JNIEnv *env, T &res, jobject obj,
|
||||
jfieldID id)
|
||||
{
|
||||
if constexpr(std::is_same<T, jboolean>::value)
|
||||
if constexpr (std::is_same_v<T, jboolean>)
|
||||
res = env->GetBooleanField(obj, id);
|
||||
else if constexpr(std::is_same<T, jbyte>::value)
|
||||
else if constexpr (std::is_same_v<T, jbyte>)
|
||||
res = env->GetByteField(obj, id);
|
||||
else if constexpr(std::is_same<T, jchar>::value)
|
||||
else if constexpr (std::is_same_v<T, jchar>)
|
||||
res = env->GetCharField(obj, id);
|
||||
else if constexpr(std::is_same<T, jshort>::value)
|
||||
else if constexpr (std::is_same_v<T, jshort>)
|
||||
res = env->GetShortField(obj, id);
|
||||
else if constexpr(std::is_same<T, jint>::value)
|
||||
else if constexpr (std::is_same_v<T, jint>)
|
||||
res = env->GetIntField(obj, id);
|
||||
else if constexpr(std::is_same<T, jlong>::value)
|
||||
else if constexpr (std::is_same_v<T, jlong>)
|
||||
res = env->GetLongField(obj, id);
|
||||
else if constexpr(std::is_same<T, jfloat>::value)
|
||||
else if constexpr (std::is_same_v<T, jfloat>)
|
||||
res = env->GetFloatField(obj, id);
|
||||
else if constexpr(std::is_same<T, jdouble>::value)
|
||||
else if constexpr (std::is_same_v<T, jdouble>)
|
||||
res = env->GetDoubleField(obj, id);
|
||||
else
|
||||
QtJniTypes::staticAssertTypeMismatch();
|
||||
|
|
@ -537,21 +537,21 @@ private:
|
|||
static constexpr void getStaticFieldForType(JNIEnv *env, T &res, jclass clazz,
|
||||
jfieldID id)
|
||||
{
|
||||
if constexpr(std::is_same<T, jboolean>::value)
|
||||
if constexpr (std::is_same_v<T, jboolean>)
|
||||
res = env->GetStaticBooleanField(clazz, id);
|
||||
else if constexpr(std::is_same<T, jbyte>::value)
|
||||
else if constexpr (std::is_same_v<T, jbyte>)
|
||||
res = env->GetStaticByteField(clazz, id);
|
||||
else if constexpr(std::is_same<T, jchar>::value)
|
||||
else if constexpr (std::is_same_v<T, jchar>)
|
||||
res = env->GetStaticCharField(clazz, id);
|
||||
else if constexpr(std::is_same<T, jshort>::value)
|
||||
else if constexpr (std::is_same_v<T, jshort>)
|
||||
res = env->GetStaticShortField(clazz, id);
|
||||
else if constexpr(std::is_same<T, jint>::value)
|
||||
else if constexpr (std::is_same_v<T, jint>)
|
||||
res = env->GetStaticIntField(clazz, id);
|
||||
else if constexpr(std::is_same<T, jlong>::value)
|
||||
else if constexpr (std::is_same_v<T, jlong>)
|
||||
res = env->GetStaticLongField(clazz, id);
|
||||
else if constexpr(std::is_same<T, jfloat>::value)
|
||||
else if constexpr (std::is_same_v<T, jfloat>)
|
||||
res = env->GetStaticFloatField(clazz, id);
|
||||
else if constexpr(std::is_same<T, jdouble>::value)
|
||||
else if constexpr (std::is_same_v<T, jdouble>)
|
||||
res = env->GetStaticDoubleField(clazz, id);
|
||||
else
|
||||
QtJniTypes::staticAssertTypeMismatch();
|
||||
|
|
@ -561,23 +561,23 @@ private:
|
|||
static constexpr void setFieldForType(JNIEnv *env, jobject obj,
|
||||
jfieldID id, T value)
|
||||
{
|
||||
if constexpr(std::is_same<T, jboolean>::value)
|
||||
if constexpr (std::is_same_v<T, jboolean>)
|
||||
env->SetBooleanField(obj, id, value);
|
||||
else if constexpr(std::is_same<T, jbyte>::value)
|
||||
else if constexpr (std::is_same_v<T, jbyte>)
|
||||
env->SetByteField(obj, id, value);
|
||||
else if constexpr(std::is_same<T, jchar>::value)
|
||||
else if constexpr (std::is_same_v<T, jchar>)
|
||||
env->SetCharField(obj, id, value);
|
||||
else if constexpr(std::is_same<T, jshort>::value)
|
||||
else if constexpr (std::is_same_v<T, jshort>)
|
||||
env->SetShortField(obj, id, value);
|
||||
else if constexpr(std::is_same<T, jint>::value)
|
||||
else if constexpr (std::is_same_v<T, jint>)
|
||||
env->SetIntField(obj, id, value);
|
||||
else if constexpr(std::is_same<T, jlong>::value)
|
||||
else if constexpr (std::is_same_v<T, jlong>)
|
||||
env->SetLongField(obj, id, value);
|
||||
else if constexpr(std::is_same<T, jfloat>::value)
|
||||
else if constexpr (std::is_same_v<T, jfloat>)
|
||||
env->SetFloatField(obj, id, value);
|
||||
else if constexpr(std::is_same<T, jdouble>::value)
|
||||
else if constexpr (std::is_same_v<T, jdouble>)
|
||||
env->SetDoubleField(obj, id, value);
|
||||
else if constexpr(std::is_convertible<T, jobject>::value)
|
||||
else if constexpr (std::is_convertible_v<T, jobject>)
|
||||
env->SetObjectField(obj, id, value);
|
||||
else
|
||||
QtJniTypes::staticAssertTypeMismatch();
|
||||
|
|
@ -587,23 +587,23 @@ private:
|
|||
static constexpr void setStaticFieldForType(JNIEnv *env, jclass clazz,
|
||||
jfieldID id, T value)
|
||||
{
|
||||
if constexpr(std::is_same<T, jboolean>::value)
|
||||
if constexpr (std::is_same_v<T, jboolean>)
|
||||
env->SetStaticBooleanField(clazz, id, value);
|
||||
else if constexpr(std::is_same<T, jbyte>::value)
|
||||
else if constexpr (std::is_same_v<T, jbyte>)
|
||||
env->SetStaticByteField(clazz, id, value);
|
||||
else if constexpr(std::is_same<T, jchar>::value)
|
||||
else if constexpr (std::is_same_v<T, jchar>)
|
||||
env->SetStaticCharField(clazz, id, value);
|
||||
else if constexpr(std::is_same<T, jshort>::value)
|
||||
else if constexpr (std::is_same_v<T, jshort>)
|
||||
env->SetStaticShortField(clazz, id, value);
|
||||
else if constexpr(std::is_same<T, jint>::value)
|
||||
else if constexpr (std::is_same_v<T, jint>)
|
||||
env->SetStaticIntField(clazz, id, value);
|
||||
else if constexpr(std::is_same<T, jlong>::value)
|
||||
else if constexpr (std::is_same_v<T, jlong>)
|
||||
env->SetStaticLongField(clazz, id, value);
|
||||
else if constexpr(std::is_same<T, jfloat>::value)
|
||||
else if constexpr (std::is_same_v<T, jfloat>)
|
||||
env->SetStaticFloatField(clazz, id, value);
|
||||
else if constexpr(std::is_same<T, jdouble>::value)
|
||||
else if constexpr (std::is_same_v<T, jdouble>)
|
||||
env->SetStaticDoubleField(clazz, id, value);
|
||||
else if constexpr(std::is_convertible<T, jobject>::value)
|
||||
else if constexpr (std::is_convertible_v<T, jobject>)
|
||||
env->SetStaticObjectField(clazz, id, value);
|
||||
else
|
||||
QtJniTypes::staticAssertTypeMismatch();
|
||||
|
|
|
|||
|
|
@ -148,72 +148,72 @@ static void staticAssertTypeMismatch()
|
|||
template<typename T>
|
||||
constexpr auto typeSignature()
|
||||
{
|
||||
if constexpr(std::is_array_v<T>) {
|
||||
using UnderlyingType = typename std::remove_extent<T>::type;
|
||||
if constexpr (std::is_array_v<T>) {
|
||||
using UnderlyingType = typename std::remove_extent_t<T>;
|
||||
static_assert(!std::is_array_v<UnderlyingType>,
|
||||
"typeSignature() does not handle multi-dimensional arrays");
|
||||
return String("[") + typeSignature<UnderlyingType>();
|
||||
} else if constexpr(std::is_same_v<T, jobject>) {
|
||||
} else if constexpr (std::is_same_v<T, jobject>) {
|
||||
return String("Ljava/lang/Object;");
|
||||
} else if constexpr(std::is_same_v<T, jclass>) {
|
||||
} else if constexpr (std::is_same_v<T, jclass>) {
|
||||
return String("Ljava/lang/Class;");
|
||||
} else if constexpr(std::is_same_v<T, jstring>) {
|
||||
} else if constexpr (std::is_same_v<T, jstring>) {
|
||||
return String("Ljava/lang/String;");
|
||||
} else if constexpr(std::is_same_v<T, jobjectArray>) {
|
||||
} else if constexpr (std::is_same_v<T, jobjectArray>) {
|
||||
return String("[Ljava/lang/Object;");
|
||||
} else if constexpr(std::is_same_v<T, jthrowable>) {
|
||||
} else if constexpr (std::is_same_v<T, jthrowable>) {
|
||||
return String("Ljava/lang/Throwable;");
|
||||
} else if constexpr(std::is_same_v<T, jbooleanArray>) {
|
||||
} else if constexpr (std::is_same_v<T, jbooleanArray>) {
|
||||
return String("[Z");
|
||||
} else if constexpr(std::is_same_v<T, jbyteArray>) {
|
||||
} else if constexpr (std::is_same_v<T, jbyteArray>) {
|
||||
return String("[B");
|
||||
} else if constexpr(std::is_same_v<T, jshortArray>) {
|
||||
} else if constexpr (std::is_same_v<T, jshortArray>) {
|
||||
return String("[S");
|
||||
} else if constexpr(std::is_same_v<T, jintArray>) {
|
||||
} else if constexpr (std::is_same_v<T, jintArray>) {
|
||||
return String("[I");
|
||||
} else if constexpr(std::is_same_v<T, jlongArray>) {
|
||||
} else if constexpr (std::is_same_v<T, jlongArray>) {
|
||||
return String("[J");
|
||||
} else if constexpr(std::is_same_v<T, jfloatArray>) {
|
||||
} else if constexpr (std::is_same_v<T, jfloatArray>) {
|
||||
return String("[F");
|
||||
} else if constexpr(std::is_same_v<T, jdoubleArray>) {
|
||||
} else if constexpr (std::is_same_v<T, jdoubleArray>) {
|
||||
return String("[D");
|
||||
} else if constexpr(std::is_same_v<T, jcharArray>) {
|
||||
} else if constexpr (std::is_same_v<T, jcharArray>) {
|
||||
return String("[C");
|
||||
} else if constexpr(std::is_same_v<T, jboolean>) {
|
||||
} else if constexpr (std::is_same_v<T, jboolean>) {
|
||||
return String("Z");
|
||||
} else if constexpr(std::is_same_v<T, bool>) {
|
||||
} else if constexpr (std::is_same_v<T, bool>) {
|
||||
return String("Z");
|
||||
} else if constexpr(std::is_same_v<T, jbyte>) {
|
||||
} else if constexpr (std::is_same_v<T, jbyte>) {
|
||||
return String("B");
|
||||
} else if constexpr(std::is_same_v<T, jchar>) {
|
||||
} else if constexpr (std::is_same_v<T, jchar>) {
|
||||
return String("C");
|
||||
} else if constexpr(std::is_same_v<T, char>) {
|
||||
} else if constexpr (std::is_same_v<T, char>) {
|
||||
return String("C");
|
||||
} else if constexpr(std::is_same_v<T, jshort>) {
|
||||
} else if constexpr (std::is_same_v<T, jshort>) {
|
||||
return String("S");
|
||||
} else if constexpr(std::is_same_v<T, short>) {
|
||||
} else if constexpr (std::is_same_v<T, short>) {
|
||||
return String("S");
|
||||
} else if constexpr(std::is_same_v<T, jint>) {
|
||||
} else if constexpr (std::is_same_v<T, jint>) {
|
||||
return String("I");
|
||||
} else if constexpr(std::is_same_v<T, int>) {
|
||||
} else if constexpr (std::is_same_v<T, int>) {
|
||||
return String("I");
|
||||
} else if constexpr(std::is_same_v<T, uint>) {
|
||||
} else if constexpr (std::is_same_v<T, uint>) {
|
||||
return String("I");
|
||||
} else if constexpr(std::is_same_v<T, jlong>) {
|
||||
} else if constexpr (std::is_same_v<T, jlong>) {
|
||||
return String("J");
|
||||
} else if constexpr(std::is_same_v<T, long>) {
|
||||
} else if constexpr (std::is_same_v<T, long>) {
|
||||
return String("J");
|
||||
} else if constexpr(std::is_same_v<T, jfloat>) {
|
||||
} else if constexpr (std::is_same_v<T, jfloat>) {
|
||||
return String("F");
|
||||
} else if constexpr(std::is_same_v<T, float>) {
|
||||
} else if constexpr (std::is_same_v<T, float>) {
|
||||
return String("F");
|
||||
} else if constexpr(std::is_same_v<T, jdouble>) {
|
||||
} else if constexpr (std::is_same_v<T, jdouble>) {
|
||||
return String("D");
|
||||
} else if constexpr(std::is_same_v<T, double>) {
|
||||
} else if constexpr (std::is_same_v<T, double>) {
|
||||
return String("D");
|
||||
} else if constexpr(std::is_same_v<T, void>) {
|
||||
} else if constexpr (std::is_same_v<T, void>) {
|
||||
return String("V");
|
||||
} else if constexpr(IsStringType<T>::value) {
|
||||
} else if constexpr (IsStringType<T>::value) {
|
||||
static_assert(!IsStringType<T>::value, "Don't use a literal type, call data!");
|
||||
} else {
|
||||
staticAssertTypeMismatch();
|
||||
|
|
@ -229,7 +229,7 @@ static void staticAssertClassNotRegistered()
|
|||
template<typename T>
|
||||
constexpr auto className()
|
||||
{
|
||||
if constexpr(std::is_same<T, jstring>::value)
|
||||
if constexpr (std::is_same_v<T, jstring>)
|
||||
return String("java/lang/String");
|
||||
else
|
||||
staticAssertClassNotRegistered();
|
||||
|
|
@ -244,7 +244,7 @@ static constexpr bool isPrimitiveType()
|
|||
template<typename T>
|
||||
static constexpr bool isObjectType()
|
||||
{
|
||||
if constexpr(std::is_convertible<T, jobject>::value) {
|
||||
if constexpr (std::is_convertible_v<T, jobject>) {
|
||||
return true;
|
||||
} else {
|
||||
constexpr auto signature = typeSignature<T>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue