|
Category: | Wiki/Software/Widgets | Rating: | |
Name: | just another simple member function callback implementation | Popularity: | 3% |
Version: | 0.0.1 | License: | free for all |
Author: | inter | EMail: | laGrandeInter1908 |
Created: | Sep 03, 2008 |
Updated: | Sep 04, 2008 |
Home Page: | http://www.fltk.org (805 visits) |
Download: | ftp://www.fltk.org (883 visits) |
Description: | A really simple one, no patch, fast, C++ standard compliant, just include the header.
Sample:
class fooWin : public Window, public Slot<fooWin> {
.....
fooWin(...)
...
{
// for member widget
slot<&fooWin::funcControlWidget>(barWidget);
// for this window
slot<&fooWin::funcControlThisWindow>();
}
}
/*------------------------------fltk/Slot.h--------------------------*/
#ifndef _FLSLOT_H_
#define _FLSLOT_H_
namespace fltk {
class Widget;
template<typename windowT>
class Slot {
public:
template<void (windowT::*methodP)()>
slot() {
static_cast<windowT*>(this)->callback(&self_stub<methodP>);
}
template<void (windowT::*methodP)() const>
slot() {
static_cast<windowT*>(this)->callback(&self_stub<methodP>);
}
template<void (windowT::*methodP)(),typename widgetT>
slot(widgetT* widget) {
widget->callback(&stub<methodP>,static_cast<void*>(this));
}
template<void (windowT::*methodP)() const,typename widgetT>
slot(widgetT* widget) {
widget->callback(&stub<methodP>,static_cast<void*>(this));
}
template<void (windowT::*methodP)(),typename widgetT>
slot(widgetT& widget) {
widget.callback(&stub<methodP>,static_cast<void*>(this));
}
template<void (windowT::*methodP)() const,typename widgetT>
slot(widgetT& widget) {
widget.callback(&stub<methodP>,static_cast<void*>(this));
}
private:
template<void (windowT::*methodP)()>
static void self_stub(Widget* window){
(static_cast<windowT*>(window)->*methodP)();
}
template<void (windowT::*methodP)() const>
static void self_stub(Widget* window){
(static_cast<windowT*>(window)->*methodP)();
}
template<void (windowT::*methodP)()>
static void stub(Widget* widget,void* window){
(static_cast<windowT*>(window)->*methodP)();
}
template<void (windowT::*methodP)() const>
static void stub(Widget* widget,void* window){
(static_cast<windowT*>(window)->*methodP)();
}
};
}
#endif /* _FLSLOT_H_ */
|
[ Submit Article | View All ]No articles found.
[ Submit Comment ] |
| |