From patchwork Sat Oct 12 18:43:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2165 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8F7BB61563 for ; Sat, 12 Oct 2019 20:44:18 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B473B33A for ; Sat, 12 Oct 2019 20:44:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1570905858; bh=w8a1lB+CzP86yPSLqH/maQu2rcKF90DtfQQx6a9ulnA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cRnxiTMZoG1jr/rVa30G1Fw74FvdlSSacrechawZjfPspWU6FwoZBeEqVZ/kMRXX5 l+k5oF26OSU9bqhsu2lmTkgCmSxgyGj4J0My7Ts7m9ZQhC8mbyqaf8CWrAFt0EMwYo p0HWGWuLf3nphhHY869HOMGjmrjF4ddDRGlJiXeE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Oct 2019 21:43:57 +0300 Message-Id: <20191012184407.31684-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191012184407.31684-1-laurent.pinchart@ideasonboard.com> References: <20191012184407.31684-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/14] libcamera: controls: Add comparison operators for ControlValue X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Oct 2019 18:44:18 -0000 Add equality and non equality comparison operators for the ControlValue class. This simplifies code that deals with control values. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/controls.h | 6 ++++++ src/libcamera/controls.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index d8acd800b143..342251c21018 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -40,6 +40,12 @@ public: std::string toString() const; + bool operator==(const ControlValue &other) const; + bool operator!=(const ControlValue &other) const + { + return !(*this == other); + } + private: ControlType type_; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 70c1af481af2..bfab177fc508 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -194,6 +194,33 @@ std::string ControlValue::toString() const return ""; } +/** + * \brief Compare ControlValue instances for equality + * \return True if the values have identical types and values, false otherwise + */ +bool ControlValue::operator==(const ControlValue &other) const +{ + if (type_ != other.type_) + return false; + + switch (type_) { + case ControlTypeBool: + return bool_ == other.bool_; + case ControlTypeInteger32: + return integer32_ == other.integer32_; + case ControlTypeInteger64: + return integer64_ == other.integer64_; + default: + return false; + } +} + +/** + * \fn bool ControlValue::operator!=() + * \brief Compare ControlValue instances for non equality + * \return False if the values have identical types and values, true otherwise + */ + /** * \class ControlId * \brief Control static metadata