i'm trying translate c++ class interface to other languages using swig. my c++ interface is like this:
this is file mitprotocol.h
class MitProtocolCallBack
{
public:
virtual const string & TestFunc(deque<int> & param) = 0;
};
class MitProtocolInterface
{
public:
virtual void ReleaseMe() = 0;
virtual void SetCallBack(MitProtocolCallBack * mitProtocolCallBack) = 0;
virtual void UnTar(const string & filePathAndName) = 0;
};
MitProtocolInterface * CreateMitProtocolInterface();
in c++ , i can use this interface like this:
this is file test.cpp:
class testclass : public MitProtocolCallBack
{
public:
void playhaha()
{
mitProtocolInterface->UnTar("");
}
private:
string str_res;
public:
virtual const string & TestFunc(deque<int> & param)
{
str_res = "abc";
return str_res;
}
private:
MitProtocolInterface * mitProtocolInterface;
public:
testclass()
{
mitProtocolInterface = CreateMitProtocolInterface();
mitProtocolInterface->SetCallBack(this);
}
~testclass()
{
mitProtocolInterface->ReleaseMe();
}
};
void main()
{
testclass haha;
haha.playhaha();
}
then i tried wrap the c++ interface using swig:
this is file mitprotocol.i:
%module mitprotocol
%include "std_string.i"
%include "std_deque.i"
%{
#include "mitprotocol.h"
%}
namespace std {
%template(IntDeque) deque<int>;
}
%include "mitprotocol.h"
then i executed:
swig -c++ -python mitprotocol.i
then i got 2 files:
file mitprotocol.py: for python interface
file mitprotocol_wrap.cxx: to compile with other c++ source codes as a lib
then i tried to use the python interface:
this is file test.py:
import mitprotocol
class myclass(mitprotocol.MitProtocolCallBack):
def __init__(self):
self.mitProtocolInterface = mitprotocol.CreateMitProtocolInterface()
self.mitProtocolInterface.SetCallBack(self)
def __delete__(self):
self.mitProtocolInterface.ReleaseMe()
def TestFunc(self, param):
print param
return "aedfas"
def playhaha(self):
self.mitProtocolInterface.UnTar("")
ffsa = myclass()
ffsa.playhaha()
and finally i got an erro in line:
self.mitProtocolInterface.SetCallBack(self)
the error is:
TypeError: in method 'MitProtocolInterface_SetCallBack',
argument 2 of type 'MitProtocolCallBack *'
i think it's crashed when trying pass python class instance to swig wrapped c++ interface. anyone with any help ?