[C++-sig] wrap C++ function with private copy constructor

Manuela Kaelberer Manuela.Kaelberer at LBBW.de
Wed Jul 13 16:19:44 CEST 2011


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 at LBBW.de
www.LBBW.de

Landesbank Baden-Wuerttemberg
Anstalt des oeffentlichen Rechts
Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz
HRA 12704
Amtsgericht Stuttgart



More information about the Cplusplus-sig mailing list