From 33dd4fab9d39726be4fcbd300a27f2640be1cd6f Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 23 Jul 2021 02:41:16 +0300 Subject: libcamera: base: class: Don't pass Extensible pointer to Private constructor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Extensible and Extensible::Private classes contain pointers to each other. These pointers are initialized in the respective class's constructor, by passing a pointer to the other class to each constructor. This particular construct reduces the flexibility of the Extensible pattern, as the Private class instance has to be allocated and constructed in the members initializer list of the Extensible class's constructor. It is thus impossible to perform any operation on the Private class between its construction and the construction of the Extensible class, or to subclass the Private class without subclassing the Extensible class. To make the design pattern more flexible, don't pass the pointer to the Extensible class to the Private class's constructor, but initialize the pointer manually in the Extensible class's constructor. This requires a const_cast as the o_ member of the Private class is const. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- include/libcamera/base/class.h | 4 +++- include/libcamera/internal/framebuffer.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/libcamera/base/class.h b/include/libcamera/base/class.h index 9c7f0f2e..a5946836 100644 --- a/include/libcamera/base/class.h +++ b/include/libcamera/base/class.h @@ -64,7 +64,7 @@ public: class Private { public: - Private(Extensible *o); + Private(); virtual ~Private(); #ifndef __DOXYGEN__ @@ -82,6 +82,8 @@ public: #endif private: + /* To initialize o_ from Extensible. */ + friend class Extensible; Extensible *const o_; }; diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h index a11e895d..8c187adf 100644 --- a/include/libcamera/internal/framebuffer.h +++ b/include/libcamera/internal/framebuffer.h @@ -52,7 +52,7 @@ class FrameBuffer::Private : public Extensible::Private LIBCAMERA_DECLARE_PUBLIC(FrameBuffer) public: - Private(FrameBuffer *buffer); + Private(); void setRequest(Request *request) { request_ = request; } -- cgit v1.2.1