Boost logo

Boost Users :

Subject: [Boost-users] a quick question regarding extending a class with boost::function
From: Littlefield, Tyler (tyler_at_[hidden])
Date: 2011-04-06 12:22:36


Hello all:
I am working on a mud engine (essentially a game engine), and I had a quick question. I have an event class (yes, I know about boost::signal, but I don't want to go back and it doesn't support delayed events). I would like to set up my event class so that it will take a function object as it's callback, which allows someone extending the engine to add their own content to use global functions, member functions, lambdas, etc etc.

Now, here is my problem, and this may be more of a c++ question than a boost question; I'm not really sure.

Right now, every time an event gets called, I pass in the object that called it, as well as an EventArgs pointer. So an event callback function might look like this:
void OnMouseDown(Object* obj, OnMouseDownArgs* args);
Now, it might be useful to have the x and y coordenates where the OnMouseDown event was called, which means I end up doing something like:
class OnMouseDownArgs:public EventArgs
{
public:
int x, y;
};
which essentially means that for every new type of event, I have to declare an EventArgs class for that.
So here was my idea; I thought it would be kind of cool to do something like:
Event* OnMouseDown<int, int> = new Event<int, int>();
which leads me to a question. given that template, how would I define a function object with those arguments? better yet, how would I accept an arbitrary number of arguments to the template, then take those arguments and create a boost::function object with them, as well as extend the .Call method to take the arguments I passed in?
So in summary, I am trying to extend the boost::function object to accept a set of arguments passed in through a template when the Event object was created, as well as extend the Call method on the Event object to take the two ints as in the MouseDownEvent as arguments.
Thanks,
Ty


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net