From patchwork Fri Mar 6 15:59:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2984 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 DF146627C3 for ; Fri, 6 Mar 2020 17:00:20 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 77573312 for ; Fri, 6 Mar 2020 17:00:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1583510420; bh=DsTpPs4eXqU2lxxJeXEvAe1oDTBrGAdfoK9opzfPu6k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tfrbjH3tOa07d19gfu+mTXesZ2DDw14MMNH5mqc3NwTSJLvmzcoJXj7raCD8RM9xa Dh0bqKQ6yHAQFbIE5i2s+6lADSxZvkrDszIK9AbyoAfnKwe4FqS5vZ4C/wzgXfyjwa 5ZX8UpWB0i1+8cXGa6jzjwUPIMKchVUQ7xSSGDaU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Mar 2020 17:59:43 +0200 Message-Id: <20200306160002.30549-14-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200306160002.30549-1-laurent.pinchart@ideasonboard.com> References: <20200306160002.30549-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 13/32] libcamera: controls: Move ControlValue constructor to controls.h 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: Fri, 06 Mar 2020 16:00:21 -0000 To avoid defining all specializations of the ControlValue constructor manually, move the definition of those functions to controls.h and turn them into a single template function. The default constructor is still kept in controls.cpp. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/controls.h | 10 +++++++--- src/libcamera/controls.cpp | 27 +++------------------------ 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 39e240438861..dfe69916cd64 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -55,9 +55,13 @@ class ControlValue { public: ControlValue(); - ControlValue(bool value); - ControlValue(int32_t value); - ControlValue(int64_t value); + + template + ControlValue(T value) + : type_(details::control_type>::value) + { + *reinterpret_cast(&bool_) = value; + } ControlType type() const { return type_; } bool isNone() const { return type_ == ControlTypeNone; } diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index f3d79785e6a8..5cc8ce2199d0 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -74,31 +74,10 @@ ControlValue::ControlValue() } /** - * \brief Construct a Boolean ControlValue - * \param[in] value Boolean value to store + * \fn template T ControlValue::ControlValue(T value) + * \brief Construct a ControlValue of type T + * \param[in] value Initial value */ -ControlValue::ControlValue(bool value) - : type_(ControlTypeBool), bool_(value) -{ -} - -/** - * \brief Construct an integer ControlValue - * \param[in] value Integer value to store - */ -ControlValue::ControlValue(int32_t value) - : type_(ControlTypeInteger32), integer32_(value) -{ -} - -/** - * \brief Construct a 64 bit integer ControlValue - * \param[in] value Integer value to store - */ -ControlValue::ControlValue(int64_t value) - : type_(ControlTypeInteger64), integer64_(value) -{ -} /** * \fn ControlValue::type()