誰かがこれを将来的に探している場合には、私はstd_string.iをC#のように作成しました。私のために働くと思われる。私の場合はもっと適切だったのでrefを変更しましたが、refもうまくいくはずです。
私は%と呼ばれるが、私はconstのSTDのためargout定義する必要がある理由
/* -----------------------------------------------------------------------------
* std_string_ref.i
*
* Typemaps for std::string& and const std::string&
* These are mapped to a C# String and are passed around by reference
*
* ----------------------------------------------------------------------------- */
%{
#include <string>
%}
namespace std {
%naturalvar string;
class string;
// string &
%typemap(ctype) std::string & "char**"
%typemap(imtype) std::string & "/*imtype*/ out string"
%typemap(cstype) std::string & "/*cstype*/ out string"
//C++
%typemap(in, canthrow=1) std::string &
%{ //typemap in
std::string temp;
$1 = &temp;
%}
//C++
%typemap(argout) std::string &
%{
//Typemap argout in c++ file.
//This will convert c++ string to c# string
*$input = SWIG_csharp_string_callback($1->c_str());
%}
%typemap(argout) const std::string &
%{
//argout typemap for const std::string&
%}
%typemap(csin) std::string & "out $csinput"
%typemap(throws, canthrow=1) string &
%{ SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.c_str());
return $null; %}
}
.iファイルから「std_string.i」が含ま:: SWIGは混乱とconstのSTDを上書きするための文字列&は以下のとおりです。 :文字列&もtypemapで指定します。
%typemap(argout)std::string&
{
//typemap argout std::string&
PyObject* obj = PyUnicode_FromStringAndSize((*$1).c_str(),(*$1).length());
$result=SWIG_Python_AppendOutput($result, obj);
}
%typemap(argout) const std::string &
%{
//argout typemap for const std::string&
%}
:だから私は、明示的に、私はこのようなものを作成したPython用
(あなたは異なるユースケースを持っている場合があります)私の場合には上書きしないようにそれを伝えます