-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathJniJavaClassClassDef.h
106 lines (80 loc) · 2.89 KB
/
JniJavaClassClassDef.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
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
#pragma once
#ifndef JNI_JAVA_CLASS_CLASS_DEF_H
#define JNI_JAVA_CLASS_CLASS_DEF_H
#include <JniForwards.h>
#include <JniProxy.h>
#include <JniJavaObjectClassDef.h>
namespace JNI {
class JavaClass : public JavaObject {
template<typename R, typename ... Args>
struct MethodGetter;
template<typename R, typename ... Args>
struct StaticMethodGetter;
template<typename T>
struct FieldGetter;
template<typename T>
struct StaticFieldGetter;
public:
JavaClass();
JavaClass(JavaEnv env, jclass c);
JavaClass(JavaEnv env, const char * val);
JavaClass(JavaEnv env, const std::string& val);
JavaClass(const JavaClass& c);
JavaClass(JavaClass&& c);
static JavaClass New(JavaEnv env, const char * str);
static JavaClass New(JavaEnv env, const std::string& str);
JavaObject NewObject() const;
template<typename R, typename ... Args>
JavaObject NewObject(Args&& ... args) const {
return FromJavaProxy<JavaObject>(_env, _env.Val()->NewObject(Val(), GetConstructor<R(Args...)>().Val(), ToJavaProxy(_env, std::forward<Args>(args)).Val()...)).Val();
}
virtual ~JavaClass();
JavaClass& operator=(const JavaClass& cls);
JavaClass& operator=(JavaClass&& cls);
using JavaObject::operator==;
using JavaObject::operator!=;
bool operator==(const JavaClass& cls) const;
bool operator!=(const JavaClass& cls) const;
bool operator==(const std::string& str) const;
bool operator!=(const std::string& str) const;
friend bool operator==(const std::string& str, const JavaClass& self) {
return self == str;
}
friend bool operator!=(const std::string& str, const JavaClass& self) {
return self != str;
}
jclass Val() const;
JavaClass Superclass() const;
jboolean IsAssignableFrom(const JavaClass& cls) const;
template<typename T>
JavaMethod<T> GetMethod(const JavaObject& obj, const char * name) const {
return JavaMethod<T>(obj, MethodGetter<T>().Get(*this, name));
}
template<typename T>
JavaStaticMethod<T> GetStaticMethod(const char * name) const {
return JavaStaticMethod<T>(*this, StaticMethodGetter<T>().Get(*this, name));
}
JavaStaticMethod<void()> GetDefaultConstructor() const;
// почему-то, конструктор в JNI -- не статический метод класса О_о
// я сделал статическим
template<typename T>
JavaStaticMethod<T> GetConstructor() const {
return JavaStaticMethod<T>(*this, MethodGetter<T>().Get(*this, "<init>"));
}
template<typename T>
JavaField<T> GetField(const JavaObject& obj, const char * name) const {
return JavaField<T>(obj, FieldGetter<T>().Get(*this, name));
}
template<typename T>
JavaStaticField<T> GetStaticField(const char * name) const {
return JavaStaticField<T>(*this, StaticFieldGetter<T>().Get(*this, name));
}
template<typename T>
T GetStaticFieldValue(const char * name) const {
return GetStaticField<T>(name).Get();
}
private:
static jclass GetClass(JavaEnv env, const char * name);
};
}
#endif