Boost.Python: how to output a factory method in python
I have a C ++ API that is built into a dll, now I want an api using python, so I decided to rebuild the dll with boost.python, but I'm new to boost.python.
The API is in the CMyApi.h file , it has a factory way like:
class __declspec(dllexport) CMyApi
{
public:
static CMyApi* CreateUserApi(const char *path = "");
virtual void Init() = 0;
protected:
~CMyApi(){};
};
CMyApi is a virtual class and CApiImpl inherits from CMyApi, it is defined in CApiImpl.h :
class CApiImpl : public CMyApi
{
public:
CApiImpi();
~CApiImpi();
virtual void Init();
};
CApiImpl.cpp contains the CApiImpl implementation and the CMyApi :: CreateUserApi implementation:
static CMyApi* CMyApi::CreateUserApi(const char *path)
{
return new CApiImpl();
}
I don't want to expose CApiImpl for the api user, I would like the API to be called by CMyApi, so the user has CMyApi.h and a DLL file.
CMyApi wraps like this:
class CMyApiWrapper : public CMyApi, public wrapper<CMApi>
{
void Init()
{
this->get_override("Init")();
}
};
BOOST_PYTHON_MODULE(CMyApiWrapper)
{
class_<CMyApiWrapper>("CMyApiWrapper")
.def("CreateUserApi", &CMyApi::CreateUserApi)
.staticmethod("CreateUserApi")
.def("Init", pure_virtual(&CMyApi::Init));
}
The above BOOST_PYTHON_MODULE cannot pass the assembly, what's wrong in my program?
+3
source to share
No one has answered this question yet
Check out similar questions: