diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cam/options.cpp | 22 | ||||
-rw-r--r-- | src/cam/options.h | 7 |
2 files changed, 29 insertions, 0 deletions
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 <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 */ diff --git a/src/cam/options.h b/src/cam/options.h index b33a90fc..e0ff50af 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -10,6 +10,7 @@ #include <ctype.h> #include <list> #include <map> +#include <vector> 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 addValue(const OptionValue &value); + ValueType type() const { return type_; } operator int() const; operator std::string() const; operator KeyValueParser::Options() const; + operator std::vector<OptionValue>() const; int toInteger() const; std::string toString() const; KeyValueParser::Options toKeyValues() const; + std::vector<OptionValue> toArray() const; private: ValueType type_; int integer_; std::string string_; KeyValueParser::Options keyValues_; + std::vector<OptionValue> array_; }; class OptionsParser |