From patchwork Mon Apr 21 15:35:55 2025 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: 23194 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 0E1E0C331E for ; Mon, 21 Apr 2025 15:36:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E876268ACA; Mon, 21 Apr 2025 17:36:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cNcDB6T8"; dkim-atps=neutral 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 16EE568AC2 for ; Mon, 21 Apr 2025 17:36:01 +0200 (CEST) Received: from pb-laptop.local (185.221.143.16.nat.pool.zt.hu [185.221.143.16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6AC566D5; Mon, 21 Apr 2025 17:33:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745249634; bh=1cAs7nNJZnmC61fakZ7EkFpphcpojXJw7mR0Xw6X6/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cNcDB6T8bVyj9WGlvefoJhi7GerW7kpzZlK3nH5C7LRM1aT6nDk99g6myEvdLDV7D 2Sls2/nCWfHyKec8wYvPsQIusYk3fU20QvO1MAjo4qF3PGuZVb0r1tnkjWpO1gECzx CKw5UeF1JeCtQHdA3T7BIsmAdc9alFJB3Bmwkc5M= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Jacopo Mondi Subject: [PATCH v2 4/5] libcamera: controls: Implement `swap()` Date: Mon, 21 Apr 2025 17:35:55 +0200 Message-ID: <20250421153556.171192-5-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421153556.171192-1-barnabas.pocze@ideasonboard.com> References: <20250421153556.171192-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 both free and member function `swap()` for `ControlValue`. The general `std::swap()` swaps two values by combining a move construction and two move assignments, but for `ControlValue` a simpler implementation can be provided by just swapping the members. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- include/libcamera/controls.h | 19 +++++++++++++++++++ src/libcamera/controls.cpp | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 866d667c4..62ee5ebd6 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -259,6 +259,25 @@ public: void reserve(ControlType type, bool isArray = false, std::size_t numElements = 1); + void swap(ControlValue &other) noexcept + { + /* `type_` is a bit field, so `std::swap()` cannot be used. */ + { + auto tmp = type_; + type_ = other.type_; + other.type_ = tmp; + } + + std::swap(isArray_, other.isArray_); + std::swap(numElements_, other.numElements_); + std::swap(storage_, other.storage_); + } + + friend void swap(ControlValue &a, ControlValue &b) noexcept + { + a.swap(b); + } + private: ControlType type_ : 8; bool isArray_; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 135e87613..ae54f8c77 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -412,6 +412,21 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen storage_.external = new uint8_t[newSize]; } +/** + * \fn ControlValue::swap(ControlValue &other) noexcept + * \brief Swap two control values + * + * This function swaps the contained value of \a this with that of \a other. + */ + +/** + * \fn ControlValue::swap(ControlValue &a, ControlValue &b) noexcept + * \brief Swap two control values + * + * This function swaps the contained value of \a a with that of \a b. + * \sa ControlValue::swap() + */ + /** * \class ControlId * \brief Control static metadata