Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-12-07 18:13:06


----- Original Message -----
> From: "Ullrich Koethe" <koethe_at_[hidden]>
>
> David Abrahams wrote:
>
> > I think I see a way to do this without the get_window_class() function. I
> > think it also will substantially cut down on code bloat. The usage would be
> > something like:
> >
> > reswindow_class.declare_base(PyObject_Getattr(PyImport_GetModule("uimodule")
> > , "Window)))
> >
>
> I tried this (with corrected function names :-), but it crashed. Perhaps
> it doesn't work because Py_Initialize() must be called prior to a call
> to PyImport_ImportModule("ui"). But this would create another
> interpreter which isn't what we want either.

Don't you mean PyInitModule() rather than Py_Initialize()? Maybe you're not
allowed to initialize a new module during the initialization of another one.

> Anyway, I just realized that the function "get_window_class()" is
> unnecessary because we can do the following directly within
> "logicmodule.cpp":
>
> boost::python::detail::extension_class<Window> * window_class =
> dynamic_cast<boost::python::detail::extension_class<Window> *>(
> boost::python::detail::class_registry<Window>::class_object());

Ick! But I see your point.

> Of course, this should be encapsulated. Encapsulation would be much
> easier if the inheritance hierarchy would be changed into:
>
> template <class T>
> class typed_extension_class_base : public extension_class_base
> { ... };
>
> template <class T, class U = held_instance<T> >
> class extension_class
> : public python_extension_class_converters<T, U>, functions
> public typed_extension_class_base<T>
> { ... };

I think I see where you're going with this...

> Then, class_registry<T>::class_object() could return a
> typed_extension_class_base<T>*, and one could simply write:
>
> reswindow_class.declare_base(get_class_object<Window>());
>
> (or something similar, according to MSVC's limitations).

MSVC can handle this syntax if you use the "default pointer argument" hack (see
boost/operators.hpp). Now the question becomes: should there be a distinction
between class_registry<T> and typed_extension_class_base<T>?

> Note that we
> can't use extension_class directly because we don't know the
> held_instance type if callbacks are enabled.

It took me a little while to figure out what you were saying, but now I think I
understand. You need to know the held_instance type to do the downcast/upcast
stuff.

OK, we should definitely explore this for the release following the one Beman is
going to do this weekend. We can begin (on a branch of course) as soon as you
like.

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk