Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Callbacks and Timers » partial parametrizing of Callback<>
partial parametrizing of Callback<> [message #27408] Thu, 15 July 2010 21:33 Go to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi folks,

imagine i want to do the following

void MyCallback::Action(int i, float f)
{
	RLOG("" << i << " " << f);
}

void MyCallback::Test()
{
	Callback1<int> cb;
	cb = callback2(this, &CLASSNAME::Action, 1.0f); //latter param already specified
	cb(123); //first parameter specified now
}


partially specify the arguments to the callback, the rest specify later.

would it be possible with callbacks (i imagine one needs to extend the template generators for that)?
Re: partial parametrizing of Callback<> [message #27409 is a reply to message #27408] Thu, 15 July 2010 22:36 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

kohait00 wrote on Thu, 15 July 2010 21:33

hi folks,

imagine i want to do the following

void MyCallback::Action(int i, float f)
{
	RLOG("" << i << " " << f);
}

void MyCallback::Test()
{
	Callback1<int> cb;
	cb = callback2(this, &CLASSNAME::Action, 1.0f); //latter param already specified
	cb(123); //first parameter specified now
}


partially specify the arguments to the callback, the rest specify later.

would it be possible with callbacks (i imagine one needs to extend the template generators for that)?



Hi kohait,

If I understand right what you want to achieve, than it is possible and actually quite easy Wink :
void MyCallback::Action(int i, float f)
{
	RLOG("" << i << " " << f);
}

void MyCallback::Test()
{
	Callback1<int> cb;
	cb = callback1(this, &CLASSNAME::Action, 1.0f);
	cb(123);
}

As you can see, you were very close, just one letter is different Smile

Hope I got you question right, it looks suspiciously simple.

Best regards,
Honza
Re: partial parametrizing of Callback<> [message #27410 is a reply to message #27409] Fri, 16 July 2010 07:06 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
yeaaaaaa, and it works..thanks a lot.

i didnt know something like that was possible, found callback was strict enough concerning type checks.. well perfect. has this support for such semmi parametrized Callback arrived recently or already long time ago.

but what does not work is with 3 params..
void MyCallback::Action(int i, float f)
{
	RLOG("" << i << " " << f);
}

void MyCallback::Action2(int i, float f, int k)
{
	RLOG("" << i << " " << f);
}

void MyCallback::Test()
{
	//works
	Callback1<int> cb;
	cb = callback1(this, &CLASSNAME::Action, 12.0f);
	cb(123);	

	//DONT works
	Callback2<int, float> cb2;
	cb2 = callback2(this, &CLASSNAME::Action2, 1234);
	cb2(234, 10.f);

	//DONT works
	Callback1<int> cb3;
	cb3 = callback1(this, &CLASSNAME::Action2, 1234, 13.0f);
	cb3(234);
}


[Updated on: Fri, 16 July 2010 07:20]

Report message to a moderator

Re: partial parametrizing of Callback<> [message #27418 is a reply to message #27410] Fri, 16 July 2010 15:16 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

kohait00 wrote on Fri, 16 July 2010 07:06

i didnt know something like that was possible, found callback was strict enough concerning type checks.. well perfect. has this support for such semmi parametrized Callback arrived recently or already long time ago.

It is there as long as I remember Smile

The case with three parameters is not used that often, therefore there is no template for it. Also with increasing number of parameters, the complexity rises. For 3 parameter function, we should supply 2 functions (returning 1 and 2 parameter callback), for 4 parameter function 3 generating functions etc.

But you can "easily" (not to be taken too seriously Smile ) extend the templates yourself. I know you already looked into the internals of Callback, so it should not be that hard for you. Sorry for not supplying the actual code, but my head goes dizzy whenever I start thinking about templates with so many parameters - BTW: that is possibly one of the reasons why such complicated callbacks are not present in U++ by default Wink

Regards,
Honza
Re: partial parametrizing of Callback<> [message #27421 is a reply to message #27418] Fri, 16 July 2010 19:17 Go to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
thanks for the infos,

its no problem not having them, i was just wondering Smile one can accomodate the code to fit it as well.but good to know
Previous Topic: Strange crash connected to Timer
Next Topic: PROPOSAL: delegate like separation of method and args in Callbacks
Goto Forum:
  


Current Time: Thu Mar 28 16:06:54 CET 2024

Total time taken to generate the page: 0.01179 seconds