From patchwork Sun Jul 11 17:03:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12894 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 3DC2FC3225 for ; Sun, 11 Jul 2021 17:04:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 60C2868521; Sun, 11 Jul 2021 19:04:51 +0200 (CEST) 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="iLHoS+Mw"; 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 120486851B for ; Sun, 11 Jul 2021 19:04:49 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9BA4F255 for ; Sun, 11 Jul 2021 19:04:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626023088; bh=Z7K9NPx1ABJVzh27zZgvw/0OrteuDBPTsu+nL5gx+Ds=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iLHoS+Mwk1fLbB1zR/4BOR5ugr9DkJH2hnFXfU+e5UvU4GsgvIxiwVZ3QryOr+d1B ppJTbJUzmAi/P753XXrOiHlTDh7uBN9cIirN8aoxRAWJfyhBuIvVr6YCEP+Ti/LkyQ fDiOOglorGvUlUuMNvDv2eOk3uYKlj8lk6vPao9s= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 11 Jul 2021 20:03:57 +0300 Message-Id: <20210711170359.300-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210711170359.300-1-laurent.pinchart@ideasonboard.com> References: <20210711170359.300-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/3] libcamera: base: class: Expose Extensible private data to other classes 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" Despite sharing the same name, the private data class created by the Extensible design pattern and the C++ private access specifier have different goals. The latter specifies class members private to the class, while the former stores data not visible to the application. There are use cases for accessing the private data class from other classes inside libcamera. Make this possible by exposing public _d() functions in the class deriving from Extensible. This won't allow access to the private data by applications as the definition of the Private class isn't visible outside of libcamera. The _d() functions need to be defined as template functions to delay their evaluation, as the static_cast() operator in the Extensible::_d() functions needs the Private class to be fully defined. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Hirokazu Honda Reviewed-by: Kieran Bingham --- include/libcamera/base/class.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/libcamera/base/class.h b/include/libcamera/base/class.h index a07dac057331..8212c3d4a5ae 100644 --- a/include/libcamera/base/class.h +++ b/include/libcamera/base/class.h @@ -33,14 +33,24 @@ namespace libcamera { #define LIBCAMERA_DECLARE_PRIVATE() \ public: \ class Private; \ - friend class Private; + friend class Private; \ + template \ + const Private *_d() const \ + { \ + return Extensible::_d(); \ + } \ + template \ + Private *_d() \ + { \ + return Extensible::_d(); \ + } #define LIBCAMERA_DECLARE_PUBLIC(klass) \ friend class klass; \ using Public = klass; #define LIBCAMERA_D_PTR() \ - _d(); + _d(); #define LIBCAMERA_O_PTR() \ _o();