Java/ c++ SWIG -调用函数与数组参数
Java/C++ SWIG - Calling function with array parameter
我的代码是这样的:
bool doSomething( unsigned int x, const myStruct1 typeOne[2], myStruct2 typeTwo[2] );
使用swig得到java代码:
public static boolean doSomething(long x, myStruct1 typeOne, myStruct2 type2){}
我想要的是:
public static boolean doSomething(long x, myStruct1[] typeOne, myStruct2[] type2){}
我得到的问题是,SWIG不能知道我的数组在Java中只有2个元素,因为Java声明是无大小的。
我试过使用回车。I在swig界面中。我使用了arrays_functions指令,但它没有改变方法签名。
我的下一个想法是在SWIG文件中编写一个内联函数,它为每个结构体接受两个参数,然后充当实际函数的代理。
有更好的主意吗?
您可以使用现有的"arrays_java. xml "。i" SWIG库文件。
文件中有一个宏叫做JAVA_ARRAYSOFCLASSES
,可以用作:
%module test
%include <arrays_java.i>
JAVA_ARRAYSOFCLASSES(myStruct1);
JAVA_ARRAYSOFCLASSES(myStruct2);
struct myStruct1 {};
struct myStruct2 {};
bool doSomething(unsigned int x, const myStruct1 typeOne[2], myStruct2 typeTwo[2]);
生成以下Java函数:
public static boolean doSomething(long x, myStruct1[] typeOne, myStruct2[] typeTwo)
这正是你想要的!(如果你好奇的话,可以看看它的底层——这都是typemaps的标准用法)。
相关文章:
- 第 i 个元素返回 i 的函数数组
- 使用嵌套函数数组是个好主意吗?
- 正确实现类函数数组
- 试图引用已删除函数数组的相等运算符
- 如何在静态函数中使用成员函数数组
- 无法创建函数数组
- 构造函数数组
- 使用开关或定义函数数组 - 更快
- 编写一个函数,该函数将覆盖主函数数组中的值
- 可以像'funs[1]();'一样调用的函数数组
- std::AVX内部函数数组
- 如果数组大小未知,如何将函数数组作为参数传递
- 从函数数组中获取值
- 使用元编程在编译时初始化函数数组
- 将C函数数组转换为C++函数指针数组
- 复制构造函数 [数组] C++
- 添加函数数组并随机选择其中一个
- 指针到私有成员函数数组
- 可以单独声明函数数组的元素
- (c++)将main中的随机值保存到函数数组中