From patchwork Thu Sep 3 09:18:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 28182 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 5DCA2C334A for ; Thu, 3 Sep 2026 09:18:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2063E685D8; Thu, 3 Sep 2026 11:18:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Y/g3TYzp"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F1377685D7 for ; Thu, 3 Sep 2026 11:18:47 +0200 (CEST) Received: from pb-laptop.local (185.221.143.32.nat.pool.zt.hu [185.221.143.32]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CB472233B; Thu, 3 Sep 2026 11:17:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1788427036; bh=5E4PqNZs5SlUYdqcDT1B5Kk7GujaqPPo61Waw0gPMU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y/g3TYzpNvvY66wICqlwaI7XMJeKsGrMN58VSM72DO7BqA/1IrBY5Ngb5OXe3G6YS RsGN1LYmT9icGPb89Q+VsRfVTvkzKqS/5KDoL/SIr+klqkyxG8wE+7RcGCp5rYf3OK zju7EYebKulsoqxYmt67AR98F9AJPiKxo0cHHcRg= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Jacopo Mondi , Laurent Pinchart Subject: [PATCH v3 3/5] libcamera: controls: Implement move ctor/assignment Date: Thu, 3 Sep 2026 11:18:41 +0200 Message-ID: <20260903091843.85548-4-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260903091843.85548-1-barnabas.pocze@ideasonboard.com> References: <20260903091843.85548-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implement a move constructor and move assignment operator for `ControlValue`. The `ControlValue` type already has an "empty" state that is used when creating a default constructed `ControlValue`, so have the moved-from instance return to that state after move construction/assignment. This is useful, for example, for `std::vector` as most implementations will use the copy constructor when reallocating if no nothrow move constructor is available. Having a nothrow move constructor avoids the extra copies. It is also useful when using temporaries of `ControlValue` with other containers such as `std::optional`, and it also makes `ControlInfo` "cheaply" move constructible/assignable. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/controls.h | 23 +++++++++++++++++++++++ src/libcamera/controls.cpp | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index e4d5d13a2c..aef17abe07 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -173,6 +174,28 @@ public: ControlValue(const ControlValue &other); ControlValue &operator=(const ControlValue &other); + ControlValue(ControlValue &&other) noexcept + : type_(std::exchange(other.type_, ControlTypeNone)), + isArray_(std::exchange(other.isArray_, false)), + numElements_(std::exchange(other.numElements_, 0)), + storage_(std::exchange(other.storage_, {})) + { + } + + ControlValue &operator=(ControlValue &&other) noexcept + { + if (this != &other) { + release(); + + type_ = std::exchange(other.type_, ControlTypeNone); + isArray_ = std::exchange(other.isArray_, false); + numElements_ = std::exchange(other.numElements_, 0); + storage_ = std::exchange(other.storage_, {}); + } + + return *this; + } + ControlType type() const { return type_; } bool isNone() const { return type_ == ControlTypeNone; } bool isArray() const { return isArray_; } diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index e9d4e7eb47..588b609373 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -156,6 +156,24 @@ ControlValue &ControlValue::operator=(const ControlValue &other) return *this; } +/** + * \fn ControlValue::ControlValue(ControlValue &&other) noexcept + * \brief Move constructor for ControlValue + * \param[in] other The ControlValue object to move from + * + * Move constructs a ControlValue instance from \a other. + * After this operation \a other will be in the same state + * as a default constructed ControlValue instance. + */ + +/** + * \fn ControlValue &ControlValue::operator=(ControlValue &&other) noexcept + * \brief Move assignment operator for ControlValue + * \param[in] other The ControlValue object to move from + * + * \sa ControlValue::ControlValue(ControlValue &&other) + */ + /** * \fn ControlValue::type() * \brief Retrieve the data type of the value