私はSWIGのOUTPUTタイプマップをクラスタイプに適用しようとすることにこれまで問題がありましたが、これにはprevious questionと尋ねました。私が得たクラス型のOUTPUTタイプマップを作成するにはどうすればよいですか?
答えはそこに役立ちましたが、まだのような何かを行うにSWIGを頼むために私を必要とします。これは、次のメッセージで、SWIG 3.0.6に私のために動作していないよう
%apply exportedClassType& OUTPUT { exportedClassType& result };
を:the documentationを見てから
Warning 453: Can't apply (exportedClassType &OUTPUT). No typemaps are defined.
:
がprimarことに注意してくださいtypemaps.iファイルの目的は、基本データ型をサポートすることです。 typemaps.iはBarのOUTPUTルールを定義していないので、このような関数を書くことは意図した効果がないかもしれません。 void foo(Bar *OUTPUT);
これはサポートされていないようです。このような、より何かに
// interface.i
%apply exportedClassType& OUTPUT { exportedClassType& result };
int getClassType(exportedClassType& result);
// interface_wrap.cxx
SWIGINTERN PyObject *_wrap_getClassType(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
exportedClassType *arg1 = 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
int result;
if (!PyArg_ParseTuple(args,(char *)"O:getClassType",&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1, SWIGTYPE_p_exportedClassType, 0);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "getClassType" "', argument " "1"" of type '" "exportedClassType &""'");
}
if (!argp1) {
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "getClassType" "', argument " "1"" of type '" "exportedClassType &""'");
}
arg1 = reinterpret_cast< exportedClassType * >(argp1);
result = (int)getClassType(*arg1);
resultobj = SWIG_From_int(static_cast<int>(result));
return resultobj;
fail:
return NULL;
}
// wrapper.py
def getClassType(result):
return _wrapper.getClassType(result)
getClassType = _wrapper.getClassType
:だから私は私の質問は、私はクラスタイプのための生成されたラッパーコードはここから行くようにinterface.iファイルで定義する必要がありますタイプマップのどのような組み合わせで、あると思いますか?
// interface.i
%apply bool& OUTPUT { bool& result };
int getSimpleType(bool& result);
// interface_wrap.cxx
SWIGINTERN PyObject *_wrap_getSimpleType(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
bool *arg1 = 0 ;
bool temp1 ;
int res1 = SWIG_TMPOBJ ;
int result;
arg1 = &temp1;
if (!PyArg_ParseTuple(args,(char *)":getSimpleType")) SWIG_fail;
result = (int)getSimpleType(*arg1);
resultobj = SWIG_From_int(static_cast<int>(result));
if (SWIG_IsTmpObj(res1)) {
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_From_bool((*arg1)));
} else {
int new_flags = SWIG_IsNewObj(res1) ? (SWIG_POINTER_OWN | 0) : 0 ;
resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_NewPointerObj((void*)(arg1), SWIGTYPE_p_bool, new_flags));
}
return resultobj;
fail:
return NULL;
}
// wrapper.py
def getSimpleType():
return _wrapper.getSimpleType()
getSimpleType = _wrapper.getSimpleType
I /アウト/ argoutタイプマップになどSWIG_Python_AppendOutput
が私のexportedClassType
のために呼ばれているので、必要なものを得ることはありません。誰も私にいくつかのポインタを教えてもらえますか?いいえ。
使ってPythonの中からオブジェクトを作成することができます。私は通常、コンストラクタをラップし、SWIGに多態性を処理させますが、出力が参照されるファクトリを作成することができました。 –
[クラスの型にSWIG OUTPUTの型マップを適用する方法は?](http://stackoverflow.com/questions/32478649/how-to-apply-swig-output-typemaps-for-class-types-in) -python) –