JNI: remove compatibility template functions

With all submodules ported, we can remove the old template functions
that prevented us from partial specialization for containers.

Change-Id: I78467b6b343b779270e6f49d7db4ac5deb1a0b95
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
bb10
Volker Hilsheimer 2023-09-17 12:46:39 +02:00
parent 281f499b20
commit 980b86d09f
2 changed files with 12 additions and 26 deletions

View File

@ -46,7 +46,7 @@ public:
template<typename Class, typename ...Args>
static inline QJniObject construct(Args &&...args)
{
return QJniObject(QtJniTypes::className<Class>().data(),
return QJniObject(QtJniTypes::Traits<Class>::className().data(),
QtJniTypes::constructorSignature<Args...>().data(),
std::forward<Args>(args)...);
}
@ -190,7 +190,7 @@ public:
static auto callStaticMethod(const char *methodName, Args &&...args)
{
QJniEnvironment env;
const jclass clazz = QJniObject::loadClass(QtJniTypes::className<Klass>().data(),
const jclass clazz = QJniObject::loadClass(QtJniTypes::Traits<Klass>::className().data(),
env.jniEnv());
const jmethodID id = clazz ? getMethodID(env.jniEnv(), clazz, methodName,
QtJniTypes::methodSignature<Ret, Args...>().data(), true)
@ -315,7 +315,7 @@ public:
>
static auto getStaticField(const char *fieldName)
{
return getStaticField<T>(QtJniTypes::className<Klass>(), fieldName);
return getStaticField<T>(QtJniTypes::Traits<Klass>::className(), fieldName);
}
template <typename T
@ -475,7 +475,7 @@ public:
>
static void setStaticField(const char *fieldName, T value)
{
setStaticField(QtJniTypes::className<Klass>(), fieldName, value);
setStaticField(QtJniTypes::Traits<Klass>::className(), fieldName, value);
}
static QJniObject fromString(const QString &string);

View File

@ -240,30 +240,16 @@ struct Traits {
}
};
// compatibility until submodules are ported
template <typename T>
constexpr auto typeSignature()
{
return Traits<T>::signature();
}
template <typename T>
constexpr auto className()
{
return Traits<T>::className();
}
// have to use the compatibility functions here until porting is complete
template<typename T>
static constexpr bool isPrimitiveType()
{
return typeSignature<T>().size() == 2;
return Traits<T>::signature().size() == 2;
}
template<typename T>
static constexpr bool isArrayType()
{
constexpr auto signature = typeSignature<T>();
constexpr auto signature = Traits<T>::signature();
return signature.startsWith('[') && signature.size() > 2;
}
@ -273,7 +259,7 @@ static constexpr bool isObjectType()
if constexpr (std::is_convertible_v<T, jobject>) {
return true;
} else {
constexpr auto signature = typeSignature<T>();
constexpr auto signature = Traits<T>::signature();
return (signature.startsWith('L') && signature.endsWith(';')) || isArrayType<T>();
}
}
@ -286,10 +272,10 @@ static constexpr void assertObjectType()
"an object type signature registered)!");
}
// A set of types is valid if typeSignature is implemented for all of them
// A set of types is valid if Traits::signature is implemented for all of them
template<typename ...Types>
constexpr bool ValidSignatureTypesDetail = !std::disjunction<std::is_same<
decltype(QtJniTypes::typeSignature<Types>()),
decltype(Traits<Types>::signature()),
void>...,
IsStringType<Types>...>::value;
template<typename ...Types>
@ -307,15 +293,15 @@ template<typename R, typename ...Args, ValidSignatureTypes<R, Args...> = true>
static constexpr auto methodSignature()
{
return (CTString("(") +
... + typeSignature<q20::remove_cvref_t<Args>>())
... + Traits<q20::remove_cvref_t<Args>>::signature())
+ CTString(")")
+ typeSignature<R>();
+ Traits<R>::signature();
}
template<typename T, ValidSignatureTypes<T> = true>
static constexpr auto fieldSignature()
{
return QtJniTypes::typeSignature<T>();
return QtJniTypes::Traits<T>::signature();
}
template<typename ...Args, ValidSignatureTypes<Args...> = true>