Boost logo

Boost :

From: Anton Gluck (gluc_at_[hidden])
Date: 2000-11-28 11:35:36

> > Since now I am returning a pointer I wrote a
> > to_python for this that examines the ClusterVar, casts it as CatVar or
> > ContVar accordingly, and then returns the object. Now Python will receive
> > actual CatVar and ContVar objects. In case somebody is interested, here is
> > the code for to_python:
> >
> > PyObject* to_python(ClusterVar* cv)
> > {
> > if (typeid(*cv) == typeid(CatVar)) {
> > return to_python(dynamic_cast<CatVar&>(*cv));
> > }
> > else if (typeid(*cv) == typeid(ContVar)) {
> > return to_python(dynamic_cast<ContVar&>(*cv));
> > }
> > else return to_python(*cv);
> > // in case we have a genuine ClusterVar object
> > }
> I don't really understand what you're up to with this, but it strikes me (in
> my gut - oof!) as highly likely to be unneccessary, and more suitably
> replaced by Ullrich's declare_base() mechanism. He's a better candidate to
> help you out with this, though.

Without the casting, Python just gets ClusterVar objects that have lost
their CatVar-ness or ContVar-ness as you so nicely said. I am declaring
ClusterVar as base class of CatVar and ContVar in the wrapper code,
though. That's why I was really quite puzzled when I wasn't able to get
back CatVars and ContVars in Python.

There'd be other ways to do the casting - I could use static casting in
the code above, or use bad_cast exceptions to test whether I have a CatVar
or a ContVar - but for me this didn't work without the casting.


Boost list run by bdawes at, gregod at, cpdaniel at, john at