From patchwork Thu Feb 11 13:34:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11240 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 AD96EBD162 for ; Thu, 11 Feb 2021 13:34:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C86DC63733; Thu, 11 Feb 2021 14:34:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jgioIMq0"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 832C4601B5 for ; Thu, 11 Feb 2021 14:34:48 +0100 (CET) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2196999D; Thu, 11 Feb 2021 14:34:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1613050488; bh=vaNO8wpv7TTP0Ei1xXlxB2UStxTDudgc0PVEQp5TYdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jgioIMq0x6FJkEyT9DN+ocILDhDgVQc9U4o7nliJMxcIJaxMykN46WTQPY6mLFdKF 0Xc2SLFT73bcHsGbOUOtSWWtQZ7jz/TctjsPj2HFr6blIvwSbGiXk/W+BRVwTwjyGR YGzH0th+JokEjC5Hu9nPjeUIXqBtVXmWv9cAyR7A= From: Kieran Bingham To: libcamera devel Date: Thu, 11 Feb 2021 13:34:40 +0000 Message-Id: <20210211133444.764808-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210211133444.764808-1-kieran.bingham@ideasonboard.com> References: <20210211133444.764808-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/6] libcamera: class: Provide move and copy disablers 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" It can be difficult to correctly parse the syntax for copy/move and the associated assignment operators. Provide helpers as syntactic sugar to facilitate disabling either the copy constructor, and copy assignment operator, and the move constructor and move assignment operator in a way which is explicit and clear. Signed-off-by: Kieran Bingham --- include/libcamera/class.h | 12 ++++++++++++ src/libcamera/class.cpp | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/libcamera/class.h b/include/libcamera/class.h index 2d9b7ebfdb08..5cd31d1b9f37 100644 --- a/include/libcamera/class.h +++ b/include/libcamera/class.h @@ -11,6 +11,18 @@ namespace libcamera { +#define LIBCAMERA_DISABLE_COPY(klass) \ + klass(const klass &) = delete; \ + klass &operator=(const klass &) = delete + +#define LIBCAMERA_DISABLE_MOVE(klass) \ + klass(klass &&) = delete; \ + klass &operator=(klass &&) = delete + +#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass) \ + LIBCAMERA_DISABLE_COPY(klass); \ + LIBCAMERA_DISABLE_MOVE(klass) + #ifndef __DOXYGEN__ #define LIBCAMERA_DECLARE_PRIVATE(klass) \ public: \ diff --git a/src/libcamera/class.cpp b/src/libcamera/class.cpp index 8a608edb369b..b081d05ec3ac 100644 --- a/src/libcamera/class.cpp +++ b/src/libcamera/class.cpp @@ -17,6 +17,24 @@ namespace libcamera { +/** + * \def LIBCAMERA_DISABLE_COPY + * \brief Delete the copy constructor and assignment operator. + * \param klass The identifier of the class to modify + */ + +/** + * \def LIBCAMERA_DISABLE_MOVE + * \brief Delete the move construtor and assignment operator. + * \param klass The identifier of the class to modify + */ + +/** + * \def LIBCAMERA_DISABLE_COPY_AND_MOVE + * \brief Delete all copy and move constructors, and assignment operators. + * \param klass The identifier of the class to modify + */ + /** * \def LIBCAMERA_DECLARE_PRIVATE * \brief Declare private data for a public class