9 #ifndef _COMMANDLINEPARSER_
10 #define _COMMANDLINEPARSER_
16 #include <QtCore/QStringList>
31 typedef std::map<std::string,std::pair<bool*,std::string> >
switches_t;
43 switches_t::iterator boolarg(
_switches.begin());
44 switches_t::iterator boolargEnd(
_switches.end());
45 for (;boolarg != boolargEnd; ++boolarg)
47 cout << boolarg->first <<
":"<<boolarg->second.second<<endl;
50 intarguments_t::iterator intarg(
_intargs.begin());
51 intarguments_t::iterator intargEnd(
_intargs.end());
52 for (;intarg != intargEnd; ++intarg)
54 cout << intarg->first <<
":"<<intarg->second.second
55 <<
" Default value is '"<<*(intarg->second.first)<<
"'"<<endl;
58 stringarguments_t::iterator strarg(
_stringargs.begin());
59 stringarguments_t::iterator strargEnd(
_stringargs.end());
60 for (;strarg != strargEnd; ++strarg)
62 cout << strarg->first <<
":"<<strarg->second.second
63 <<
" Default value is '"<<*(strarg->second.first)<<
"'"<<endl;
80 QStringList::const_iterator argument(argumentList.constBegin()+1);
81 for (; argument != argumentList.constEnd(); ++argument)
83 switches_t::iterator boolarg(
_switches.find(argument->toStdString()));
86 *(boolarg->second.first) =
true;
89 intarguments_t::iterator intarg(
_intargs.find(argument->toStdString()));
93 if (argument == argumentList.constEnd())
95 *(intarg->second.first) = argument->toInt();
98 stringarguments_t::iterator stringarg(
_stringargs.find(argument->toStdString()));
102 if (argument == argumentList.constEnd())
104 *(stringarg->second.first) = argument->toStdString();
108 std::cout <<
"CommandlineArgumentParser(): parameter '" << argument->toStdString()
109 <<
"' is unknown. Possible values for this version of the program are: "
122 void add(
const std::string &sw,
const std::string& desc,
bool &val)
133 void add(
const std::string &sw,
const std::string& desc, std::string &val)
144 void add(
const std::string &sw,
const std::string& desc,
int &val)
146 _intargs[sw] = make_pair(&val, desc);
void add(const std::string &sw, const std::string &desc, std::string &val)
add a switch to the string container
void usage()
output which commandline parameters are available
std::map< std::string, std::pair< int *, std::string > > intarguments_t
a container type for switches
stringarguments_t _stringargs
container for the string arguments
switches_t _switches
container for the switches
void add(const std::string &sw, const std::string &desc, bool &val)
add a switch to the switches container
void add(const std::string &sw, const std::string &desc, int &val)
add a switch to the int container
command line argument parser
intarguments_t _intargs
container for the int arguments
std::map< std::string, std::pair< std::string *, std::string > > stringarguments_t
a container type for switches
void operator()(const QStringList &argumentList)
operator to parse the argumetns
std::map< std::string, std::pair< bool *, std::string > > switches_t
a container type for switches