Parse the command line, return the index of the first non-option argument. *@throws bad_option if there is a parsing error or unknown option. */
| 62 | *@throws bad_option if there is a parsing error or unknown option. |
| 63 | */ |
| 64 | int parse() { |
| 65 | int arg = 1; |
| 66 | for (; arg < argc_ && argv_[arg][0] == '-'; ++arg) { |
| 67 | opts::iterator i = opts_.begin(); |
| 68 | while (i != opts_.end() && !(*i)->parse(argc_, argv_, arg)) |
| 69 | ++i; |
| 70 | if (i == opts_.end()) |
| 71 | throw bad_option(std::string("unknown option ") + argv_[arg]); |
| 72 | } |
| 73 | if (help_) throw bad_option(""); |
| 74 | return arg; |
| 75 | } |
| 76 | |
| 77 | /** Print a usage message */ |
| 78 | friend std::ostream& operator<<(std::ostream& os, const options& op) { |