Changes in / [215:17c644f5f98d:213:56579d12575b] in lemon-main
- Location:
- lemon
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/arg_parser.cc
r214 r210 240 240 } 241 241 242 void ArgParser::show(std::ostream &os,Opts:: const_iterator i) const242 void ArgParser::show(std::ostream &os,Opts::iterator i) 243 243 { 244 244 os << "-" << i->first; 245 245 if(i->second.has_syn) 246 for(Opts:: const_iterator j=_opts.begin();j!=_opts.end();++j)246 for(Opts::iterator j=_opts.begin();j!=_opts.end();++j) 247 247 if(j->second.syn&&j->second.help==i->first) 248 248 os << "|-" << j->first; … … 262 262 } 263 263 264 void ArgParser::show(std::ostream &os,Groups:: const_iterator i) const265 { 266 GroupData::Opts:: const_iterator o=i->second.opts.begin();264 void ArgParser::show(std::ostream &os,Groups::iterator i) 265 { 266 GroupData::Opts::iterator o=i->second.opts.begin(); 267 267 while(o!=i->second.opts.end()) { 268 268 show(os,_opts.find(*o)); … … 272 272 } 273 273 274 void ArgParser::showHelp(Opts:: const_iterator i) const274 void ArgParser::showHelp(Opts::iterator i) 275 275 { 276 276 if(i->second.help.size()==0||i->second.syn) return; … … 280 280 std::cerr << " " << i->second.help << std::endl; 281 281 } 282 void ArgParser::showHelp(std::vector<ArgParser::OtherArg>::const_iterator i) 283 const 282 void ArgParser::showHelp(std::vector<ArgParser::OtherArg>::iterator i) 284 283 { 285 284 if(i->help.size()==0) return; … … 288 287 } 289 288 290 void ArgParser::shortHelp() const289 void ArgParser::shortHelp() 291 290 { 292 291 const unsigned int LINE_LEN=77; … … 294 293 std::cerr << "Usage:\n " << _command_name; 295 294 int pos=_command_name.size()+2; 296 for(Groups:: const_iterator g=_groups.begin();g!=_groups.end();++g) {295 for(Groups::iterator g=_groups.begin();g!=_groups.end();++g) { 297 296 std::ostringstream cstr; 298 297 cstr << ' '; … … 307 306 pos+=cstr.str().size(); 308 307 } 309 for(Opts:: const_iterator i=_opts.begin();i!=_opts.end();++i)308 for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) 310 309 if(!i->second.ingroup&&!i->second.syn) { 311 310 std::ostringstream cstr; … … 321 320 pos+=cstr.str().size(); 322 321 } 323 for(std::vector<OtherArg>:: const_iterator i=_others_help.begin();322 for(std::vector<OtherArg>::iterator i=_others_help.begin(); 324 323 i!=_others_help.end();++i) 325 324 { … … 337 336 } 338 337 339 void ArgParser::showHelp() const338 void ArgParser::showHelp() 340 339 { 341 340 shortHelp(); 342 341 std::cerr << "Where:\n"; 343 for(std::vector<OtherArg>:: const_iterator i=_others_help.begin();342 for(std::vector<OtherArg>::iterator i=_others_help.begin(); 344 343 i!=_others_help.end();++i) showHelp(i); 345 for(Opts:: const_iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i);344 for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i); 346 345 exit(1); 347 346 } 348 347 349 348 350 void ArgParser::unknownOpt(std::string arg) const349 void ArgParser::unknownOpt(std::string arg) 351 350 { 352 351 std::cerr << "\nUnknown option: " << arg << "\n"; … … 356 355 } 357 356 358 void ArgParser::requiresValue(std::string arg, OptType t) const357 void ArgParser::requiresValue(std::string arg, OptType t) 359 358 { 360 359 std::cerr << "Argument '" << arg << "' requires a"; … … 377 376 378 377 379 void ArgParser::checkMandatories() const378 void ArgParser::checkMandatories() 380 379 { 381 380 bool ok=true; 382 for(Opts:: const_iterator i=_opts.begin();i!=_opts.end();++i)381 for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) 383 382 if(i->second.mandatory&&!i->second.set) 384 383 { … … 389 388 showHelp(i); 390 389 } 391 for(Groups:: const_iterator i=_groups.begin();i!=_groups.end();++i)390 for(Groups::iterator i=_groups.begin();i!=_groups.end();++i) 392 391 if(i->second.mandatory||i->second.only_one) 393 392 { 394 393 int set=0; 395 for(GroupData::Opts:: const_iterator o=i->second.opts.begin();394 for(GroupData::Opts::iterator o=i->second.opts.begin(); 396 395 o!=i->second.opts.end();++o) 397 396 if(_opts.find(*o)->second.set) ++set; … … 400 399 ": At least one of the following arguments is mandatory.\n"; 401 400 ok=false; 402 for(GroupData::Opts:: const_iterator o=i->second.opts.begin();401 for(GroupData::Opts::iterator o=i->second.opts.begin(); 403 402 o!=i->second.opts.end();++o) 404 403 showHelp(_opts.find(*o)); … … 408 407 ": At most one of the following arguments can be given.\n"; 409 408 ok=false; 410 for(GroupData::Opts:: const_iterator o=i->second.opts.begin();409 for(GroupData::Opts::iterator o=i->second.opts.begin(); 411 410 o!=i->second.opts.end();++o) 412 411 showHelp(_opts.find(*o)); -
lemon/arg_parser.h
r214 r209 272 272 ///@} 273 273 274 private: 275 void show(std::ostream &os,Opts::const_iterator i) const; 276 void show(std::ostream &os,Groups::const_iterator i) const; 277 void showHelp(Opts::const_iterator i) const; 278 void showHelp(std::vector<OtherArg>::const_iterator i) const; 279 280 void unknownOpt(std::string arg) const; 281 282 void requiresValue(std::string arg, OptType t) const; 283 void checkMandatories() const; 284 285 void shortHelp() const; 286 void showHelp() const; 287 public: 274 void show(std::ostream &os,Opts::iterator i); 275 void show(std::ostream &os,Groups::iterator i); 276 void showHelp(Opts::iterator i); 277 void showHelp(std::vector<OtherArg>::iterator i); 278 void shortHelp(); 279 void showHelp(); 280 281 void unknownOpt(std::string arg); 282 283 void requiresValue(std::string arg, OptType t); 284 void checkMandatories(); 288 285 289 286 ///Start the parsing process … … 297 294 298 295 ///Give back the command name (the 0th argument) 299 const std::string &commandName() const{ return _command_name; }296 const std::string &commandName() { return _command_name; } 300 297 301 298 ///Check if an opion has been given to the command. 302 bool given(std::string op) const303 { 304 Opts:: const_iterator i = _opts.find(op);299 bool given(std::string op) 300 { 301 Opts::iterator i = _opts.find(op); 305 302 return i!=_opts.end()?i->second.set:false; 306 303 } … … 315 312 class RefType 316 313 { 317 constArgParser &_parser;314 ArgParser &_parser; 318 315 std::string _name; 319 316 public: 320 317 ///\e 321 RefType( constArgParser &p,const std::string &n) :_parser(p),_name(n) {}318 RefType(ArgParser &p,const std::string &n) :_parser(p),_name(n) {} 322 319 ///\e 323 320 operator bool() 324 321 { 325 Opts:: const_iterator i = _parser._opts.find(_name);322 Opts::iterator i = _parser._opts.find(_name); 326 323 LEMON_ASSERT(i!=_parser._opts.end(), 327 324 std::string()+"Unkown option: '"+_name+"'"); … … 333 330 operator std::string() 334 331 { 335 Opts:: const_iterator i = _parser._opts.find(_name);332 Opts::iterator i = _parser._opts.find(_name); 336 333 LEMON_ASSERT(i!=_parser._opts.end(), 337 334 std::string()+"Unkown option: '"+_name+"'"); … … 343 340 operator double() 344 341 { 345 Opts:: const_iterator i = _parser._opts.find(_name);342 Opts::iterator i = _parser._opts.find(_name); 346 343 LEMON_ASSERT(i!=_parser._opts.end(), 347 344 std::string()+"Unkown option: '"+_name+"'"); … … 355 352 operator int() 356 353 { 357 Opts:: const_iterator i = _parser._opts.find(_name);354 Opts::iterator i = _parser._opts.find(_name); 358 355 LEMON_ASSERT(i!=_parser._opts.end(), 359 356 std::string()+"Unkown option: '"+_name+"'"); … … 369 366 ///Give back the value of an option. 370 367 ///\sa RefType 371 RefType operator[](const std::string &n) const368 RefType operator[](const std::string &n) 372 369 { 373 370 return RefType(*this, n); … … 378 375 ///Give back a reference to a vector consisting of the program arguments 379 376 ///not starting with a '-' character. 380 const std::vector<std::string> &files() const{ return _file_args; }377 std::vector<std::string> &files() { return _file_args; } 381 378 382 379 };
Note: See TracChangeset
for help on using the changeset viewer.