Search code examples
c++boostrational-rose

Best way to avoid a thousand if statements?


I basically have this problem: right now, we have a system where it gets a string as input, and it basically says ACTION:.

For each of the actions there is an automatically generated function(Rational Rose GRRR), such as

bouncer_comm.chatMessage("data goes here").sendAt(msg->sapIndex0());
bouncer_comm.askforname().sendAt(msg->sapindex0());

bouncer_comm returns an RTOutSignal, I can't create them manually because of the bizarre structure rose uses.

Right now, my only option is to create a hundred or so if statements, where I do:

if(action == "CHAT")  bouncer_comm.chatMessage("data goes here").sendAt(msg->sapIndex0());

Which is realllllyy annoying.

What would be the best way to avoid this? I've looked at / tried countless things, this is a really old version of rational rose (pre 2k) and yeah.

If anyone has any ideas that would be amazing.


Solution

  • I like @cobbal's idea of the function pointer hash above, but you could replace this conditional logic with polymorphism.

    see: http://c2.com/cgi/wiki?ReplaceConditionalWithPolymorphism