util/OptionParser: add struct Result

Prepare for option values.
This commit is contained in:
Max Kellermann
2018-01-17 11:00:07 +01:00
parent d588da69e5
commit c45fe3517c
3 changed files with 17 additions and 13 deletions

View File

@@ -45,17 +45,22 @@ public:
remaining_head(const_cast<const char **>(_argv + 1)),
remaining_tail(remaining_head) {}
struct Result {
int index;
constexpr operator bool() noexcept {
return index >= 0;
}
};
/**
* Parses current command line entry.
* Regardless of result, advances current position to the next
* command line entry.
*
* Throws on error.
*
* @return the index if an option was found, -1 if there are
* no more options
*/
int Next();
Result Next();
/**
* Returns the remaining non-option arguments.
@@ -65,7 +70,7 @@ public:
}
private:
unsigned IdentifyOption(const char *s) const;
Result IdentifyOption(const char *s) const;
};
#endif