cam: options: Add an array data type to OptionValue
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 <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
af45435014
commit
2a608965f8
2 changed files with 29 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
* options.cpp - cam - Options parsing
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <getopt.h>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
@ -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<OptionValue>() const
|
||||
{
|
||||
return toArray();
|
||||
}
|
||||
|
||||
int OptionValue::toInteger() const
|
||||
{
|
||||
if (type_ != ValueInteger)
|
||||
|
@ -311,6 +325,14 @@ KeyValueParser::Options OptionValue::toKeyValues() const
|
|||
return keyValues_;
|
||||
}
|
||||
|
||||
std::vector<OptionValue> OptionValue::toArray() const
|
||||
{
|
||||
if (type_ != ValueArray)
|
||||
return std::vector<OptionValue>{};
|
||||
|
||||
return array_;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* OptionsParser
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue