boost-python: How do I provide a custom constructor wrapper function?
I'm using boost-python to create python bindings for a C++ class named
CppClass. When necessary, I can route calls to "normal" member functions
through little wrapper functions that preprocess the arguments (e.g.
extract C++ types from the python args), like so:
class CppClass
{
CppClass(SpecialParameters p);
void doSomething(int x, float y);
};
using namespace boost::python; // For extract, tuple, init, class_, etc.
class WrapperFuncs
{
static void doSomething(CppClass & c, tuple t)
{
int x = extract<int>(t.attr("__getitem__")(0));
float y = extract<float>(t.attr("__getitem__")(1));
c.doSomething(x,y);
}
};
class_<CppClass, boost::shared_ptr<CppClass> >
("CppClass", init<SpecialParameters>())
.def("doSomething", &WrapperFuncs::doSomething, (arg("t")))
But how do I do the same for the CppClass constructor?
No comments:
Post a Comment