From 3fd5ade00c5da727184c6c5aa728d4ee27bb6ac2 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 1 Feb 2019 11:26:50 +0200 Subject: cam: options: Add explicit conversion methods to OptionValue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The OptionValue class defines operators to convert the variant to all the supported option types. As a convenience, add explicit methods to perform the same operations, avoiding the need to write long static_cast<>() statements in the caller. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/cam/options.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/cam/options.cpp') diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 4c9f3a36..eb59376f 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -273,6 +273,21 @@ OptionValue::OptionValue(const KeyValueParser::Options &value) } OptionValue::operator int() const +{ + return toInteger(); +} + +OptionValue::operator std::string() const +{ + return toString(); +} + +OptionValue::operator KeyValueParser::Options() const +{ + return toKeyValues(); +} + +int OptionValue::toInteger() const { if (type_ != OptionInteger) return 0; @@ -280,7 +295,7 @@ OptionValue::operator int() const return integer_; } -OptionValue::operator std::string() const +std::string OptionValue::toString() const { if (type_ != OptionString) return std::string(); @@ -288,7 +303,7 @@ OptionValue::operator std::string() const return string_; } -OptionValue::operator KeyValueParser::Options() const +KeyValueParser::Options OptionValue::toKeyValues() const { if (type_ != OptionKeyValue) return KeyValueParser::Options(); -- cgit v1.2.1