// Copyright (C) 2020 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 QLAZILYALLOCATED_P_H #define QLAZILYALLOCATED_P_H // // W A R N I N G // ------------- // // This file is not part of the Qt API. It exists purely as an // implementation detail. This header file may change from version to // version without notice, or even be removed. // // We mean it. // #include #include QT_BEGIN_NAMESPACE template::TagType> class QLazilyAllocated { public: inline QLazilyAllocated(); inline ~QLazilyAllocated(); inline bool isAllocated() const; inline T *operator->() const; inline T &value(); inline const T &value() const; inline Tag tag() const; inline void setTag(Tag t); private: mutable QTaggedPointer d; }; template QLazilyAllocated::QLazilyAllocated() { } template QLazilyAllocated::~QLazilyAllocated() { delete d.data(); } template bool QLazilyAllocated::isAllocated() const { return !d.isNull(); } template T &QLazilyAllocated::value() { if (d.isNull()) d = new T; return *d; } template const T &QLazilyAllocated::value() const { if (d.isNull()) d = new T; return *d; } template T *QLazilyAllocated::operator->() const { return d.data(); } template Tag QLazilyAllocated::tag() const { return d.tag(); } template void QLazilyAllocated::setTag(Tag t) { d.setTag(t); } QT_END_NAMESPACE #endif // QLAZILYALLOCATED_P_H