Loading...
Searching...
No Matches
class.hpp
Go to the documentation of this file.
#pragma once
#include <jni/functions.hpp>
#include <jni/tagging.hpp>
#include <jni/advanced_ownership.hpp>
#include <jni/object.hpp>
namespace jni
{
template < class TheTag, class... > class Constructor;
template < class TheTag, class > class Field;
template < class TheTag, class > class StaticField;
template < class TheTag, class > class Method;
template < class TheTag, class > class StaticMethod;
template < class TheTag >
class Class : public Object<ClassTag>
{
public:
using TagType = TheTag;
using SuperType = Object<ClassTag>;
using UntaggedType = jclass;
protected:
explicit Class(std::nullptr_t = nullptr)
{}
explicit Class(UntaggedType* p)
: SuperType(p)
{}
Class(const Class&) = delete;
Class& operator=(const Class&) = delete;
public:
template < class... ExpectedArgs, class... ActualArgs >
auto New(JNIEnv& env, const Constructor<TagType, ExpectedArgs...>& method, const ActualArgs&... args) const
-> std::enable_if_t< Conjunction<std::is_convertible<const ActualArgs&, const ExpectedArgs&>...>::value, Local<Object<TagType>> >
{
return Local<Object<TagType>>(env, &NewObject(env, *this->get(), method, Untag(args)...));
}
template < class T >
auto Get(JNIEnv& env, const StaticField<TagType, T>& field) const
-> std::enable_if_t< IsPrimitive<T>::value, T >
{
return jni::GetStaticField<T>(env, *this->get(), field);
}
template < class T >
auto Get(JNIEnv& env, const StaticField<TagType, T>& field) const
-> std::enable_if_t< !IsPrimitive<T>::value, Local<T> >
{
return Local<T>(env, reinterpret_cast<typename T::UntaggedType*>(jni::GetStaticField<jobject*>(env, *this->get(), field)));
}
template < class T >
auto Set(JNIEnv& env, const StaticField<TagType, T>& field, T value) const
-> std::enable_if_t< IsPrimitive<T>::value >
{
SetStaticField<T>(env, *this->get(), field, value);
}
template < class Expected, class Actual >
auto Set(JNIEnv& env, const StaticField<TagType, Expected>& field, const Actual& value) const
-> std::enable_if_t< !IsPrimitive<Expected>::value
&& std::is_convertible<const Actual&, const Expected&>::value >
{
SetStaticField<jobject*>(env, *this->get(), field, value.get());
}
template < class R, class... ExpectedArgs, class... ActualArgs >
auto Call(JNIEnv& env, const StaticMethod<TagType, R (ExpectedArgs...)>& method, const ActualArgs&... args) const
-> std::enable_if_t< IsPrimitive<R>::value
&& Conjunction<std::is_convertible<const ActualArgs&, const ExpectedArgs&>...>::value, R >
{
return CallStaticMethod<R>(env, *this->get(), method, Untag(args)...);
}
template < class R, class... ExpectedArgs, class... ActualArgs >
auto Call(JNIEnv& env, const StaticMethod<TagType, R (ExpectedArgs...)>& method, const ActualArgs&... args) const
-> std::enable_if_t< !IsPrimitive<R>::value
&& !std::is_void<R>::value
&& Conjunction<std::is_convertible<const ActualArgs&, const ExpectedArgs&>...>::value, Local<R> >
{
return Local<R>(env, reinterpret_cast<typename R::UntaggedType*>(CallStaticMethod<jobject*>(env, *this->get(), method, Untag(args)...)));
}
template < class... ExpectedArgs, class... ActualArgs >
auto Call(JNIEnv& env, const StaticMethod<TagType, void (ExpectedArgs...)>& method, const ActualArgs&... args) const
-> std::enable_if_t< Conjunction<std::is_convertible<const ActualArgs&, const ExpectedArgs&>...>::value >
{
CallStaticMethod<void>(env, *this->get(), method, Untag(args)...);
}
static Local<Class> Find(JNIEnv& env)
{
return Local<Class>(env, &FindClass(env, TagType::Name()));
}
static const Class& Singleton(JNIEnv& env)
{
static Global<Class, EnvIgnoringDeleter> singleton = NewGlobal<EnvIgnoringDeleter>(env, Find(env));
return singleton;
}
template < class... Args >
Constructor<TagType, Args...> GetConstructor(JNIEnv& env) const
{
return Constructor<TagType, Args...>(env, *this);
}
template < class T >
Field<TagType, T> GetField(JNIEnv& env, const char* name) const
{
return Field<TagType, T>(env, *this, name);
}
template < class T >
StaticField<TagType, T> GetStaticField(JNIEnv& env, const char* name) const
{
return StaticField<TagType, T>(env, *this, name);
}
template < class T >
Method<TagType, T> GetMethod(JNIEnv& env, const char* name) const
{
return Method<TagType, T>(env, *this, name);
}
template < class T >
StaticMethod<TagType, T> GetStaticMethod(JNIEnv& env, const char* name) const
{
return StaticMethod<TagType, T>(env, *this, name);
}
};
}
advanced_ownership.hpp
jni::Class::Set
auto Set(JNIEnv &env, const StaticField< TagType, T > &field, T value) const -> std::enable_if_t< IsPrimitive< T >::value >
Definition class.hpp:58
jni::Class::GetStaticField
StaticField< TagType, T > GetStaticField(JNIEnv &env, const char *name) const
Definition class.hpp:120
jni::Class::Class
Class(UntaggedType *p)
Definition class.hpp:28
jni::Class::Get
auto Get(JNIEnv &env, const StaticField< TagType, T > &field) const -> std::enable_if_t< !IsPrimitive< T >::value, Local< T > >
Definition class.hpp:51
jni::Class::GetMethod
Method< TagType, T > GetMethod(JNIEnv &env, const char *name) const
Definition class.hpp:126
jni::Class::Class
Class(const Class &)=delete
jni::Class::Call
auto Call(JNIEnv &env, const StaticMethod< TagType, void(ExpectedArgs...)> &method, const ActualArgs &... args) const -> std::enable_if_t< Conjunction< std::is_convertible< const ActualArgs &, const ExpectedArgs & >... >::value >
Definition class.hpp:90
jni::Class::Find
static Local< Class > Find(JNIEnv &env)
Definition class.hpp:96
jni::Class::Call
auto Call(JNIEnv &env, const StaticMethod< TagType, R(ExpectedArgs...)> &method, const ActualArgs &... args) const -> std::enable_if_t< IsPrimitive< R >::value &&Conjunction< std::is_convertible< const ActualArgs &, const ExpectedArgs & >... >::value, R >
Definition class.hpp:73
jni::Class::GetConstructor
Constructor< TagType, Args... > GetConstructor(JNIEnv &env) const
Definition class.hpp:108
jni::Class::Set
auto Set(JNIEnv &env, const StaticField< TagType, Expected > &field, const Actual &value) const -> std::enable_if_t< !IsPrimitive< Expected >::value &&std::is_convertible< const Actual &, const Expected & >::value >
Definition class.hpp:65
jni::Class::GetField
Field< TagType, T > GetField(JNIEnv &env, const char *name) const
Definition class.hpp:114
jni::Class::Get
auto Get(JNIEnv &env, const StaticField< TagType, T > &field) const -> std::enable_if_t< IsPrimitive< T >::value, T >
Definition class.hpp:44
jni::Class::Class
Class(std::nullptr_t=nullptr)
Definition class.hpp:25
jni::Class::UntaggedType
jclass UntaggedType
Definition class.hpp:22
jni::Class::GetStaticMethod
StaticMethod< TagType, T > GetStaticMethod(JNIEnv &env, const char *name) const
Definition class.hpp:132
jni::Class::operator=
Class & operator=(const Class &)=delete
jni::Class::TagType
TheTag TagType
Definition class.hpp:20
jni::Class::SuperType
Object< ClassTag > SuperType
Definition class.hpp:21
jni::Class::Singleton
static const Class & Singleton(JNIEnv &env)
Definition class.hpp:101
jni::Class::Call
auto Call(JNIEnv &env, const StaticMethod< TagType, R(ExpectedArgs...)> &method, const ActualArgs &... args) const -> std::enable_if_t< !IsPrimitive< R >::value &&!std::is_void< R >::value &&Conjunction< std::is_convertible< const ActualArgs &, const ExpectedArgs & >... >::value, Local< R > >
Definition class.hpp:81
jni::Class::New
auto New(JNIEnv &env, const Constructor< TagType, ExpectedArgs... > &method, const ActualArgs &... args) const -> std::enable_if_t< Conjunction< std::is_convertible< const ActualArgs &, const ExpectedArgs & >... >::value, Local< Object< TagType > > >
Definition class.hpp:37
jni::Constructor
Definition constructor.hpp:9
jni::Field
Definition field.hpp:13
jni::Method
Definition class.hpp:13
jni::Object< ClassTag >::get
UntaggedType * get() const
Definition object.hpp:63
jni::Object< ClassTag >::Object
Object(std::nullptr_t=nullptr)
Definition object.hpp:52
jni::StaticField
Definition static_field.hpp:13
jni::StaticMethod
Definition class.hpp:14
functions.hpp
jni
Definition advanced_ownership.hpp:6
jni::NewObject
jobject & NewObject(JNIEnv &env, jclass &clazz, jmethodID &method, Args &&... args)
Definition functions.hpp:241
jni::CallStaticMethod
std::enable_if_t<!std::is_void< R >::value, R > CallStaticMethod(JNIEnv &env, jclass &clazz, jmethodID &method, Args &&... args)
Definition functions.hpp:328
jni::FindClass
jclass & FindClass(JNIEnv &env, const char *name)
Definition functions.hpp:34
jni::Global
Unique< T, Deleter<&JNIEnv::DeleteGlobalRef > > Global
Definition unique.hpp:102
jni::SetStaticField
void SetStaticField(JNIEnv &env, jclass &clazz, jfieldID &field, T value)
Definition functions.hpp:357
jni::GetStaticField
T GetStaticField(JNIEnv &env, jclass &clazz, jfieldID &field)
Definition functions.hpp:350
jni::NewGlobal
auto NewGlobal(JNIEnv &env, const T &t)
Definition unique.hpp:156
jni::Local
Unique< T, DefaultRefDeleter<&JNIEnv::DeleteLocalRef > > Local
Definition unique.hpp:110
jni::Untag
auto Untag(T primitive) -> std::enable_if_t< IsPrimitive< T >::value, T >
Definition tagging.hpp:116
object.hpp
jni::Conjunction
Definition traits.hpp:28
jni::jclass
Definition types.hpp:38
tagging.hpp