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 » Sun May 25, 2008 12:13 pm

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 » Sun May 25, 2008 4:26 pm

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 » Tue May 27, 2008 4:43 am

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 » Tue May 27, 2008 7:25 pm

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 » Tue May 27, 2008 11:00 pm

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 » Sun Jun 08, 2008 10:45 am

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

Post Reply