just another simple member function callback implementation 0.0.1

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Back To Listings  ]
 
Category:Wiki/Software/WidgetsRating:
1.66 
Name:just another simple member function callback implementationPopularity:3%
Version:0.0.1License:free for all
Author:interEMail: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_ */


Articles

Submit Article | View All ]

No articles found.


Comments

Submit Comment ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2023 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.