By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

Swig wrapping C++ Polymorphism

P: n/a
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);
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.