File indexing completed on 2024-05-12 15:56:58
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_PINNED_SHARED_PTR_H 0008 #define KIS_PINNED_SHARED_PTR_H 0009 0010 #include "kis_shared_ptr.h" 0011 0012 /** 0013 * A special type of KisSharedPtr that doesn't support conversion 0014 * into raw pointer. You cannot convert it into raw pointer and cannot 0015 * accidentally delete it. It is done with a hiding KisSharedPtr's 0016 * conversion routine and substituting is with a custom one. 0017 */ 0018 template <typename T> 0019 class KisPinnedSharedPtr : public KisSharedPtr<T> 0020 { 0021 typedef KisSharedPtr<T> BaseClass; 0022 class NotConvertibleToT {~NotConvertibleToT() = delete;}; 0023 typedef NotConvertibleToT* RestrictedBool; 0024 public: 0025 KisPinnedSharedPtr() 0026 { 0027 } 0028 0029 inline KisPinnedSharedPtr(T *other) 0030 : BaseClass(other) 0031 { 0032 } 0033 0034 template <typename X> 0035 inline KisPinnedSharedPtr(const KisWeakSharedPtr<X>& other) 0036 : BaseClass(other) 0037 { 0038 } 0039 0040 0041 template <typename X> 0042 inline KisPinnedSharedPtr(const KisSharedPtr<X> &other) 0043 : BaseClass(other) 0044 { 0045 } 0046 0047 0048 inline operator RestrictedBool() const 0049 { 0050 return this->isNull() ? 0 : reinterpret_cast<NotConvertibleToT*>(1); 0051 } 0052 0053 bool operator!() const 0054 { 0055 return this->isNull(); 0056 } 0057 private: 0058 explicit operator const T*() const; 0059 }; 0060 0061 #include <kis_debug.h> 0062 0063 template <typename T> 0064 inline QDebug operator<<(QDebug dbg, const KisPinnedSharedPtr<T> &ptr) 0065 { 0066 dbg.nospace() << ptr.data(); 0067 return dbg; 0068 } 0069 0070 #endif // KIS_PINNED_SHARED_PTR_H 0071