Index:
[thread]
[date]
[subject]
[author]
From: Garrett Mitchener <wgm2@duke.edu>
To :
Date: 08 Mar 1999 21:04:52 -0500
Re: design
Jay Steele <jes22@duke.edu> writes:
> I have a design question...
> when dealing with command line parameters, the help page mentions that
> you should not use switch statements, but maybe a map of command line
> objects. What exactly would the command line objects map to...an object
> of function to call when the command line object is "on"? I am confused
> what the best way to handle command line stuff is without using if's and
> switch statements. Could someone please explain a solution?
>
> thanks
> jay
See the help page, design hints, and look under scandir stuff. The
information about command objects is in there, although it's written
in terms of scanning and sorting. The idea is that you replace a
bunch of swtich/if-else spaghetti with something like this:
map<string,Command*> optionTable;
optionTable["r"] = new ReverseCommand(...);
optionTable["smart"] = new SmartCommand(...);
...
OptionIterator i = ...(argc,argv);
while( !i.IsDone() )
{
if( optionTable contains i )
{
optionTable[i]->Execute();
}
}
Cryptically yours,
-- "The Crypt Keeper" :-)
Index:
[thread]
[date]
[subject]
[author]