File indexing completed on 2024-05-12 15:58:40

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KIS_RESTRICTED_SHARED_PTR
0008 #define KIS_RESTRICTED_SHARED_PTR
0009 
0010 #include "kis_shared_ptr.h"
0011 #include "kis_pinned_shared_ptr.h"
0012 
0013 /**
0014  * A special type of KisSharedPtr that forbids creation of a shared
0015  * pointer from raw pointer. This is needed to avoid cases when we
0016  * pass 'this' into a shared pointer and end up in potentially
0017  * dangerous state. See KisUniformPaintOpProperty for an example.
0018  */
0019 template <typename T>
0020 class KisRestrictedSharedPtr : public KisSharedPtr<T>
0021 {
0022     typedef KisSharedPtr<T> BaseClass;
0023 public:
0024     KisRestrictedSharedPtr()
0025     {
0026     }
0027 
0028     template <typename X>
0029     inline KisRestrictedSharedPtr(const KisWeakSharedPtr<X>& other)
0030         : BaseClass(other)
0031     {
0032     }
0033 
0034 
0035     template <typename X>
0036     inline KisRestrictedSharedPtr(const KisSharedPtr<X> &other)
0037         : BaseClass(other)
0038     {
0039     }
0040 
0041     template <typename X>
0042     inline KisRestrictedSharedPtr(const KisRestrictedSharedPtr<X> &other)
0043         : BaseClass(other)
0044     {
0045     }
0046 
0047     template <typename X>
0048     inline KisRestrictedSharedPtr(const KisPinnedSharedPtr<X> &other)
0049         : BaseClass(other)
0050     {
0051     }
0052 
0053 
0054 private:
0055     template <typename X>
0056     KisRestrictedSharedPtr(X other);
0057 };
0058 
0059 #endif // KIS_RESTRICTED_SHARED_PTR
0060