Loading...
Searching...
No Matches
tagging.hpp
Go to the documentation of this file.
#pragma once
#include <jni/traits.hpp>
#include <jni/unique.hpp>
#include <type_traits>
namespace jni
{
class ObjectBase;
template < class Tag > class Object;
template < class E, class = void > class Array;
template < class > struct TypeSignature;
struct ObjectTag
{
static constexpr auto Name() { return "java/lang/Object"; }
};
struct StringTag
{
static constexpr auto Name() { return "java/lang/String"; }
};
struct ClassTag
{
static constexpr auto Name() { return "java/lang/Class"; }
};
template < class T >
struct ArrayTag
{
static constexpr auto Name() { return TypeSignature<Array<T>>()(); }
};
template < class Tag, class = int >
struct SuperTag
{
using Type = ObjectTag;
};
template < class Tag >
struct SuperTag< Tag, decltype(std::declval<typename Tag::SuperTag>(), 0) >
{
using Type = typename Tag::SuperTag;
};
template < class Tag, class Enable = void >
struct TagTraits
{
using SuperType = Object<typename SuperTag<Tag>::Type>;
using UntaggedType = jobject;
};
template <>
struct TagTraits< ObjectTag >
{
using SuperType = ObjectBase;
using UntaggedType = jobject;
};
template <>
struct TagTraits< StringTag >
{
using SuperType = Object<ObjectTag>;
using UntaggedType = jstring;
};
template <>
struct TagTraits< ClassTag >
{
using SuperType = Object<ObjectTag>;
using UntaggedType = jclass;
};
template < class E >
struct TagTraits< ArrayTag<E>, std::enable_if_t<IsPrimitive<E>::value> >
{
using SuperType = Object<ObjectTag>;
using UntaggedType = jarray<E>;
};
template < class Tag >
struct TagTraits< ArrayTag<Object<Tag>> >
{
using SuperType = Object<ObjectTag>;
using UntaggedType = jarray<jobject>;
};
template < class T >
auto Tag(JNIEnv&, T primitive)
-> std::enable_if_t< IsPrimitive<T>::value, T >
{
return primitive;
}
template < class T, class U >
auto Tag(JNIEnv& env, U* u)
-> std::enable_if_t< !IsPrimitive<T>::value, Input<T> >
{
return Input<T>(env, u);
}
template < class T, class U >
auto Tag(JNIEnv& env, U& u)
-> std::enable_if_t< !IsPrimitive<T>::value, Input<T> >
{
return Input<T>(env, &u);
}
template < class T >
auto Untag(T primitive)
-> std::enable_if_t< IsPrimitive<T>::value, T >
{
return primitive;
}
template < class T >
auto Untag(const T& t)
-> std::enable_if_t< !IsPrimitive<T>::value, decltype(t.get()) >
{
return t.get();
}
template < class T >
using UntaggedType = decltype(Untag(std::declval<T>()));
}
jni::Array
Definition array.hpp:11
jni::ObjectBase
Definition object.hpp:15
jni::Object
Definition object.hpp:45
jni
Definition advanced_ownership.hpp:6
jni::UntaggedType
decltype(Untag(std::declval< T >())) UntaggedType
Definition tagging.hpp:130
jni::Tag
auto Tag(JNIEnv &, T primitive) -> std::enable_if_t< IsPrimitive< T >::value, T >
Definition tagging.hpp:94
jni::Input
Unique< T, NullDeleter > Input
Definition unique.hpp:123
jni::Untag
auto Untag(T primitive) -> std::enable_if_t< IsPrimitive< T >::value, T >
Definition tagging.hpp:116
std
Definition errors.hpp:10
jni::ArrayTag
Definition tagging.hpp:33
jni::ArrayTag::Name
static constexpr auto Name()
Definition tagging.hpp:34
jni::ClassTag
Definition tagging.hpp:27
jni::ClassTag::Name
static constexpr auto Name()
Definition tagging.hpp:28
jni::ObjectTag
Definition tagging.hpp:17
jni::ObjectTag::Name
static constexpr auto Name()
Definition tagging.hpp:18
jni::StringTag
Definition tagging.hpp:22
jni::StringTag::Name
static constexpr auto Name()
Definition tagging.hpp:23
jni::SuperTag< Tag, decltype(std::declval< typename Tag::SuperTag >(), 0) >::Type
typename Tag::SuperTag Type
Definition tagging.hpp:47
jni::SuperTag
Definition tagging.hpp:40
jni::SuperTag::Type
ObjectTag Type
Definition tagging.hpp:41
jni::TagTraits< ArrayTag< E >, std::enable_if_t< IsPrimitive< E >::value > >::UntaggedType
jarray< E > UntaggedType
Definition tagging.hpp:82
jni::TagTraits< ArrayTag< E >, std::enable_if_t< IsPrimitive< E >::value > >::SuperType
Object< ObjectTag > SuperType
Definition tagging.hpp:81
jni::TagTraits< ArrayTag< Object< Tag > > >::UntaggedType
jarray< jobject > UntaggedType
Definition tagging.hpp:89
jni::TagTraits< ArrayTag< Object< Tag > > >::SuperType
Object< ObjectTag > SuperType
Definition tagging.hpp:88
jni::TagTraits< ClassTag >::UntaggedType
jclass UntaggedType
Definition tagging.hpp:75
jni::TagTraits< ClassTag >::SuperType
Object< ObjectTag > SuperType
Definition tagging.hpp:74
jni::TagTraits< ObjectTag >::UntaggedType
jobject UntaggedType
Definition tagging.hpp:61
jni::TagTraits< ObjectTag >::SuperType
ObjectBase SuperType
Definition tagging.hpp:60
jni::TagTraits< StringTag >::SuperType
Object< ObjectTag > SuperType
Definition tagging.hpp:67
jni::TagTraits< StringTag >::UntaggedType
jstring UntaggedType
Definition tagging.hpp:68
jni::TagTraits
Definition tagging.hpp:52
jni::TagTraits::UntaggedType
jobject UntaggedType
Definition tagging.hpp:54
jni::TagTraits::SuperType
Object< typename SuperTag< Tag >::Type > SuperType
Definition tagging.hpp:53
jni::TypeSignature
Definition tagging.hpp:13
jni::jarray
Definition types.hpp:43
jni::jclass
Definition types.hpp:38
jni::jobject
Definition types.hpp:31
jni::jstring
Definition types.hpp:39
traits.hpp
unique.hpp