Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qshareddata_impl.h
Go to the documentation of this file.
1
// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
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 reason:default
4
5
#
if
0
6
#
pragma
qt_sync_skip_header_check
7
#
pragma
qt_sync_stop_processing
8
#
endif
9
10
#
ifndef
QSHAREDDATA_IMPL_H
11
#
define
QSHAREDDATA_IMPL_H
12
13
#
include
<
QtCore
/
qcompare
.
h
>
14
#
include
<
QtCore
/
qglobal
.
h
>
15
#
include
<
QtCore
/
qshareddata
.
h
>
16
17
QT_BEGIN_NAMESPACE
18
19
namespace
QtPrivate
{
20
21
template
<
typename
T>
22
class
QExplicitlySharedDataPointerV2
23
{
24
Qt::totally_ordered_wrapper<T *> d;
25
26
public
:
27
constexpr
QExplicitlySharedDataPointerV2
()
noexcept
:
d
(
nullptr
) {}
28
29
explicit
QExplicitlySharedDataPointerV2
(T *t)
noexcept
30
:
d
(
t
)
31
{
32
if
(d)
33
d->ref.ref();
34
}
35
36
QExplicitlySharedDataPointerV2
(T *t,
QAdoptSharedDataTag
)
noexcept
37
:
d
(
t
)
38
{
39
}
40
41
QExplicitlySharedDataPointerV2
(
const
QExplicitlySharedDataPointerV2
&other)
noexcept
42
:
d
(
other
.
d
)
43
{
44
if
(d)
45
d->ref.ref();
46
}
47
48
QExplicitlySharedDataPointerV2
&
operator
=(
const
QExplicitlySharedDataPointerV2
&other)
noexcept
49
{
50
QExplicitlySharedDataPointerV2
copy(other);
51
swap
(
copy
)
;
52
return
*
this
;
53
}
54
55
QExplicitlySharedDataPointerV2
(
QExplicitlySharedDataPointerV2
&&other)
noexcept
56
:
d
(
std
::
exchange
(
other
.
d
,
nullptr
))
57
{
58
}
59
60
QExplicitlySharedDataPointerV2
&
operator
=(
QExplicitlySharedDataPointerV2
&&other)
noexcept
61
{
62
QExplicitlySharedDataPointerV2
moved(std::move(other));
63
swap
(
moved
)
;
64
return
*
this
;
65
}
66
67
~
QExplicitlySharedDataPointerV2
()
68
{
69
if
(d && !d->ref.deref())
70
delete
d.get();
71
}
72
73
void
detach
()
74
{
75
if
(!d) {
76
// should this codepath be here on in all user's detach()?
77
d.reset(
new
T);
78
d->ref.ref();
79
}
else
if
(d->ref.loadRelaxed() != 1) {
80
// TODO: qAtomicDetach here...?
81
QExplicitlySharedDataPointerV2
copy(
new
T(*d));
82
swap
(
copy
)
;
83
}
84
}
85
86
void
reset
(T *t =
nullptr
)
noexcept
87
{
88
if
(d && !d->ref.deref())
89
delete
d.get();
90
d.reset(t);
91
if
(d)
92
d->ref.ref();
93
}
94
95
constexpr
T *
take
()
noexcept
96
{
97
return
std::exchange(d,
nullptr
).get();
98
}
99
100
bool
isShared
()
const
noexcept
101
{
102
return
d && d->ref.loadRelaxed() != 1;
103
}
104
105
constexpr
void
swap
(
QExplicitlySharedDataPointerV2
&other)
noexcept
106
{
107
qt_ptr_swap(d, other.d);
108
}
109
110
// important change from QExplicitlySharedDataPointer: deep const
111
constexpr
T &
operator
*() {
return
*(d.get()); }
112
constexpr
T *
operator
->() {
return
d.get(); }
113
constexpr
const
T &
operator
*()
const
{
return
*(d.get()); }
114
constexpr
const
T *
operator
->()
const
{
return
d.get(); }
115
116
constexpr
T *
data
()
noexcept
{
return
d.get(); }
117
constexpr
const
T *
data
()
const
noexcept
{
return
d.get(); }
118
119
constexpr
explicit
operator
bool
()
const
noexcept
{
return
d.get(); }
120
121
private
:
122
constexpr
friend
bool
comparesEqual
(
const
QExplicitlySharedDataPointerV2
&lhs,
123
const
QExplicitlySharedDataPointerV2
&rhs)
noexcept
124
{
return
lhs.d == rhs.d; }
125
constexpr
friend
Qt
::
strong_ordering
126
compareThreeWay
(
const
QExplicitlySharedDataPointerV2
&lhs,
127
const
QExplicitlySharedDataPointerV2
&rhs)
noexcept
128
{
return
Qt::compareThreeWay(lhs.d, rhs.d); }
129
Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE
(
QExplicitlySharedDataPointerV2
)
130
131
constexpr
friend
bool
132
comparesEqual
(
const
QExplicitlySharedDataPointerV2
&lhs,
std
::
nullptr_t
)
noexcept
133
{
return
lhs.d ==
nullptr
; }
134
constexpr
friend
Qt
::
strong_ordering
135
compareThreeWay
(
const
QExplicitlySharedDataPointerV2
&lhs,
std
::
nullptr_t
)
noexcept
136
{
return
Qt::compareThreeWay(lhs.d,
nullptr
); }
137
Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(
QExplicitlySharedDataPointerV2
, std::nullptr_t)
138
};
139
140
template
<
typename
T>
141
constexpr
void
swap
(
QExplicitlySharedDataPointerV2
<T> &lhs,
QExplicitlySharedDataPointerV2
<T> &rhs)
noexcept
142
{
143
lhs.swap(rhs);
144
}
145
146
}
// namespace QtPrivate
147
148
template
<
class
T>
149
Q_DECLARE_TYPEINFO_BODY
(
QtPrivate
::
QExplicitlySharedDataPointerV2
<T>,
Q_RELOCATABLE_TYPE
);
150
151
QT_END_NAMESPACE
152
153
#
endif
// QSHAREDDATA_IMPL_H
QtPrivate::QExplicitlySharedDataPointerV2
Definition
qshareddata_impl.h:23
QtPrivate::QExplicitlySharedDataPointerV2::QExplicitlySharedDataPointerV2
QExplicitlySharedDataPointerV2(const QExplicitlySharedDataPointerV2 &other) noexcept
Definition
qshareddata_impl.h:41
QtPrivate::QExplicitlySharedDataPointerV2::reset
void reset(T *t=nullptr) noexcept
Definition
qshareddata_impl.h:86
QtPrivate::QExplicitlySharedDataPointerV2::swap
constexpr void swap(QExplicitlySharedDataPointerV2 &other) noexcept
Definition
qshareddata_impl.h:105
QtPrivate::QExplicitlySharedDataPointerV2::operator->
constexpr T * operator->()
Definition
qshareddata_impl.h:112
QtPrivate::QExplicitlySharedDataPointerV2::data
constexpr const T * data() const noexcept
Definition
qshareddata_impl.h:117
QtPrivate::QExplicitlySharedDataPointerV2::operator=
QExplicitlySharedDataPointerV2 & operator=(const QExplicitlySharedDataPointerV2 &other) noexcept
Definition
qshareddata_impl.h:48
QtPrivate::QExplicitlySharedDataPointerV2::QExplicitlySharedDataPointerV2
constexpr QExplicitlySharedDataPointerV2() noexcept
Definition
qshareddata_impl.h:27
QtPrivate::QExplicitlySharedDataPointerV2::detach
void detach()
Definition
qshareddata_impl.h:73
QtPrivate::QExplicitlySharedDataPointerV2::QExplicitlySharedDataPointerV2
QExplicitlySharedDataPointerV2(T *t, QAdoptSharedDataTag) noexcept
Definition
qshareddata_impl.h:36
QtPrivate::QExplicitlySharedDataPointerV2::operator=
QExplicitlySharedDataPointerV2 & operator=(QExplicitlySharedDataPointerV2 &&other) noexcept
Definition
qshareddata_impl.h:60
QtPrivate::QExplicitlySharedDataPointerV2::compareThreeWay
constexpr friend Qt::strong_ordering compareThreeWay(const QExplicitlySharedDataPointerV2 &lhs, const QExplicitlySharedDataPointerV2 &rhs) noexcept
Definition
qshareddata_impl.h:126
QtPrivate::QExplicitlySharedDataPointerV2::operator*
constexpr const T & operator*() const
Definition
qshareddata_impl.h:113
QtPrivate::QExplicitlySharedDataPointerV2::operator*
constexpr T & operator*()
Definition
qshareddata_impl.h:111
QtPrivate::QExplicitlySharedDataPointerV2::operator->
constexpr const T * operator->() const
Definition
qshareddata_impl.h:114
QtPrivate::QExplicitlySharedDataPointerV2::QExplicitlySharedDataPointerV2
QExplicitlySharedDataPointerV2(T *t) noexcept
Definition
qshareddata_impl.h:29
QtPrivate::QExplicitlySharedDataPointerV2::data
constexpr T * data() noexcept
Definition
qshareddata_impl.h:116
QtPrivate::QExplicitlySharedDataPointerV2::take
constexpr T * take() noexcept
Definition
qshareddata_impl.h:95
QtPrivate::QExplicitlySharedDataPointerV2::~QExplicitlySharedDataPointerV2
~QExplicitlySharedDataPointerV2()
Definition
qshareddata_impl.h:67
QtPrivate::QExplicitlySharedDataPointerV2::operator bool
constexpr operator bool() const noexcept
Definition
qshareddata_impl.h:119
QtPrivate::QExplicitlySharedDataPointerV2::QExplicitlySharedDataPointerV2
QExplicitlySharedDataPointerV2(QExplicitlySharedDataPointerV2 &&other) noexcept
Definition
qshareddata_impl.h:55
QtPrivate::QExplicitlySharedDataPointerV2::comparesEqual
constexpr friend bool comparesEqual(const QExplicitlySharedDataPointerV2 &lhs, std::nullptr_t) noexcept
Definition
qshareddata_impl.h:132
QtPrivate::QExplicitlySharedDataPointerV2::comparesEqual
constexpr friend bool comparesEqual(const QExplicitlySharedDataPointerV2 &lhs, const QExplicitlySharedDataPointerV2 &rhs) noexcept
Definition
qshareddata_impl.h:122
QtPrivate::QExplicitlySharedDataPointerV2::compareThreeWay
constexpr friend Qt::strong_ordering compareThreeWay(const QExplicitlySharedDataPointerV2 &lhs, std::nullptr_t) noexcept
Definition
qshareddata_impl.h:135
QtPrivate::QExplicitlySharedDataPointerV2::isShared
bool isShared() const noexcept
Definition
qshareddata_impl.h:100
QtPrivate
Definition
qalloc.h:29
QtPrivate::swap
constexpr void swap(QExplicitlySharedDataPointerV2< T > &lhs, QExplicitlySharedDataPointerV2< T > &rhs) noexcept
Definition
qshareddata_impl.h:141
Q_DECLARE_TYPEINFO_BODY
Q_DECLARE_TYPEINFO_BODY(QtPrivate::QExplicitlySharedDataPointerV2< T >, Q_RELOCATABLE_TYPE)
qtbase
src
corelib
tools
qshareddata_impl.h
Generated on
for Qt by
1.18.0