0
2
0
... | ... |
@@ -25,49 +25,49 @@ |
25 | 25 |
/// \include arg_parser_demo.cc |
26 | 26 |
|
27 | 27 |
#include <lemon/arg_parser.h> |
28 | 28 |
|
29 | 29 |
using namespace lemon; |
30 | 30 |
int main(int argc, const char **argv) |
31 | 31 |
{ |
32 | 32 |
ArgParser ap(argc,argv); |
33 | 33 |
int i; |
34 | 34 |
std::string s; |
35 | 35 |
double d; |
36 | 36 |
bool b,sil; |
37 | 37 |
bool g1,g2,g3; |
38 | 38 |
ap.refOption("n", "An integer input.", i, true) |
39 | 39 |
.refOption("val", "A double input.", d) |
40 | 40 |
.doubleOption("val2", "A double input.", d) |
41 | 41 |
.synonym("vals","val") |
42 | 42 |
.refOption("name", "A string input.", s) |
43 | 43 |
.refOption("f", "A switch.", b) |
44 | 44 |
.refOption("nohelp", "", sil) |
45 | 45 |
.refOption("gra","Choice A",g1) |
46 | 46 |
.refOption("grb","Choice B",g2) |
47 | 47 |
.refOption("grc","Choice C",g3) |
48 | 48 |
.optionGroup("gr","gra") |
49 |
.optionGroup("gr"," |
|
49 |
.optionGroup("gr","grb") |
|
50 | 50 |
.optionGroup("gr","grc") |
51 | 51 |
.mandatoryGroup("gr") |
52 | 52 |
.onlyOneGroup("gr") |
53 | 53 |
.other("infile","The input file.") |
54 | 54 |
.other("..."); |
55 | 55 |
|
56 | 56 |
ap.parse(); |
57 | 57 |
|
58 | 58 |
std::cout << "Parameters of '" << ap.commandName() << "':\n"; |
59 | 59 |
|
60 | 60 |
if(ap.given("n")) std::cout << " Value of -n: " << i << std::endl; |
61 | 61 |
if(ap.given("val")) std::cout << " Value of -val: " << d << std::endl; |
62 | 62 |
if(ap.given("name")) std::cout << " Value of -name: " << s << std::endl; |
63 | 63 |
if(ap.given("f")) std::cout << " -f is given\n"; |
64 | 64 |
if(ap.given("nohelp")) std::cout << " Value of -nohelp: " << sil << std::endl; |
65 | 65 |
if(ap.given("gra")) std::cout << " -gra is given\n"; |
66 | 66 |
if(ap.given("grb")) std::cout << " -grb is given\n"; |
67 | 67 |
if(ap.given("grc")) std::cout << " -grc is given\n"; |
68 | 68 |
|
69 | 69 |
switch(ap.files().size()) { |
70 | 70 |
case 0: |
71 | 71 |
std::cout << " No file argument was given.\n"; |
72 | 72 |
break; |
73 | 73 |
case 1: |
... | ... |
@@ -173,49 +173,48 @@ |
173 | 173 |
_opts[name]=p; |
174 | 174 |
return *this; |
175 | 175 |
} |
176 | 176 |
|
177 | 177 |
ArgParser &ArgParser::funcOption(const std::string &name, |
178 | 178 |
const std::string &help, |
179 | 179 |
void (*func)(void *),void *data) |
180 | 180 |
{ |
181 | 181 |
ParData p; |
182 | 182 |
p.func_p.p=func; |
183 | 183 |
p.func_p.data=data; |
184 | 184 |
p.self_delete=false; |
185 | 185 |
p.help=help; |
186 | 186 |
p.type=FUNC; |
187 | 187 |
p.mandatory=false; |
188 | 188 |
_opts[name]=p; |
189 | 189 |
return *this; |
190 | 190 |
} |
191 | 191 |
|
192 | 192 |
ArgParser &ArgParser::optionGroup(const std::string &group, |
193 | 193 |
const std::string &opt) |
194 | 194 |
{ |
195 | 195 |
Opts::iterator i = _opts.find(opt); |
196 | 196 |
LEMON_ASSERT(i!=_opts.end(), "Unknown option: '"+opt+"'"); |
197 |
if(i==_opts.end()) std::cout << "JAJJJJJJJJ\n"; |
|
198 | 197 |
LEMON_ASSERT(!(i->second.ingroup), |
199 | 198 |
"Option already in option group: '"+opt+"'"); |
200 | 199 |
GroupData &g=_groups[group]; |
201 | 200 |
g.opts.push_back(opt); |
202 | 201 |
i->second.ingroup=true; |
203 | 202 |
return *this; |
204 | 203 |
} |
205 | 204 |
|
206 | 205 |
ArgParser &ArgParser::onlyOneGroup(const std::string &group) |
207 | 206 |
{ |
208 | 207 |
GroupData &g=_groups[group]; |
209 | 208 |
g.only_one=true; |
210 | 209 |
return *this; |
211 | 210 |
} |
212 | 211 |
|
213 | 212 |
ArgParser &ArgParser::synonym(const std::string &syn, |
214 | 213 |
const std::string &opt) |
215 | 214 |
{ |
216 | 215 |
Opts::iterator o = _opts.find(opt); |
217 | 216 |
Opts::iterator s = _opts.find(syn); |
218 | 217 |
LEMON_ASSERT(o!=_opts.end(), "Unknown option: '"+opt+"'"); |
219 | 218 |
LEMON_ASSERT(s==_opts.end(), "Option already used: '"+syn+"'"); |
220 | 219 |
ParData p; |
221 | 220 |
p.help=opt; |
0 comments (0 inline)