-
Notifications
You must be signed in to change notification settings - Fork 6
/
JNIArrays.swift.gyb
106 lines (84 loc) · 3.64 KB
/
JNIArrays.swift.gyb
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import CJNI
%{
jTypes = [
# You can only set / get one jobject array element at a time
# So we handle that case manually, and automate the rest...
# ('Object', 'jobject'),
('Boolean', 'jboolean'),
('Byte', 'jbyte'),
('Char', 'jchar'),
('Short', 'jshort'),
('Int', 'jint'),
('Long', 'jlong'),
('Float', 'jfloat'),
('Double', 'jdouble')
]
}%
public extension JNI {
public func GetArrayLength(array: jarray) -> jsize {
let env = self._env
return env.memory.memory.GetArrayLength(env, array)
}
% # You can only set / get one object element at a time
public func NewObjectArray(length: jsize, _ elementClass: jclass, _ initialElement: jobject) -> jobjectArray {
let env = self._env
return env.memory.memory.NewObjectArray(env, length, elementClass, initialElement)
}
public func GetObjectArrayElement(array: jobjectArray, _ index: jsize) -> jobject {
let env = self._env
return env.memory.memory.GetObjectArrayElement(env, array, index)
}
public func SetObjectArrayElement(array: jobjectArray, _ index: jsize, _ value: jobject) {
let env = self._env
env.memory.memory.SetObjectArrayElement(env, array, index, value)
}
% # But we can automate the rest
% for (TypeName, type) in jTypes:
public func New${TypeName}Array(length: jsize) -> ${type}Array {
let env = self._env
return env.memory.memory.New${TypeName}Array(env, length)
}
public func Get${TypeName}ArrayElements(array: ${type}Array, _ isCopy: UnsafeMutablePointer<jboolean>) -> UnsafeMutablePointer<${type}> {
let env = self._env
return env.memory.memory.Get${TypeName}ArrayElements(env, array, isCopy)
}
public func Release${TypeName}ArrayElements(array: ${type}Array, _ elems: UnsafeMutablePointer<${type}>, _ mode: jint) {
let env = self._env
env.memory.memory.Release${TypeName}ArrayElements(env, array, elems, mode)
}
public func Get${TypeName}ArrayRegion(array: ${type}Array, _ start: jsize, _ len: jsize, _ buf: UnsafeMutablePointer<${type}>) {
let env = self._env
env.memory.memory.Get${TypeName}ArrayRegion(env, array, start, len, buf)
}
public func Set${TypeName}ArrayRegion(array: ${type}Array, _ start: jsize, _ len: jsize, _ buf: UnsafePointer<${type}>) {
let env = self._env
env.memory.memory.Set${TypeName}ArrayRegion(env, array, start, len, buf)
}
% end
}
/// High performance JNI extensions
public extension JNI {
public func GetPrimitiveArrayCritical(array: jarray, _ isCopy: UnsafeMutablePointer<jboolean>) -> UnsafeMutablePointer<Void> {
let env = self._env
return env.memory.memory.GetPrimitiveArrayCritical(env, array, isCopy)
}
public func ReleasePrimitiveArrayCritical(array: jarray, _ carray: UnsafeMutablePointer<Void>, _ mode: jint) {
let env = self._env
env.memory.memory.ReleasePrimitiveArrayCritical(env, array, carray, mode)
}
public func NewDirectByteBuffer(address: UnsafeMutablePointer<Void>, _ capacity: jlong) -> jobject {
let env = self._env
return env.memory.memory.NewDirectByteBuffer(env, address, capacity)
}
public func GetDirectBufferAddress(buf: jobject) -> UnsafeMutablePointer<Void> {
let env = self._env
return env.memory.memory.GetDirectBufferAddress(env, buf)
}
public func GetDirectBufferCapacity(buf: jobject) -> jlong {
let env = self._env
return env.memory.memory.GetDirectBufferCapacity(env, buf)
}
}
// ${'Local Variables'}:
// eval: (read-only-mode 1)
// End: