From patchwork Sun Jul 4 23:28:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12803 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 6251DC3222 for ; Sun, 4 Jul 2021 23:29:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 800356850E; Mon, 5 Jul 2021 01:29:04 +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="jFUwztlz"; 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 4435960285 for ; Mon, 5 Jul 2021 01:29:02 +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 C7A9C2E4; Mon, 5 Jul 2021 01:29:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1625441342; bh=xFRGxn6j48ULjmSDD4kDRN8p50XOodLPb+s3O8I4/Cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jFUwztlzx5QartCILqv8bi1lpkZ26CDIXBvi6nPWsOyt8kFo4pkQjI4R3LsBnPeUQ 843u+sRD3+1YGkNNIBpONrOgsl2I1nqvmDDrI9mjyOzgQalThmDpY300muV8h82iqt 735qZx8qRmi/kfY1NYibMiXA1HsAg0BooZ2ggZac= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Jul 2021 02:28:15 +0300 Message-Id: <20210704232817.8205-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210704232817.8205-1-laurent.pinchart@ideasonboard.com> References: <20210704232817.8205-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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: Hirokazu Honda --- 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();