How to redesign big switch case?

From: Siemel Naran (SiemelNaran_at_REMOVE.att.net)
Date: 03/22/04


Date: Mon, 22 Mar 2004 04:50:46 GMT

How to redesign big switch case?

I wrote an editor that reads chars, and does a switch (char) to process the
character. For example, if char is HOME then go to the beginning of the
line, and if char is CTRL-RIGHT then go to the start of the next word. As I
added more cases and support for reverse incremental history mode, the code
grew longer and longer. It is now 562 lines, or 58% of the entire file.
This seems a bit clumsy. Fortunately the code does not have any goto
statements and seems pretty structured and clear to me, so it's not exactly
sphaghetti code. Is it worthwhile to change the code? If yes, then how?
Finally, it would be nice to allow users to derive their own editor class
from my one and add support for more special keys.

Thanks.



Relevant Pages

  • Re: How to redesign big switch case?
    ... > I wrote an editor that reads chars, and does a switch to process ... if char is HOME then go to the beginning of the ... it would be nice to allow users to derive their own editor class ... virtual void onKey ...
    (comp.lang.cpp)
  • Re: Are _T() and TEXT() macros equivalent?
    ... are not concerned if a char takes 1 byte or 100. ... since the language defines an object ... various ramifications of using and not using the switch. ... Why the fixation on basing the meaning of the keyword "char" on a compiler ...
    (microsoft.public.vc.mfc)
  • Re: Nice problem to solve: switch via a table
    ... Implement a switch statement in Forth. ... char a char e char i char o char u char y ... Say we instead build something like a jump table. ... But I'm not sure that Forth needs giant switch statements ...
    (comp.lang.forth)
  • [Full-disclosure] DoS code for Cisco VLAN Trunking Protocol Vulnerability
    ... 1.the switch must in Server/Client Mode. ... 2.the port,attacker connected,must be in trunk Mode. ... int main(int argc, char *argv) ...
    (Full-Disclosure)
  • DoS code for Cisco VLAN Trunking Protocol Vulnerability
    ... 1.the switch must in Server/Client Mode. ... 2.the port,attacker connected,must be in trunk Mode. ... int main(int argc, char *argv) ...
    (Bugtraq)