From patchwork Fri Mar 22 01:53:47 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: 780 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BECB36110A for ; Fri, 22 Mar 2019 02:54:07 +0100 (CET) X-Halon-ID: 600d7062-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 600d7062-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:47 +0100 Message-Id: <20190322015349.14934-3-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 2/4] 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: Fri, 22 Mar 2019 01:54:08 -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 a more complex constructor us needed which can combine already stored instances of an option with new ones. Signed-off-by: Niklas Söderlund --- src/cam/options.cpp | 21 +++++++++++++++++++++ src/cam/options.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 497833397d894f82..7995a9b359764ec7 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -272,6 +272,14 @@ OptionValue::OptionValue(const KeyValueParser::Options &value) { } +OptionValue::OptionValue(const OptionValue &value, + const std::vector &array) + : type_(ValueArray) +{ + array_ = array; + array_.push_back(value); +} + OptionValue::operator int() const { return toInteger(); @@ -287,6 +295,11 @@ OptionValue::operator KeyValueParser::Options() const return toKeyValues(); } +OptionValue::operator std::vector() const +{ + return toArray(); +} + int OptionValue::toInteger() const { if (type_ != ValueInteger) @@ -311,6 +324,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..789ba36187dd1fc3 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(); @@ -91,22 +93,26 @@ public: OptionValue(const char *value); OptionValue(const std::string &value); OptionValue(const KeyValueParser::Options &value); + OptionValue(const OptionValue &value, const std::vector &array); 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