C++/JNI - 如何访问在 JAVA (Android NDK) 中的 .h 中声明的枚举
C++ / JNI - How to access enum declared in .h in JAVA (Android NDK)
我在 C++ 中有头文件,其中声明了一些枚举。
// enum.h
enum event {
event_1,
event_2,
event_3,
event_4
}
C++ 文件和头文件在库 .so 中编译(使用 GNU)。
现在我想在我的 Java class 中这样做 :
// Test.java
public class Test {
private event currentEvent;
public test() {
if (currentEvent == event.event_1)
; // I will do my stuff
}
}
有人有建议吗?
谢谢
我怀疑是否有直接的方法。
对于 C 或 C++,您可以使用 SWIG。它自动为 C++ 类 和元素生成 Java 包装器。
21.3.5.5 Simple enums
This approach is similar to the type unsafe approach. Each enum item
is also wrapped as a static final integer. However, these integers are
not generated into a class named after the C/C++ enum. Instead, global
enums are generated into the constants interface. Also, enums defined
in a C++ class have their enum items generated directly into the Java
proxy class rather than an inner class within the Java proxy class. In
fact, this approach is effectively wrapping the enums as if they were
anonymous enums and the resulting code is as per anonymous enums. The
implementation is in the "enumsimple.swg" file.
Compatibility Note: SWIG-1.3.21 and earlier versions wrapped all enums
using this approach. The type unsafe approach is preferable to this
one and this simple approach is only included for backwards
compatibility with these earlier versions of SWIG.
我在 C++ 中有头文件,其中声明了一些枚举。
// enum.h
enum event {
event_1,
event_2,
event_3,
event_4
}
C++ 文件和头文件在库 .so 中编译(使用 GNU)。
现在我想在我的 Java class 中这样做 :
// Test.java
public class Test {
private event currentEvent;
public test() {
if (currentEvent == event.event_1)
; // I will do my stuff
}
}
有人有建议吗?
谢谢
我怀疑是否有直接的方法。
对于 C 或 C++,您可以使用 SWIG。它自动为 C++ 类 和元素生成 Java 包装器。
21.3.5.5 Simple enums
This approach is similar to the type unsafe approach. Each enum item is also wrapped as a static final integer. However, these integers are not generated into a class named after the C/C++ enum. Instead, global enums are generated into the constants interface. Also, enums defined in a C++ class have their enum items generated directly into the Java proxy class rather than an inner class within the Java proxy class. In fact, this approach is effectively wrapping the enums as if they were anonymous enums and the resulting code is as per anonymous enums. The implementation is in the "enumsimple.swg" file.
Compatibility Note: SWIG-1.3.21 and earlier versions wrapped all enums using this approach. The type unsafe approach is preferable to this one and this simple approach is only included for backwards compatibility with these earlier versions of SWIG.