[C++-sig] Python + Boost Python V2 + downcasting

Nicolas Lelong n_lelong at hotmail.com
Thu Nov 7 14:29:48 CET 2002


> > I even thought about implementing my own 'isinstance' function but
> > I'm not familiar enough with boost python & python !!... Any help or
> > advice will be _greatly_ appreciated :)
>
> Why do you need to do this? Such downcasting is usually the mark of a
> poor design.

Thanks for your reply,

I'm aware that this design decision may not be the best - but it suits the
needs I have for now... I have a tree structure representing hierarchical
dependencies between elements of a graphical system. The objects have a
similar base interface that is used to navigate through the graph - but each
class of item has a set a specific properties.

We decided to use a 'node class' identification system based on C++ RTTI
because we did not want to reinvent the weel. Now, if I really can't get the
correct info in Python, I'll have two choices:
- propose a change in the node class identification system (i'd rather not)
- drop Python (i'd rather not !).

I believe that there must be a way to extract to RTTI info from the object
holder as it is done to allow the call of a function that takes a
Derived&(or *) in parameter - it would help me going on in my Python
evaluation - before having to rethink the whole heart of the application !
Could you give me a few hints to create my own implementation of
'isinstance' as i don't have much time to investigate the boost python v2
internal structures ?

Thank you,
Nicolas.




More information about the Cplusplus-sig mailing list