Swig wrapping C++ Polymorphism

J

James Carroll

Hi, I asked this on the SWIG mailing list, but it's pretty dead over there....
I'm trying to get Python to pass a subclass of a C++ object to another
C++ object...

I have three C++ classes,

TiledImageSource

ZoomifyReaderWx which ISA TiledImageSource

TiffWriter which has a method which takes a TiledImageSource

reader = bright.ZoomifyReaderWx()
writer = bright.TiledTiffWriter()
writer.SetImageSource(reader) <- doesn't work, error below.

TiffWriter has a SetImageSource method that takes a pointer to a
TiledImageSource.
When I try to pass an instance of ZoomifyReaderWx to TiffWriter, SWIG
can't hook the two up.

How can I fix this? I think I need a typemap, but I'm not sure of the syntax.

Thanks!
-Jim


Test script
----------------------------

reader = bright.ZoomifyReaderWx()
reader.Open("C:/Slides/test.pff")

writer = bright.TiledTiffWriter()
writer.SetImageSource(reader)
writer.CreateFile("C:/Slides/test.tif")

while not writer.IsFinished():
writer.ProcessABit()
print ".",

Exception
----------------------------
C:\jimc\prj\bright\scripts\vsEdit>python piplineTest.py
Traceback (most recent call last):
File "piplineTest.py", line 11, in ?
writer.SetImageSource(reader)
File "C:\jimc\prj\bright\scripts\vsEdit\bright.py", line 88, in SetImageSource

def SetImageSource(*args): return _bright.TiledTiffWriter_SetImageSource(*ar
gs)
TypeError: argument number 2: a 'TiledImageSource *' is expected, 'PySwigObject(
_p_ZoomifyReaderWx)' is received


Interface files (exceprts)
----------------------------

class ZoomifyReaderWx: public TiledImageSource
{
public:
bool Open(wxString filename);
void Close();

ZoomifyReaderWx();
//%pragma(python) addtomethod = "__init__:self._setOORInfo(self)"

// necessary for ZoomableImageReader
virtual int GetWidth(int reduction = 0);
virtual int GetHeight(int reduction = 0);
....


class TiledTiffWriter
{
public:
TiledTiffWriter();
//%pragma(python) addtomethod = "__init__:self._setOORInfo(self)"

void SetImageSource(TiledImageSource *source);
void SetJpegQuality(int quality) { m_iJpegQuality = quality; }
void CreateFile(char *filename);
....

class TiledImageSource
{
public:
//%pragma(python) addtomethod = "__init__:self._setOORInfo(self)"

virtual int GetWidth(int reduction = 0);
virtual int GetHeight(int reduction = 0);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top