Page 1 of 1

new Event parameters

Posted: Tue Dec 14, 2004 19:18
by spannerman
Hi Eddie,

I posted this question in the wrong forum at one point, so you may have seen it briefly, but here it is again.

I am upgrading my application to use the new event subscription technique...I have been holding off doing it for a while but Ive heard that the new way yields better performance. It's all going well, but I have a few lines that I cant get to compile anymore, and these concern the passing of some extra parameters to my method which handles the event.

So, for example, I used to use this line of code which subscribed an event and in addition passed the String "Basic" through to my handlePanelShown method:


Code: Select all

myPanel->subscribeEvent( StaticText::EventShown,boost::bind(&MyWindow::handlePanelShown, this, _1, "Basic") );


The new way which does away with boost and uses the Subscriber probably should look something like this:

Code: Select all

myPanel->subscribeEvent( StaticText::EventShown,Event::Subscriber(&MyWindow::handlePanelShown, this,  "Basic") );


except this no longer compiles. The error says I am passing the wrong number of arguments, but my handlePanelShown method has not changed.

Any ideas what I might be doing wrong?

new Event parameters

Posted: Tue Dec 14, 2004 19:53
by nfz
I know I am not CE but I'll make a stab at this since I started you on the change and I suspected this would cause a headache for you.

Event::Subscriber template does not support user definable number of arguments like boost::bind does. I think you have two alternatives. The first one is to change your design a bit and pass those user defined arguments by some other means or setup some state machines. The second option is to continue using boost::bind for those methods that take more arguments than the Event::Subscriber does and live with the overhead for those few methods that use it.

new Event parameters

Posted: Tue Dec 14, 2004 21:17
by spannerman
Aah, ok, Cheers nfz. I dont fancy going back to boost so I'll get some alternative going instead. Like you said, not too many methods are affected so shouldnt be too bad.

new Event parameters

Posted: Wed Dec 15, 2004 09:30
by CrazyEddie
Hi,

These would have been my suggestions too :D

The approach I would take would probably be to code a template functor class that could accept additional parameters (or something of that nature).

CE.