JavaSWIG:如何为多参数类型映射重新排序输入参数 class Foo : virtual public FooBase { public: virtual void bar(void *pBuffer, int64_t address, int64_t length) = 0; };
我希望能够使用控制器在Java中实现这个类。生成的Java类应该是这样的JavaSWIG:如何为多参数类型映射重新排序输入参数 class Foo : virtual public FooBase { public: virtual void bar(void *pBuffer, int64_t address, int64_t length) = 0; };,java,c++,swig,Java,C++,Swig,我希望能够使用控制器在Java中实现这个类。生成的Java类应该是这样的 private class Foo extends FooBase { ... public void bar(long address, byte[] pBuffer) {...} } 我有一张这样的类型图 %typemap(in) (void *pBuffer, int64_t length) { $1 = (void*)(jenv)->GetByteArrayElements($input,
private class Foo extends FooBase {
...
public void bar(long address, byte[] pBuffer) {...}
}
我有一张这样的类型图
%typemap(in) (void *pBuffer, int64_t length) {
$1 = (void*)(jenv)->GetByteArrayElements($input, NULL);
$2 = (jenv)->GetArrayLength($input);
if(!$1)
{
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "Failed to convert byte array.");
}
}
%typemap(freearg) (void *pBuffer, int64_t length) {
(jenv)->SetByteArrayRegion($input, 0, (jsize) $2, (const jbyte*)$1);
(jenv)->ReleaseByteArrayElements($input, (jbyte*)$1, 0);
}
%typemap(jni) (void *pBuffer, int64_t length) "jbyteArray"
%typemap(jtype) (void *pBuffer, int64_t length) "byte[]"
%typemap(jstype) (void *pBuffer, int64_t length) "byte[]"
%typemap(javain) (void *pBuffer, int64_t length) "$javainput"
但它只能在Foo::bar
的输入具有顺序时应用
整数地址,void*pBuffer,整数长度
是否可以重新排列
Foo::bar
中的输入参数,以使多参数类型映射正常工作 最简单的解决方案是创建一个新类来扩展Foo,并使用从OverwritenYou调用的重新排序的参数来交付抽象方法。我认为,您应该能够将一个做同样事情的hack放在一起,但不使用多参数类型映射,并在int64_t length
arg上设置numinputs=0
,但它比普通的多参数类型映射机制更脆弱。如果没有其他人先有机会,我会在周末回答。