// Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef PASSOWNPTR_H #define PASSOWNPTR_H #include template class PassOwnPtr; template PassOwnPtr adoptPtr(PtrType*); template struct OwnPtr : public QScopedPointer { OwnPtr() {} OwnPtr(const PassOwnPtr &ptr) : QScopedPointer(ptr.leakRef()) {} OwnPtr(const OwnPtr& other) : QScopedPointer(const_cast &>(other).take()) {} OwnPtr& operator=(const OwnPtr& other) { this->reset(const_cast &>(other).take()); return *this; } T* get() const { return this->data(); } PassOwnPtr release() { return adoptPtr(this->take()); } }; template class PassOwnPtr { public: PassOwnPtr() {} PassOwnPtr(T* ptr) : m_ptr(ptr) { } PassOwnPtr(const PassOwnPtr& other) : m_ptr(other.leakRef()) { } PassOwnPtr(const OwnPtr& other) : m_ptr(other.take()) { } ~PassOwnPtr() { } T* operator->() const { return m_ptr.data(); } T* leakRef() const { return m_ptr.take(); } private: template friend PassOwnPtr adoptPtr(PtrType*); PassOwnPtr& operator=(const PassOwnPtr& t); mutable QScopedPointer m_ptr; }; template PassOwnPtr adoptPtr(T* ptr) { PassOwnPtr result; result.m_ptr.reset(ptr); return result; } #endif // PASSOWNPTR_H