指向不透明结构的指针的Swig接口定义

时间:2014-04-29 16:59:57

标签: c++ c binding wrapper swig

我目前正在尝试使用SWIG为ReconstructMe SDK(http://reconstructme.net/)生成语言绑定。我正在尝试为Python,Java和CSharp生成低级绑定。我试图包装的API是一个简单的C-API,SWIG可以很好地自动包装它的大部分内容,除了一个关键部分。

ReconstructMe SDK将指向不透明上下文对象的指针声明为

typedef struct _reme_context* reme_context_t;

并提供两个函数,可以创建一个新的或销毁的和现有的

// Output a new context
reme_error_t reme_context_create(reme_context_t *c);

// Destroy existing context and set pointer to null
reme_error_t reme_context_destroy(reme_context_t *c);

ReMe的所有其他功能都将reme_context_t对象作为输入。例如

reme_error_t reme_context_compile(reme_context_t c);

默认情况下,SWIG会创建两种不可兑换的类型:一种用于reme_context_t,另一种用于reme_context_t*

我想要实现的是告诉SWIG将reme_context_t重新解释为指向void的指针或类似的东西,它可以在所有语言中处理并在必要时强制转换为reme_context_t。 p>

例如在CSharp中,重新解释上述内容的一种自然方式是使用System.IntPtr,以便上面转为

reme_error_t reme_context_create(out System.IntPtr c);
reme_error_t reme_context_destroy(ref System.IntPtr c);
reme_error_t reme_context_compile(System.IntPtr c);

有没有一种简单的方法可以做到这一点,并以一种通用的方式进行,SWIG代码可以处理多种语言?

提前致谢, 克里斯托弗

0 个答案:

没有答案
相关问题