-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunwrappers.h
73 lines (57 loc) · 1.26 KB
/
unwrappers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include "arrays.h"
#include "jni_types.h"
#include "object_test.h"
namespace jnipp::java {
template<typename T>
struct type_unwrapper
{
type_unwrapper(java::value value)
: value(value)
{
}
operator T() const
{
return T();
}
java::value value;
};
template<>
struct type_unwrapper<std::string>
{
type_unwrapper(java::object value)
: value(value)
{
}
operator std::string() const
{
objects::verify_instance_of(value, "java/lang/String");
jstring str_obj =
reinterpret_cast<jstring>(static_cast<::jobject>(value));
auto chars = GetJNI()->GetStringUTFChars(str_obj, nullptr);
std::string out;
if(chars)
out = chars;
GetJNI()->ReleaseStringUTFChars(str_obj, chars);
return out;
}
java::object value;
};
template<return_type T>
struct array_type_unwrapper
{
array_type_unwrapper(java::object obj)
: arrayRef(*obj.array())
{
}
array_type_unwrapper(java::array arr)
: arrayRef(arr)
{
}
array_extractors::container<T> operator*()
{
return array_extractors::container<T>(arrayRef);
}
java::array arrayRef;
};
} // namespace jnipp::java