Hi,
I'm writing a commandline argument parser that can handle switches
by using some techniques similar to the Qt slot mechanism.
example:
// inheritance method (what I'm trying at the moment)
parser.setSwitch(BoolSwitch("v", "verbose", &bVerbose));
parser.setSwitch(GeometrySwitch("s", "size", &sizeGeometry));
// template method
parser.setSwitch(Switch<bool>("v", "verbose", &bVerbose));
parser.setSwitch(Switch<Geometry>("s", "size", &sizeGeometry));
call:
char **argv = {"./example", "--verbose", "-s", "800x600"};
parser.parseCommandLine(4, argv);
Internally I store the Switches in a map using Switch * base pointers.
The appropriate method is called later using dynamic binding.
Q:
So if I'm going to use templates, can I create a similar anonymous
Switch * array? I can't use Switch<someType> * because I don't know
the specific type at definition time...
Somehow templates seem more elegant to use here. Perhaps it's just
my urge to finally start using templates somewhere ;)
Q:
In the case of non-atomic types like Geometry (2 params), I am in
need of a generic parse method... using inheritance it's just overriding,
but what to do with templates? Is this a k.o.-criteria for templates?
thx in advance, Markus
--
Analysis: sums with letters. It's for the people whose
brains aren't clever enough for numbers. (Terry Prattchet)