使用痛饮与采取的std ::字符串作为参数的方法 [英] Using SWIG with methods that take std::string as a parameter

查看:108
本文介绍了使用痛饮与采取的std ::字符串作为参数的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用SWIG来包装我的C ++类。有些方法有一个常量标准::字符串&安培; 作为参数。 SWIG创建一个名为 SWIGTYPE_p_std__string 但是你不能只传递一个普通的字符串为这个调用在C#中的方法时类型。下面的例子就是自带的SWIG包修改,例如:

I used SWIG to wrap my c++ class. Some methods have a const std::string& as a parameter. SWIG creates a type called SWIGTYPE_p_std__string however you cannot just pass a normal string for this when invoking the method in c#. The below example is just a modified example that comes with the SWIG package.:

public void setName(SWIGTYPE_p_std__string name) 
{
    examplePINVOKE.Shape_setName(swigCPtr, SWIGTYPE_p_std__string.getCPtr(name));
    if (examplePINVOKE.SWIGPendingException.Pending) throw examplePINVOKE.SWIGPendingException.Retrieve();
}

在我的接口文件我只是有:

In my interface file I just have:

/* File : example.i */
%module example

%{
#include "example.h"
%}

/* Let's just grab the original header file here */
%include "example.h"

和正在被包裹在C ++的方法是:

And the method that is being wrapped in C++ is:

void Shape::setName(const std::string& name)
{
    mName = name;
}

是否有某种类型映射的我已经把在接口文件?如果是这样,我该怎么办?

Is there some sort of typemap I have to put in the interface file? If so, how do I do that?

推荐答案

我试图解决这个我自己,当我发现你的问题。

I was trying to solve this myself when I found your question.

您需要包括

%,包括std_string.i

%include "std_string.i"

在您的.i文件。请参见 http://www.swig.org/Doc1.3/Library.html#Library_stl_cpp_library 了解更多详情。

in your .i file. See http://www.swig.org/Doc1.3/Library.html#Library_stl_cpp_library for more details.

这篇关于使用痛饮与采取的std ::字符串作为参数的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆