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?
Calling an event by a literal Topic is solved
Re: Calling an event by a literal
No, but then I didn't understand at all what you are asking.the_drow wrote:Any ideas?
-Max
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.
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.