Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlazilyallocated_p.h
Go to the documentation of this file.
1
// Copyright (C) 2020 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant
4
5
#
ifndef
QLAZILYALLOCATED_P_H
6
#
define
QLAZILYALLOCATED_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
QtCore
/
private
/
qglobal_p
.
h
>
20
#
include
<
QtCore
/
qtaggedpointer
.
h
>
21
22
QT_BEGIN_NAMESPACE
23
24
template
<
typename
T,
typename
Tag =
typename
QtPrivate::TagInfo<T>::TagType>
25
class
QLazilyAllocated {
26
public
:
27
inline
QLazilyAllocated();
28
inline
~QLazilyAllocated();
29
30
inline
bool
isAllocated()
const
;
31
32
inline
T *operator->()
const
;
33
34
inline
T &value();
35
inline
const
T &value()
const
;
36
37
inline
Tag tag()
const
;
38
inline
void
setTag(Tag t);
39
private
:
40
mutable
QTaggedPointer<T, Tag> d;
41
};
42
43
template
<
typename
T,
typename
Tag>
44
QLazilyAllocated<T, Tag>::QLazilyAllocated()
45
{
46
}
47
48
template
<
typename
T,
typename
Tag>
49
QLazilyAllocated<T, Tag>::~QLazilyAllocated()
50
{
51
delete
d.data();
52
}
53
54
template
<
typename
T,
typename
Tag>
55
bool
QLazilyAllocated<T, Tag>::isAllocated()
const
56
{
57
return
!d.isNull();
58
}
59
60
template
<
typename
T,
typename
Tag>
61
T &QLazilyAllocated<T, Tag>::value()
62
{
63
if
(d.isNull()) d =
new
T;
64
return
*d;
65
}
66
67
template
<
typename
T,
typename
Tag>
68
const
T &QLazilyAllocated<T, Tag>::value()
const
69
{
70
if
(d.isNull()) d =
new
T;
71
return
*d;
72
}
73
74
template
<
typename
T,
typename
Tag>
75
T *QLazilyAllocated<T, Tag>::operator->()
const
76
{
77
return
d.data();
78
}
79
80
template
<
typename
T,
typename
Tag>
81
Tag QLazilyAllocated<T, Tag>::tag()
const
82
{
83
return
d.tag();
84
}
85
86
template
<
typename
T,
typename
Tag>
87
void
QLazilyAllocated<T, Tag>::setTag(Tag t)
88
{
89
d.setTag(t);
90
}
91
92
QT_END_NAMESPACE
93
94
#
endif
// QLAZILYALLOCATED_P_H
qtdeclarative
src
qml
qml
ftw
qlazilyallocated_p.h
Generated on
for Qt by
1.16.1