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
qintrusivelist_p.h
Go to the documentation of this file.
1
// Copyright (C) 2021 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
QINTRUSIVELIST_P_H
6
#
define
QINTRUSIVELIST_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
21
QT_BEGIN_NAMESPACE
22
23
class
QIntrusiveListNode
24
{
25
public
:
26
~QIntrusiveListNode() { remove(); }
27
28
void
remove()
29
{
30
if
(_prev) *_prev = _next;
31
if
(_next) _next->_prev = _prev;
32
_prev =
nullptr
;
33
_next =
nullptr
;
34
}
35
36
bool
isInList()
const
{
return
_prev !=
nullptr
; }
37
38
private
:
39
template
<
class
N, QIntrusiveListNode N::*member>
40
friend
class
QIntrusiveList;
41
42
QIntrusiveListNode *_next =
nullptr
;
43
QIntrusiveListNode**_prev =
nullptr
;
44
};
45
46
template
<
class
N, QIntrusiveListNode N::*member>
47
class
QIntrusiveList
48
{
49
private
:
50
template
<
typename
O>
51
class
iterator_impl {
52
public
:
53
iterator_impl() =
default
;
54
iterator_impl(O value) : _value(value) {}
55
56
O operator*()
const
{
return
_value; }
57
O operator->()
const
{
return
_value; }
58
bool
operator==(
const
iterator_impl &other)
const
{
return
other._value == _value; }
59
bool
operator!=(
const
iterator_impl &other)
const
{
return
other._value != _value; }
60
iterator_impl &operator++()
61
{
62
_value = QIntrusiveList<N, member>::next(_value);
63
return
*
this
;
64
}
65
66
protected
:
67
O _value =
nullptr
;
68
};
69
70
public
:
71
class
iterator
:
public
iterator_impl<N *>
72
{
73
public
:
74
iterator
() =
default
;
75
iterator
(N *value) : iterator_impl<N *>(value) {}
76
77
iterator
&
erase
()
78
{
79
N *old =
this
->_value;
80
this
->_value = QIntrusiveList<N, member>::next(
this
->_value);
81
(old->*member).remove();
82
return
*
this
;
83
}
84
};
85
86
using
const_iterator
= iterator_impl<
const
N *>;
87
88
using
Iterator
=
iterator
;
89
using
ConstIterator
=
const_iterator
;
90
91
~
QIntrusiveList
() {
while
(__first) __first->remove(); }
92
93
bool
isEmpty
()
const
{
return
__first ==
nullptr
; }
94
95
void
insert
(N *n)
96
{
97
QIntrusiveListNode *nnode = &(n->*member);
98
nnode->remove();
99
100
nnode->_next = __first;
101
if
(nnode->_next) nnode->_next->_prev = &nnode->_next;
102
__first = nnode;
103
nnode->_prev = &__first;
104
}
105
106
void
remove
(N *n)
107
{
108
QIntrusiveListNode *nnode = &(n->*member);
109
nnode->remove();
110
}
111
112
bool
contains
(
const
N *n)
const
113
{
114
QIntrusiveListNode *nnode = __first;
115
while
(nnode) {
116
if
(nodeToN(nnode) == n)
117
return
true
;
118
nnode = nnode->_next;
119
}
120
return
false
;
121
}
122
123
const
N *
first
()
const
{
return
__first ? nodeToN(__first) :
nullptr
; }
124
N *
first
() {
return
__first ? nodeToN(__first) :
nullptr
; }
125
126
template
<
typename
O>
127
static
O
next
(O current)
128
{
129
QIntrusiveListNode *nextnode = (current->*member)._next;
130
return
nextnode ? nodeToN(nextnode) :
nullptr
;
131
}
132
133
iterator
begin
() {
return
__first ?
iterator
(nodeToN(__first)) :
iterator
(); }
134
iterator
end
() {
return
iterator
(); }
135
136
const_iterator
begin
()
const
137
{
138
return
__first ?
const_iterator
(nodeToN(__first)) :
const_iterator
();
139
}
140
141
const_iterator
end
()
const
{
return
const_iterator
(); }
142
143
private
:
144
145
static
N *nodeToN(QIntrusiveListNode *node)
146
{
147
QT_WARNING_PUSH
148
#
if
defined
(
Q_CC_CLANG
)
&&
Q_CC_CLANG
>=
1300
149
QT_WARNING_DISABLE_CLANG(
"-Wnull-pointer-subtraction"
)
150
#
endif
151
return
(N *)((
char
*)node - ((
char
*)&(((N *)
nullptr
)->*member) - (
char
*)
nullptr
));
152
QT_WARNING_POP
153
}
154
155
QIntrusiveListNode *__first =
nullptr
;
156
};
157
158
QT_END_NAMESPACE
159
160
#
endif
// QINTRUSIVELIST_P_H
QIntrusiveList::iterator
Definition
qintrusivelist_p.h:72
QIntrusiveList::iterator::iterator
iterator()=default
QIntrusiveList::iterator::iterator
iterator(N *value)
Definition
qintrusivelist_p.h:75
QIntrusiveList::iterator::erase
iterator & erase()
Remove the current object from the list, and return an iterator to the next element.
Definition
qintrusivelist_p.h:77
QIntrusiveList
The QIntrusiveList class is a template class that provides a list of objects using static storage.
Definition
qintrusivelist_p.h:48
QIntrusiveList::isEmpty
bool isEmpty() const
Definition
qintrusivelist_p.h:93
QIntrusiveList::insert
void insert(N *n)
Insert object into the list.
Definition
qintrusivelist_p.h:95
QIntrusiveList::end
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
Definition
qintrusivelist_p.h:134
QIntrusiveList::remove
void remove(N *n)
Remove object from the list.
Definition
qintrusivelist_p.h:106
QIntrusiveList::next
static O next(O current)
Returns the next object after current, or null if current is the last object.
Definition
qintrusivelist_p.h:127
QIntrusiveList::~QIntrusiveList
~QIntrusiveList()
Destroy the list.
Definition
qintrusivelist_p.h:91
QIntrusiveList::const_iterator
iterator_impl< const N * > const_iterator
Definition
qintrusivelist_p.h:86
QIntrusiveList::Iterator
iterator Iterator
Definition
qintrusivelist_p.h:88
QIntrusiveList::begin
iterator begin()
Returns an STL-style interator pointing to the first item in the list.
Definition
qintrusivelist_p.h:133
QIntrusiveList::first
const N * first() const
Returns the first entry in this list, or null if the list is empty.
Definition
qintrusivelist_p.h:123
QIntrusiveList::first
N * first()
Definition
qintrusivelist_p.h:124
QIntrusiveList::ConstIterator
const_iterator ConstIterator
Definition
qintrusivelist_p.h:89
QIntrusiveList::contains
bool contains(const N *n) const
Returns true if the list contains object; otherwise returns false.
Definition
qintrusivelist_p.h:112
QIntrusiveList::begin
const_iterator begin() const
Definition
qintrusivelist_p.h:136
QIntrusiveList::end
const_iterator end() const
Definition
qintrusivelist_p.h:141
qtdeclarative
src
qml
qml
ftw
qintrusivelist_p.h
Generated on
for Qt by
1.18.0