[C++-sig] Extracting inherited class instances

Furkan Kuru furkankuru at gmail.com
Wed Sep 12 12:45:26 CEST 2007


Hello,

I have a class exposed to python and extract it like this;

X& xins = boost::python::extract<X&> (xList.pop())    ( xList is a python
list)

And now I need a change and want to derive a class from X.

Actually I will need several classes derived from X.

I know how to expose them to python but I do not know how to extract and
manage them?

The only thing that comes to my mind is writing too many try catch blocks
nested.

int
len=boost::python::len(xList);

for(int i=0;i<len;i++) {

boost::python::object cur = xList.pop();

try {

Y& xins = boost::python::extract<Y&> (cur);

YHandler(Y);

}

catch(...) {

try {

Z& xins = boost::python::extract<Z&> (cur);

ZHandler(Z);

}

catch(...) {

... nested ugly structure goes on like this

}

}

}
Any help is appreciated.
-- 
Furkan Kuru
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070912/f4a10f4d/attachment.htm>


More information about the Cplusplus-sig mailing list