Boost logo

Boost Users :

Subject: [Boost-users] [python] converting C++ object to PyObject
From: Johan Råde (johan.rade_at_[hidden])
Date: 2011-07-27 05:06:16


I have three C++ classes X, Y and Z that I have exported from C++ to
Python using python::class_.

Now I want to write a factory function like

PyObject* f(char c)
{
     if(c == 'x')
         return new X;
     else if(c == 'y')
         return new Y;
     else if(c == 'z')
         return new Z;
     else
         PyErr_SetString(PyExc_ValueError, "Bad function argument");
}

and export that function to Python.

What is missing here is code that converts X*, Y* and Z* to PyObject*.
How do I write that?

Thank you,
Johan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net