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
{
public:
CppClass(SpecialParameters p);
void doSomething(int x, float y);
};
using namespace boost::python; // For extract, tuple, init, class_, etc.
class WrapperFuncs
{
public:
static void doSomething(CppClass & c, tuple t)
{
// Special extraction: Convert python arg ( a tuple) into C++ args.
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?