From patchwork Thu Apr 17 11:35:39 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: 23186 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 21B2AC3284 for ; Thu, 17 Apr 2025 11:35:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2DCA268AC0; Thu, 17 Apr 2025 13:35:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OdA3h8Bw"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E6E9C68AC0 for ; Thu, 17 Apr 2025 13:35:43 +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 4AF1311E9 for ; Thu, 17 Apr 2025 13:33:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1744889620; bh=M06HT4DwU9iVSr+nbwhaqzltK+9vyl8VxWXUj7om2PU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OdA3h8Bw6+2yZh9it1vtPALfmdgomf3QTw0ZgC/Ay0ZLxBeTccwUt57REhxZYUtZR Iostv5Fqu49D6aTz1++Ch82fI0czBZgNpa/Kq06bazAjrqVqGHt9hOGdr1l9Uuc0PI TJQ5A5fBWrw3z7tj4GBO6JNpeEgK/oVugHhqKS40= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v1 3/3] libcamera: controls: Implement `swap()` Date: Thu, 17 Apr 2025 13:35:39 +0200 Message-ID: <20250417113539.1137936-3-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250417113539.1137936-1-barnabas.pocze@ideasonboard.com> References: <20250417113539.1137936-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 | 24 ++++++++++++++++++++++++ src/libcamera/controls.cpp | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 86245e7a9..27b314dbc 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -261,6 +261,30 @@ public: void reserve(ControlType type, bool isArray = false, std::size_t numElements = 1); + void swap(ControlValue &other) noexcept + { + { + auto tmp = type_; + type_ = other.type_; + other.type_ = tmp; + } + + std::swap(isArray_, other.isArray_); + + { + auto tmp = numElements_; + numElements_ = other.numElements_; + other.numElements_ = tmp; + } + + 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 885287e71..c1ff60f39 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -411,6 +411,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