If I have an abstract base class and a derived class that inherits from it but I have another class that takes the abstract base class object as an argument, how should I go about wrapping it?
class A {
public:
A(int x, int y);
virtual int FooA(int x, int y) = 0;
virtual void FooB() = 0;
}
class B : public A{
B(int x, int y, int z, int w);
int FooA(int x, int y);
void FooB();
void FooC(int z, int w);
}
class C {
public:
C(A* ptr, int p);
}
How should I go about wrapping this as a whole? I know that I am not supposed to wrap the abstract class A but I am having difficulties wrapping C since I do not have the python object for A
EDIT: Actually I managed to wrap the class but I am still getting errors which I will illustrate further.
source.pyx
cdef extern from "A.h"
cdef cppclass A:
A(int x, int y)
int FooA(int x, int y)
void FooB()
cdef extern from "B.h"
cdef cppclass B(A):
B(int x, int y, int z, int w)
int FooA(int x, int y)
void FooB()
void FooC(int z, int w)
cdef extern from "C.h"
cdef cppclass C:
C(A* ptr, int p)
cdef class pyA:
cdef A* baseptr
def __cinit__(self, int x, int y):
if type(self) is A:
self.baseptr = new A(int x, int y)
def __dealloc__(self):
if type(self) is A:
del self.baseptr
def FooA(self, int x, int y):
pass
def FooB(self):
pass
cdef class pyB(pyA):
def __cinit__(self, int x, int y, int z, int w):
if type(self) is pyB:
self.derivedptr = self.baseptr = new B(int x, int y, int z, int w)
def __dealloc__(self):
del self.derivedptr
def FooC(self, int z, int w):
self.derivedptr.FooC(int z, int w)
cdef class pyC:
cdef C *thisptr
def __cinit__(self, pyA ptr, int p):
self.thisptr(<A *> ptr.thisptr, int p)
def __dealloc__(self):
del self.thisptr
This compiled by when I was testing pyC and passing pyB as the first argument, I got:
TypeError: "Expected pyA, got pyB".
Shouldn't pyB be able to be passed as the first argument as well since it is a subclass of pyA? Or am I way off?