From patchwork Fri Mar 22 01:53:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 781 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 43BAE610B3 for ; Fri, 22 Mar 2019 02:54:09 +0100 (CET) X-Halon-ID: 6069ab50-4c45-11e9-985a-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 6069ab50-4c45-11e9-985a-005056917f90; Fri, 22 Mar 2019 02:54:06 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Mar 2019 02:53:48 +0100 Message-Id: <20190322015349.14934-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322015349.14934-1-niklas.soderlund@ragnatech.se> References: <20190322015349.14934-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 3/4] cam: options: Add parsing of multiple instances of the same option X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Mar 2019 01:54:10 -0000 Add the ability to allow storing multiple instances of the same option. Signed-off-by: Niklas Söderlund --- src/cam/options.cpp | 12 ++++++------ src/cam/options.h | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 7995a9b359764ec7..e9dcd0c39cdc50ce 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -96,7 +96,7 @@ bool OptionsBase::parseValue(const T &opt, const Option &option, break; } - values_[opt] = value; + values_[opt] = option.array ? OptionValue(value, values_[opt]) : value; return true; } @@ -128,7 +128,7 @@ bool KeyValueParser::addOption(const char *name, OptionType type, return false; optionsMap_[name] = Option({ 0, type, name, argument, nullptr, - help, nullptr }); + help, nullptr, false }); return true; } @@ -338,7 +338,7 @@ std::vector OptionValue::toArray() const bool OptionsParser::addOption(int opt, OptionType type, const char *help, const char *name, OptionArgument argument, - const char *argumentName) + const char *argumentName, bool array) { /* * Options must have at least a short or long name, and a text message. @@ -356,16 +356,16 @@ bool OptionsParser::addOption(int opt, OptionType type, const char *help, return false; options_.push_back(Option({ opt, type, name, argument, argumentName, - help, nullptr })); + help, nullptr, array })); optionsMap_[opt] = &options_.back(); return true; } bool OptionsParser::addOption(int opt, KeyValueParser *parser, const char *help, - const char *name) + const char *name, bool array) { if (!addOption(opt, OptionKeyValue, help, name, ArgumentRequired, - "key=value[,key=value,...]")) + "key=value[,key=value,...]", array)) return false; options_.back().keyValueParser = parser; diff --git a/src/cam/options.h b/src/cam/options.h index 789ba36187dd1fc3..922db4650b49117d 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -36,6 +36,7 @@ struct Option { const char *argumentName; const char *help; KeyValueParser *keyValueParser; + bool array; bool hasShortOption() const { return isalnum(opt); } bool hasLongOption() const { return name != nullptr; } @@ -125,9 +126,9 @@ public: bool addOption(int opt, OptionType type, const char *help, const char *name = nullptr, OptionArgument argument = ArgumentNone, - const char *argumentName = nullptr); + const char *argumentName = nullptr, bool array = false); bool addOption(int opt, KeyValueParser *parser, const char *help, - const char *name = nullptr); + const char *name = nullptr, bool array = false); Options parse(int argc, char *argv[]); void usage();