From patchwork Fri Feb 12 13:30:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 11262 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 67E9EBD160 for ; Fri, 12 Feb 2021 13:31:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EC59463792; Fri, 12 Feb 2021 14:31:02 +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="OLZL2ECc"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EB35E63772 for ; Fri, 12 Feb 2021 14:31:00 +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 856101253; Fri, 12 Feb 2021 14:31:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1613136660; bh=zOj4Fv/7FwvtQV1PpQ4W0SUBsm9q+9nWisXGaTGQCX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OLZL2ECcwdfhdZxIYExWP7+Hhy/6KYaYIkm+UKWq0K3vrlJt2WWp6ELvJ/jZhaC8f Zv+nebJAlovtKLeay8ushoN35CcULhbDQtun3cA6A6iMIl4VU8DFqjenmYN6Qs+T8h fg41fedjGAKfGtFAX1oxqLYe2vo6YRMKELSECmp8= From: Kieran Bingham To: libcamera devel Date: Fri, 12 Feb 2021 13:30:51 +0000 Message-Id: <20210212133056.873230-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210212133056.873230-1-kieran.bingham@ideasonboard.com> References: <20210212133056.873230-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/7] 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 Reviewed-by: Laurent Pinchart --- include/libcamera/class.h | 18 +++++++++++++ src/libcamera/class.cpp | 57 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/include/libcamera/class.h b/include/libcamera/class.h index cb278e58204a..920624d8e726 100644 --- a/include/libcamera/class.h +++ b/include/libcamera/class.h @@ -11,6 +11,24 @@ namespace libcamera { +#ifndef __DOXYGEN__ +#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) +#else +#define LIBCAMERA_DISABLE_COPY(klass) +#define LIBCAMERA_DISABLE_MOVE(klass) +#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass) +#endif + #ifndef __DOXYGEN__ #define LIBCAMERA_DECLARE_PRIVATE(klass) \ public: \ diff --git a/src/libcamera/class.cpp b/src/libcamera/class.cpp index ce230be91e61..c1db14197b4e 100644 --- a/src/libcamera/class.cpp +++ b/src/libcamera/class.cpp @@ -17,6 +17,63 @@ namespace libcamera { +/** + * \def LIBCAMERA_DISABLE_COPY + * \brief Disable copy construction and assignment of the \a klass + * \param klass The name of the class + * + * Example usage: + * \code{.cpp} + * class NonCopyable + * { + * public: + * NonCopyable(); + * ... + * + * private: + * LIBCAMERA_DISABLE_COPY(NonCopyable) + * }; + * \endcode + */ + +/** + * \def LIBCAMERA_DISABLE_MOVE + * \brief Disable move construction and assignment of the \a klass + * \param klass The name of the class + * + * Example usage: + * \code{.cpp} + * class NonMoveable + * { + * public: + * NonMoveable(); + * ... + * + * private: + * LIBCAMERA_DISABLE_MOVE(NonMoveable) + * }; + * \endcode + */ + +/** + * \def LIBCAMERA_DISABLE_COPY_AND_MOVE + * \brief Disable copy and move construction and assignment of the \a klass +* \param klass The name of the class + * + * Example usage: + * \code{.cpp} + * class NonCopyableNonMoveable + * { + * public: + * NonCopyableNonMoveable(); + * ... + * + * private: + * LIBCAMERA_DISABLE_COPY_AND_MOVE(NonCopyableNonMoveable) + * }; + * \endcode + */ + /** * \def LIBCAMERA_DECLARE_PRIVATE * \brief Declare private data for a public class