From patchwork Mon Mar 25 23:47:34 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: 793 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D7CBB6110E for ; Tue, 26 Mar 2019 00:47:46 +0100 (CET) X-Halon-ID: 62099073-4f58-11e9-846a-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 62099073-4f58-11e9-846a-005056917a89; Tue, 26 Mar 2019 00:47:43 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Mar 2019 00:47:34 +0100 Message-Id: <20190325234736.12533-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190325234736.12533-1-niklas.soderlund@ragnatech.se> References: <20190325234736.12533-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] cam: options: Create separate enum for OptionValue types 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: Mon, 25 Mar 2019 23:47:47 -0000 In preparation for support of multiple instances of the same option, create a separate enum for the OptionValue types as it will diverge from enum OptionType. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/options.cpp | 16 ++++++++-------- src/cam/options.h | 11 +++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 655aa36bb9c93b85..497833397d894f82 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -248,27 +248,27 @@ void KeyValueParser::usage(int indent) */ OptionValue::OptionValue() - : type_(OptionNone) + : type_(ValueNone) { } OptionValue::OptionValue(int value) - : type_(OptionInteger), integer_(value) + : type_(ValueInteger), integer_(value) { } OptionValue::OptionValue(const char *value) - : type_(OptionString), string_(value) + : type_(ValueString), string_(value) { } OptionValue::OptionValue(const std::string &value) - : type_(OptionString), string_(value) + : type_(ValueString), string_(value) { } OptionValue::OptionValue(const KeyValueParser::Options &value) - : type_(OptionKeyValue), keyValues_(value) + : type_(ValueKeyValue), keyValues_(value) { } @@ -289,7 +289,7 @@ OptionValue::operator KeyValueParser::Options() const int OptionValue::toInteger() const { - if (type_ != OptionInteger) + if (type_ != ValueInteger) return 0; return integer_; @@ -297,7 +297,7 @@ int OptionValue::toInteger() const std::string OptionValue::toString() const { - if (type_ != OptionString) + if (type_ != ValueString) return std::string(); return string_; @@ -305,7 +305,7 @@ std::string OptionValue::toString() const KeyValueParser::Options OptionValue::toKeyValues() const { - if (type_ != OptionKeyValue) + if (type_ != ValueKeyValue) return KeyValueParser::Options(); return keyValues_; diff --git a/src/cam/options.h b/src/cam/options.h index 745f4a4a3a433f9e..b33a90fc6058febf 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -79,13 +79,20 @@ private: class OptionValue { public: + enum ValueType { + ValueNone, + ValueInteger, + ValueString, + ValueKeyValue, + }; + OptionValue(); OptionValue(int value); OptionValue(const char *value); OptionValue(const std::string &value); OptionValue(const KeyValueParser::Options &value); - OptionType type() const { return type_; } + ValueType type() const { return type_; } operator int() const; operator std::string() const; @@ -96,7 +103,7 @@ public: KeyValueParser::Options toKeyValues() const; private: - OptionType type_; + ValueType type_; int integer_; std::string string_; KeyValueParser::Options keyValues_; From patchwork Mon Mar 25 23:47:35 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: 791 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D03D6600FD for ; Tue, 26 Mar 2019 00:47:46 +0100 (CET) X-Halon-ID: 628f838a-4f58-11e9-846a-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 628f838a-4f58-11e9-846a-005056917a89; Tue, 26 Mar 2019 00:47:44 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Mar 2019 00:47:35 +0100 Message-Id: <20190325234736.12533-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190325234736.12533-1-niklas.soderlund@ragnatech.se> References: <20190325234736.12533-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] cam: options: Add an array data type to OptionValue 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: Mon, 25 Mar 2019 23:47:47 -0000 To allow specifying the same argument option multiple times a new type of OptionValue is needed. As parsing of options is an iterative process there is a need to append options as they are parsed so instead of setting values using the constructor a new add() method is used. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/options.cpp | 19 +++++++++++++++++++ src/cam/options.h | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 497833397d894f82..0dec154815d3cad5 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -272,6 +272,12 @@ OptionValue::OptionValue(const KeyValueParser::Options &value) { } +void OptionValue::add(const OptionValue &value) +{ + type_ = ValueArray; + array_.push_back(value); +} + OptionValue::operator int() const { return toInteger(); @@ -287,6 +293,11 @@ OptionValue::operator KeyValueParser::Options() const return toKeyValues(); } +OptionValue::operator std::vector() const +{ + return toArray(); +} + int OptionValue::toInteger() const { if (type_ != ValueInteger) @@ -311,6 +322,14 @@ KeyValueParser::Options OptionValue::toKeyValues() const return keyValues_; } +std::vector OptionValue::toArray() const +{ + if (type_ != ValueArray) + return std::vector{}; + + return array_; +} + /* ----------------------------------------------------------------------------- * OptionsParser */ diff --git a/src/cam/options.h b/src/cam/options.h index b33a90fc6058febf..6a887416c0070c41 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -10,6 +10,7 @@ #include #include #include +#include class KeyValueParser; class OptionValue; @@ -84,6 +85,7 @@ public: ValueInteger, ValueString, ValueKeyValue, + ValueArray, }; OptionValue(); @@ -92,21 +94,26 @@ public: OptionValue(const std::string &value); OptionValue(const KeyValueParser::Options &value); + void add(const OptionValue &value); + ValueType type() const { return type_; } operator int() const; operator std::string() const; operator KeyValueParser::Options() const; + operator std::vector() const; int toInteger() const; std::string toString() const; KeyValueParser::Options toKeyValues() const; + std::vector toArray() const; private: ValueType type_; int integer_; std::string string_; KeyValueParser::Options keyValues_; + std::vector array_; }; class OptionsParser From patchwork Mon Mar 25 23:47:36 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: 794 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E4CF061111 for ; Tue, 26 Mar 2019 00:47:46 +0100 (CET) X-Halon-ID: 62f44f80-4f58-11e9-846a-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 62f44f80-4f58-11e9-846a-005056917a89; Tue, 26 Mar 2019 00:47:45 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Mar 2019 00:47:36 +0100 Message-Id: <20190325234736.12533-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190325234736.12533-1-niklas.soderlund@ragnatech.se> References: <20190325234736.12533-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] cam: options: Add support for repeatable options 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: Mon, 25 Mar 2019 23:47:47 -0000 Add a flag to indicate if an option can be repeatable. If an option is repeatable it must be accessed thru the array interface, even if it's only specified once by the user. Also update the usage generator to indicate that tan option is repeatable. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/options.cpp | 21 +++++++++++++++------ src/cam/options.h | 5 +++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 0dec154815d3cad5..0fdde9d84ba0de0e 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -96,7 +96,11 @@ bool OptionsBase::parseValue(const T &opt, const Option &option, break; } - values_[opt] = value; + if (option.array) + values_[opt].add(value); + else + values_[opt] = value; + return true; } @@ -128,7 +132,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; } @@ -336,7 +340,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. @@ -354,16 +358,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; @@ -461,6 +465,8 @@ void OptionsParser::usage() length += 1 + strlen(option.argumentName); if (option.argument == ArgumentOptional) length += 2; + if (option.array) + length += 4; if (length > indent) indent = length; @@ -494,6 +500,9 @@ void OptionsParser::usage() argument += "]"; } + if (option.array) + argument += " ..."; + std::cerr << std::setw(indent) << std::left << argument; for (const char *help = option.help, *end = help; end; ) { diff --git a/src/cam/options.h b/src/cam/options.h index 6a887416c0070c41..1dac15ea90f2ffd2 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; } @@ -126,9 +127,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();