lime
Lime is a C++ library implementing Open Whisper System Signal protocol
type_signature.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <jni/functions.hpp>
4 #include <jni/object.hpp>
5 #include <jni/array.hpp>
6 
7 namespace jni
8  {
9  template < char... chars >
11  {
12  operator const char *() const
13  {
14  static const char result[] = { chars..., 0 };
15  return result;
16  }
17  };
18 
19  constexpr std::size_t StringLiteralLength(const char * str, std::size_t len = 0)
20  {
21  return str[0] ? StringLiteralLength(str + 1, len + 1) : len;
22  }
23 
24  template < class, class >
26 
27  template < class Tag, std::size_t... Is >
28  struct TagLiteralImpl< Tag, std::index_sequence<Is...> >
29  {
30  using Value = StringLiteral< Tag::Name()[Is]... >;
31  };
32 
33  template < class Tag >
35 
36  template < char... As, char... Bs >
37  constexpr auto Concat(const StringLiteral<As...>&,
38  const StringLiteral<Bs...>&)
39  {
40  return StringLiteral<As..., Bs...>();
41  }
42 
43  template < class A, class B, class... Rest >
44  constexpr auto Concat(const A& a,
45  const B& b,
46  const Rest&... rest)
47  {
48  return Concat(Concat(a, b), rest...);
49  }
50 
51  template < class > struct TypeSignature;
52 
53  template <> struct TypeSignature< jboolean > { constexpr auto operator()() const { return StringLiteral<'Z'>(); } };
54  template <> struct TypeSignature< jbyte > { constexpr auto operator()() const { return StringLiteral<'B'>(); } };
55  template <> struct TypeSignature< jchar > { constexpr auto operator()() const { return StringLiteral<'C'>(); } };
56  template <> struct TypeSignature< jshort > { constexpr auto operator()() const { return StringLiteral<'S'>(); } };
57  template <> struct TypeSignature< jint > { constexpr auto operator()() const { return StringLiteral<'I'>(); } };
58  template <> struct TypeSignature< jlong > { constexpr auto operator()() const { return StringLiteral<'J'>(); } };
59  template <> struct TypeSignature< jfloat > { constexpr auto operator()() const { return StringLiteral<'F'>(); } };
60  template <> struct TypeSignature< jdouble > { constexpr auto operator()() const { return StringLiteral<'D'>(); } };
61  template <> struct TypeSignature< void > { constexpr auto operator()() const { return StringLiteral<'V'>(); } };
62 
63  template < class TheTag >
64  struct TypeSignature< Object<TheTag> >
65  {
66  constexpr auto operator()() const
67  {
69  }
70  };
71 
72  template < class E >
73  struct TypeSignature< Array<E> >
74  {
75  constexpr auto operator()() const
76  {
77  return Concat(StringLiteral<'['>(), TypeSignature<E>()());
78  }
79  };
80 
81  template < class R, class... Args >
82  struct TypeSignature< R (Args...) >
83  {
84  constexpr auto operator()() const
85  {
86  return Concat(StringLiteral<'('>(), TypeSignature<Args>()()..., StringLiteral<')'>(), TypeSignature<R>()());
87  }
88  };
89  }
constexpr std::size_t StringLiteralLength(const char *str, std::size_t len=0)
Definition: type_signature.hpp:19
constexpr auto operator()() const
Definition: type_signature.hpp:56
typename TagLiteralImpl< Tag, std::make_index_sequence< StringLiteralLength(Tag::Name())> >::Value TagLiteral
Definition: type_signature.hpp:34
constexpr auto operator()() const
Definition: type_signature.hpp:55
constexpr auto operator()() const
Definition: type_signature.hpp:58
Definition: array.hpp:11
Definition: errors.hpp:9
constexpr auto operator()() const
Definition: type_signature.hpp:53
Definition: object.hpp:44
Definition: advanced_ownership.hpp:5
constexpr auto operator()() const
Definition: type_signature.hpp:60
Definition: type_signature.hpp:25
constexpr auto operator()() const
Definition: type_signature.hpp:84
constexpr auto operator()() const
Definition: type_signature.hpp:59
Definition: type_signature.hpp:10
constexpr auto operator()() const
Definition: type_signature.hpp:54
constexpr auto Concat(const StringLiteral< As... > &, const StringLiteral< Bs... > &)
Definition: type_signature.hpp:37
constexpr auto operator()() const
Definition: type_signature.hpp:75
constexpr auto operator()() const
Definition: type_signature.hpp:61
constexpr auto operator()() const
Definition: type_signature.hpp:66
constexpr auto operator()() const
Definition: type_signature.hpp:57
auto Tag(JNIEnv &, T primitive) -> std::enable_if_t< IsPrimitive< T >::value, T >
Definition: tagging.hpp:94
Definition: tagging.hpp:13