Calling an event by a literal Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
the_drow
Experienced Solver
Experienced Solver
Posts: 67
Joined: Fri Sep 15, 2006 6:20 am

Calling an event by a literal

Post by the_drow »

How can I raise an event by using a literal and without if...else if...?
That should be really time consuming since I have lots of events that are raised by an XML script.
Different event for each tag.
Any ideas?
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Re: Calling an event by a literal

Post by mc2r »

the_drow wrote:Any ideas?
No, but then I didn't understand at all what you are asking.

-Max
bone
Experienced Solver
Experienced Solver
Posts: 74
Joined: Fri Nov 30, 2007 10:11 am
Location: Oz

Post by bone »

How can I raise an event by using a literal and without if...else if...?
Perhaps a function reference in an array or hash map capable of storing objects and accessing the function references via a literal string key.
Cheers
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Isn't the "event table" what you need ?
Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank »

I would use a:

typedef std::map<std::string, boost::function<whatever> > EventMap;
EventMap MyEventMap;
// Fill Event Map

The String is the literal. The Function the function to call. Then, it's a simple

EVentMap::iterator it = MyEventMap.find("My Event-Name");
if (it != MyEventMap.end()) it->second();
else throw std::excepton("Huh? Unknown Event!");

If your Compiler has TR1 already, you can use tr1::function<> instead of boost's. If your STL has a Hash-Map, it could be more performant to use that.
the_drow
Experienced Solver
Experienced Solver
Posts: 67
Joined: Fri Sep 15, 2006 6:20 am

Post by the_drow »

thanks for everyone for their help.
I found it :)
Post Reply