[C++-sig] Possible overload<> template for class members
William Trenker
wtrenker at hotmail.com
Fri Dec 13 07:12:26 CET 2002
I've been getting familiar with wrapping overloaded C++ class methods for
Python using this syntax:
using namespace fltk;
using namespace boost::python;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(show_noArgs, show, 0, 0)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(show_pWindow, show, 1, 1)
BOOST_PYTHON_MODULE(byFLTK)
{
class_<Window, boost::noncopyable >("Window", init<int,int,const char
*>())
.def("show", (void(Window::*)())0, show_noArgs())
.def("show", (void(Window::*)(const Window*))0, show_pWindow())
;
}
(Like most GUI's FLTK has many overloaded methods such as window->show() or
window->show(parent).)
It took me a lot of digging to get BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS()
and the function casts in the .def's figured out. But it works just fine.
I don't know b::p well enough yet to submit proposed changes, but I was
wondering if it would be possible to have a template, possibly called
"overload", that works for overloded class members like the init<> template
does for overloaded constructors? Maybe something like this:
using namespace fltk;
BOOST_PYTHON_MODULE(byFLTK)
{
class_<Window, boost::noncopyable >("Window", init<int,int,const char
*>())
.def("show", overload<void,void>(), &Window::show)
.def("show", overload<void,const Window*>(), &Window.show)
;
}
Of course, unlike constructors, a return type has to be provided for member
functions; so I've just thrown that in as the first parameter in overload<>.
Is something like this even possible?
Cheers,
Bill
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
More information about the Cplusplus-sig
mailing list