Copy function at runtime?

I have a library with a function that accepts a function pointer and a parameter to give the function. I'm wrapping the thing in a class and so for each instance of the class I give it a function pointer to a private static dispatch function, and the parameter I give it is the this pointer. The dispatch function just calls the instance version of the function from the instance pointer given as a parameter. The issue is, when the class is destructed, it needs to remove that function-parameter pair from the functions-to-call list - but it only searches by function pointer and I cannot make it take a parameter to match with.

Is there a way I can create, at runtime, copies of the dispatch function so that the function pointers are unique? Or is there another solution?
LB.

I think, and I haven't used it for what you describe, but maybe if you can use boost for this, using boost::function and boost::bind you can get what you are looking for (I think).

Essentially boost::function acts like your function pointer, it doesn't buy you much on it's own, in your case.

1
2
3
4
5
6
void( *someFunc )(int) = &doSomething;
someFunc( 10 ); 

//using boost	
boost::function<void(int)> otherFunc = &Print;
otherFunc( 10 );


Then when you use boost::bind you can pass up to 9 parameters for regular function and 8 for member functions (this-> is implicit). Your function pointer is essentially more than just a function pointer now. I think then you can use this to describe each classes search criteria. My usage and wording may be off, but I think it is possible using a variation of boost::bind and boost::function.

edit:
This may not be possible with the private functions, but I'm not sure

edit 2:
After further investigation this may be of use to you.

Comparing Boost.Function function objects
http://www.boost.org/doc/libs/1_49_0/doc/html/function/tutorial.html#id1530326
Last edited on
The library is hard coded to take a pointer-to-function, I'm not sure how to get that from boost, or if what I got would be unique from any other instance.
And it is that library that has the container, which you cannot modify the search criteria?
http://github.com/udp/lacewing/blob/master/src/windows/EventPump.cc
Scroll down to about line 260 (line 247 is the remove function)
Reference: http://lacewing-project.org/docs/eventpump/Post.html (slightly dated)

I have absolutely no idea what I can do for this case.
Last edited on
Nevermind, I misunderstood how it works. It calls the function once after I request it to, and then forgets about it. This makes my life much easier. Sorry for the hassle.
Topic archived. No new replies allowed.