wrap C++ function with private copy constructor
Hi, I have to wrap a C++ API for Python. There are a couplt of difficulties: - The C++ classes have private constructors. - pointers to class instances are parameters for functions - callbacks that are initiated by the C++ side, but call functions implemented on the Python side. How do I do that? Any hint is appreciated. Example: class X { public: X(); virtual ~X(); virtual callback(A* a) = 0; }; class Y::X { Y(); ~Y(); callback(A* a); } class M { public: M(); virtual ~M() protected: M(const M& m); M & operator=(const M& m); } class N::M { public: N() virtual ~N() private N(const N& n); N& operator=(const N& n); } class A: { public: A(); protected: A(const A& a); A& operator=(const A& a) } class B::A { public: B(); void create(Y* y, M* m); private: B(const B& b); B& operator=(const B& b); }; ===================================================== Python: class Y: __init__(): pass def callback(a): print "callback implemented in python" y=Y() n=N() b=B() b.create(y, n) The callback function y.callback(A* a) will be called by the C++ API when an event occurs. Kind Regards Manuela Kaelberer ---------------------------------------------- Manuela Kälberer IT FM Consulting (1432 H) Landesbank Baden-Württemberg Am Hauptbahnhof 2 D-70173 Stuttgart Phone +49 711 127-43753 Fax +49 711 127-437 59 manuela.kaelberer@LBBW.de www.LBBW.de Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart
On Wednesday 13 July 2011 07:19:44 Manuela Kaelberer wrote:
I have to wrap a C++ API for Python. There are a couplt of difficulties: - The C++ classes have private constructors.
Use boost:python::no_init in class_<...>.
- pointers to class instances are parameters for functions
This is not a problem since boost.python handles pointers and references in function parameter lists automatically.
- callbacks that are initiated by the C++ side, but call functions implemented on the Python side.
This is a little tricky but is well-covered in the documentation: http://www.boost.org/doc/libs/1_47_0/libs/python/doc/tutorial/doc/html/pytho... Regards, Ravi
participants (2)
-
Manuela Kaelberer -
Ravi