lime
Lime is a C++ library implementing Open Whisper System Signal protocol
tagging.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <jni/traits.hpp>
4#include <jni/unique.hpp>
5
6#include <type_traits>
7
8namespace jni
9 {
10 class ObjectBase;
11 template < class Tag > class Object;
12 template < class E, class = void > class Array;
13 template < class > struct TypeSignature;
14
15
16 struct ObjectTag
17 {
18 static constexpr auto Name() { return "java/lang/Object"; }
19 };
20
21 struct StringTag
22 {
23 static constexpr auto Name() { return "java/lang/String"; }
24 };
25
26 struct ClassTag
27 {
28 static constexpr auto Name() { return "java/lang/Class"; }
29 };
30
31 template < class T >
32 struct ArrayTag
33 {
34 static constexpr auto Name() { return TypeSignature<Array<T>>()(); }
35 };
36
37
38 template < class Tag, class = int >
39 struct SuperTag
40 {
41 using Type = ObjectTag;
42 };
43
44 template < class Tag >
45 struct SuperTag< Tag, decltype(std::declval<typename Tag::SuperTag>(), 0) >
46 {
47 using Type = typename Tag::SuperTag;
48 };
49
50 template < class Tag, class Enable = void >
51 struct TagTraits
52 {
55 };
56
57 template <>
59 {
62 };
63
64 template <>
66 {
69 };
70
71 template <>
73 {
76 };
77
78 template < class E >
79 struct TagTraits< ArrayTag<E>, std::enable_if_t<IsPrimitive<E>::value> >
80 {
83 };
84
85 template < class Tag >
87 {
90 };
91
92
93 template < class T >
94 auto Tag(JNIEnv&, T primitive)
95 -> std::enable_if_t< IsPrimitive<T>::value, T >
96 {
97 return primitive;
98 }
99
100 template < class T, class U >
101 auto Tag(JNIEnv& env, U* u)
102 -> std::enable_if_t< !IsPrimitive<T>::value, Input<T> >
103 {
104 return Input<T>(env, u);
105 }
106
107 template < class T, class U >
108 auto Tag(JNIEnv& env, U& u)
109 -> std::enable_if_t< !IsPrimitive<T>::value, Input<T> >
110 {
111 return Input<T>(env, &u);
112 }
113
114
115 template < class T >
116 auto Untag(T primitive)
117 -> std::enable_if_t< IsPrimitive<T>::value, T >
118 {
119 return primitive;
120 }
121
122 template < class T >
123 auto Untag(const T& t)
124 -> std::enable_if_t< !IsPrimitive<T>::value, decltype(t.get()) >
125 {
126 return t.get();
127 }
128
129 template < class T >
130 using UntaggedType = decltype(Untag(std::declval<T>()));
131 }
Definition: object.hpp:15
Definition: object.hpp:45
Definition: unique.hpp:39
Definition: advanced_ownership.hpp:6
auto Tag(JNIEnv &, T primitive) -> std::enable_if_t< IsPrimitive< T >::value, T >
Definition: tagging.hpp:94
decltype(Untag(std::declval< T >())) UntaggedType
Definition: tagging.hpp:130
auto Untag(T primitive) -> std::enable_if_t< IsPrimitive< T >::value, T >
Definition: tagging.hpp:116
Definition: errors.hpp:10
Definition: tagging.hpp:33
static constexpr auto Name()
Definition: tagging.hpp:34
Definition: tagging.hpp:27
static constexpr auto Name()
Definition: tagging.hpp:28
Definition: tagging.hpp:17
static constexpr auto Name()
Definition: tagging.hpp:18
Definition: tagging.hpp:22
static constexpr auto Name()
Definition: tagging.hpp:23
Definition: tagging.hpp:40
Definition: tagging.hpp:52
Definition: tagging.hpp:13
Definition: types.hpp:38
Definition: types.hpp:31
Definition: types.hpp:39