Today's fun C++ saga starts with some progress on the event
mechanism I was thinking about yesterday. I am now able to
trigger events like this:
void SomeWidget::RandomlyFireEvents()
{
KeyEvent e;
/* fill in e */
FireEvent(&KeyEventListener::KeyPressed, e);
}
This has the advantage of being strongly typed, with most of the work done at compile-time. FireEvent is a funky method that is defined like this:
typedef void (Listener::* pmf_t)(EventObj); template<class Listener, class EventObj> inline void Event<Listener, EventObj>::FireEvent(pmf_t pmf, const EventObj &e) { listeners_t::iterator i; for (i = listeners.begin(); i != listeners.end(); i++) { ((*i)->*pmf)(e); } }
I guess all you C++ gurus out there will think this is obvious, but I thought it was pretty neat :-)
I still need to do some tests to determine the space/time efficiency of this system though. Oh well.
(Some time later...) Culus has sort of convinced me that this won't work if a widget wants to have multiple events of the same type, but in different queues. He plugged the deity system as being more flexible. It is better in some ways, but I really do not like the void * event parameter that is used in so many widget libraries.... <sigh>. Is there really no perfect solution?
I've been putting it off, but I think I need to rethink the db.d.o code and redo a lot of it.... hm...
