From patchwork Sat Feb 29 16:42:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2928 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AAE8462689 for ; Sat, 29 Feb 2020 17:43:25 +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 53144A28 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=1582994605; bh=LvRydhLlauP2ZTU/9LX68g/D+FF/gykag+1WHclmQMs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dv3OlJ9zncULWpuNesasfAsQtmoTzWU3UUmIaCuLwQQBJ6i1GH6qFeR2IiUTWDyuY cM+7r7H6VVXbgIeVidzRwz6ztYCwJ9wzUEpyeOojYoSLAlUlw0us12MmpRrSDo9YRa 0Kt+PFNkhinf7a81QkLoHGDB4/SNxlV4gYCuOiXI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Feb 2020 18:42:33 +0200 Message-Id: <20200229164254.23604-11-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 10/31] libcamera: controls: Return control by value in ControlList::get() 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 The ControlList::get() and ControlValue::get() methods return the control value by reference. This requires the ControlValue class to store the control value in the same form as the one returned by those functions. For compound controls that are soon to be added, the ControlValue class would need to store a span<> instance in addition to the control value itself, which would increase the required storage space. Prepare for support of compound controls by returning from get() by value. As all control values are 8 bytes at most, this doesn't affect efficiency negatively. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/controls.h | 10 ++++------ src/libcamera/controls.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 9d93064c11b2..3b6b231c7c64 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -42,7 +42,7 @@ public: } template - const T &get() const; + T get() const; template void set(const T &value); @@ -212,13 +212,11 @@ public: bool contains(unsigned int id) const; template - const T &get(const Control &ctrl) const + T get(const Control &ctrl) const { const ControlValue *val = find(ctrl.id()); - if (!val) { - static T t(0); - return t; - } + if (!val) + return T{}; return val->get(); } diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index a136ebd2653b..6a0d66fbea8d 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -160,7 +160,7 @@ bool ControlValue::operator==(const ControlValue &other) const */ /** - * \fn template const T &ControlValue::get() const + * \fn template T ControlValue::get() const * \brief Get the control value * * The control value type shall match the type T, otherwise the behaviour is @@ -177,7 +177,7 @@ bool ControlValue::operator==(const ControlValue &other) const #ifndef __DOXYGEN__ template<> -const bool &ControlValue::get() const +bool ControlValue::get() const { ASSERT(type_ == ControlTypeBool); @@ -185,7 +185,7 @@ const bool &ControlValue::get() const } template<> -const int32_t &ControlValue::get() const +int32_t ControlValue::get() const { ASSERT(type_ == ControlTypeInteger32); @@ -193,7 +193,7 @@ const int32_t &ControlValue::get() const } template<> -const int64_t &ControlValue::get() const +int64_t ControlValue::get() const { ASSERT(type_ == ControlTypeInteger64); @@ -720,7 +720,7 @@ bool ControlList::contains(unsigned int id) const } /** - * \fn template const T &ControlList::get(const Control &ctrl) const + * \fn template T ControlList::get(const Control &ctrl) const * \brief Get the value of control \a ctrl * \param[in] ctrl The control *