From 2a608965f8cb4bb93522e9b22af840c688ec12a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Fri, 22 Mar 2019 02:11:22 +0100 Subject: cam: options: Add an array data type to OptionValue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 addValue() method is used. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/options.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/cam/options.cpp') diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 49783339..556e7623 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -5,6 +5,7 @@ * options.cpp - cam - Options parsing */ +#include #include #include #include @@ -272,6 +273,14 @@ OptionValue::OptionValue(const KeyValueParser::Options &value) { } +void OptionValue::addValue(const OptionValue &value) +{ + assert(type_ == ValueNone || type_ == ValueArray); + + type_ = ValueArray; + array_.push_back(value); +} + OptionValue::operator int() const { return toInteger(); @@ -287,6 +296,11 @@ OptionValue::operator KeyValueParser::Options() const return toKeyValues(); } +OptionValue::operator std::vector() const +{ + return toArray(); +} + int OptionValue::toInteger() const { if (type_ != ValueInteger) @@ -311,6 +325,14 @@ KeyValueParser::Options OptionValue::toKeyValues() const return keyValues_; } +std::vector OptionValue::toArray() const +{ + if (type_ != ValueArray) + return std::vector{}; + + return array_; +} + /* ----------------------------------------------------------------------------- * OptionsParser */ -- cgit v1.2.1