From patchwork Sat Feb 29 16:42:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2930 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 61F4F62789 for ; Sat, 29 Feb 2020 17:43:26 +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 01664A28 for ; Sat, 29 Feb 2020 17:43:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1582994606; bh=kjlGLweGKYC3rHM+BnPYckKBUCNnYZR4sEgFzQal6QM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LH1kwMxqJ+C1Gxf5uoG8ZpUyooAH6c5DO+X6Q3gTbOfNziRJvdkDm+XZxGmjGrUUu RDAJKbiz6Xi7EGT43mQKztGl4A7PZwbx8H545zdWtdEAmoVk7pP2MQsVeAgkMhwWwB vUKA6DFLZKcjaGug/B6LAa2zcVLW+A2Eice9OrSs= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Feb 2020 18:42:35 +0200 Message-Id: <20200229164254.23604-13-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> References: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 12/31] libcamera: controls: Move ControlValue get() and set() 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: Sat, 29 Feb 2020 16:43:26 -0000 To avoid defining all specializations of ControlValue::get() and ControlValue::set() manually, move the definition of those functions to controls.h. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/controls.h | 15 ++++++++++-- src/libcamera/controls.cpp | 47 ------------------------------------ 2 files changed, 13 insertions(+), 49 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 429f01b0fd24..39e240438861 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -8,6 +8,7 @@ #ifndef __LIBCAMERA_CONTROLS_H__ #define __LIBCAMERA_CONTROLS_H__ +#include #include #include @@ -70,9 +71,19 @@ public: } template - T get() const; + T get() const + { + assert(type_ == details::control_type>::value); + + return *reinterpret_cast(&bool_); + } + template - void set(const T &value); + void set(const T &value) + { + type_ = details::control_type>::value; + *reinterpret_cast(&bool_) = value; + } private: ControlType type_; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 6a0d66fbea8d..f3d79785e6a8 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -175,53 +175,6 @@ bool ControlValue::operator==(const ControlValue &other) const * \param[in] value The control value */ -#ifndef __DOXYGEN__ -template<> -bool ControlValue::get() const -{ - ASSERT(type_ == ControlTypeBool); - - return bool_; -} - -template<> -int32_t ControlValue::get() const -{ - ASSERT(type_ == ControlTypeInteger32); - - return integer32_; -} - -template<> -int64_t ControlValue::get() const -{ - ASSERT(type_ == ControlTypeInteger64); - - return integer64_; -} - -template<> -void ControlValue::set(const bool &value) -{ - type_ = ControlTypeBool; - bool_ = value; -} - -template<> -void ControlValue::set(const int32_t &value) -{ - type_ = ControlTypeInteger32; - integer32_ = value; -} - -template<> -void ControlValue::set(const int64_t &value) -{ - type_ = ControlTypeInteger64; - integer64_ = value; -} -#endif /* __DOXYGEN__ */ - /** * \class ControlId * \brief Control static metadata