|
Boost : |
From: Ullrich Koethe (koethe_at_[hidden])
Date: 2000-12-07 16:48:17
David Abrahams wrote:
> > 4. in logicmodule.cpp:
> > - Include "uicommon.hpp"
> > - declare the wrapped "Window" as base of the wrapped
> > "ResultWindow"
> >
> > reswindow_class.get_extension_class()->
> > declare_base(get_window_class());
>
> 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.
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());
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>
{ ... };
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). Note that we
can't use extension_class directly because we don't know the
held_instance type if callbacks are enabled.
Ulli
-- ________________________________________________________________ | | | Ullrich Koethe Universität Hamburg / University of Hamburg | | FB Informatik / Dept. of Computer Science | | AB Kognitive Systeme / Cognitive Systems Group | | | | Phone: +49 (0)40 42883-2573 Vogt-Koelln-Str. 30 | | Fax: +49 (0)40 42883-2572 D - 22527 Hamburg | | Email: u.koethe_at_[hidden] Germany | | koethe_at_[hidden] | | WWW: http://kogs-www.informatik.uni-hamburg.de/~koethe/ | |________________________________________________________________|
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk