From patchwork Fri Feb 1 09:29:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 470 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C7B560DB5 for ; Fri, 1 Feb 2019 10:29:27 +0100 (CET) Received: from pendragon.ideasonboard.com (85-76-34-136-nat.elisa-mobile.fi [85.76.34.136]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9A95C41; Fri, 1 Feb 2019 10:29:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549013366; bh=0GOFqniVD6rVflnZ8gc4Mpr6B5x777IskxnLPUiAdCg=; h=From:To:Cc:Subject:Date:From; b=dMkp5d6irwdW3xEaXOgGtHk9ASYaxDTnVD4ERf1RagyKiXVzBNOSDnBPFyTDrXgqW lLA8Gb+kJ4FfT8j4LeyZRQOELtkG5VAOXStTumKS4vO/FYWtRgoR57jxAc1Yaul+1P TRtuqI6qpmGuLy7FOQHcMPr7aEVz+LmTD9NkLxco= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 1 Feb 2019 11:29:19 +0200 Message-Id: <20190201092919.8336-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] cam: options: Add explicit conversion methods 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, 01 Feb 2019 09:29:27 -0000 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 +++++++++++++++++-- src/cam/options.h | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 4c9f3a36d435..eb59376fa459 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(); diff --git a/src/cam/options.h b/src/cam/options.h index e1fd62ecd369..2d3aa50b5051 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -91,6 +91,10 @@ public: operator std::string() const; operator KeyValueParser::Options() const; + int toInteger() const; + std::string toString() const; + KeyValueParser::Options toKeyValues() const; + private: OptionType type_; int integer_;