diff options
author | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2019-01-28 00:41:50 +0100 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-02-01 11:41:59 +0200 |
commit | 69be770715769bf15fab69bdb650fbcbc0e74db1 (patch) | |
tree | 08919515e9c3f7c2ed79e929e656d5dc2536752a /src | |
parent | c6468e45d1dedb295f6e67b3a49d2d4f4dfeee1c (diff) |
cam: options: Return whether addOption() succeeds or not
To later extend the options handling to cover subparsing of arguments it
will be needed to know if the addition of the option itself was
successful or not. The information is already present in addOption()
this change just makes it available.
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/cam/options.cpp | 11 | ||||
-rw-r--r-- | src/cam/options.h | 2 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/cam/options.cpp b/src/cam/options.cpp index f48bd1fc..c13022ce 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -38,7 +38,7 @@ void OptionsBase<T>::clear() template class OptionsBase<int>; -void OptionsParser::addOption(int opt, const char *help, const char *name, +bool OptionsParser::addOption(int opt, const char *help, const char *name, OptionArgument argument, const char *argumentName) { /* @@ -46,18 +46,19 @@ void OptionsParser::addOption(int opt, const char *help, const char *name, * If an argument is accepted, it must be described by argumentName. */ if (!isalnum(opt) && !name) - return; + return false; if (!help || help[0] == '\0') - return; + return false; if (argument != ArgumentNone && !argumentName) - return; + return false; /* Reject duplicate options. */ if (optionsMap_.find(opt) != optionsMap_.end()) - return; + return false; options_.push_back(Option({ opt, name, argument, argumentName, help })); optionsMap_[opt] = &options_.back(); + return true; } OptionsParser::Options OptionsParser::parse(int argc, char **argv) diff --git a/src/cam/options.h b/src/cam/options.h index 2bf1f160..2272385a 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -49,7 +49,7 @@ public: { }; - void addOption(int opt, const char *help, const char *name = nullptr, + bool addOption(int opt, const char *help, const char *name = nullptr, OptionArgument argument = ArgumentNone, const char *argumentName = nullptr); |