Qt 6.x
The Qt SDK
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
4#ifndef QINTRUSIVELIST_P_H
5#define QINTRUSIVELIST_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19
21
23template<class N, QIntrusiveListNode N::*member>
25{
26public:
29
30 inline bool isEmpty() const;
31 inline void insert(N *n);
32 inline void remove(N *n);
33 inline bool contains(N *) const;
34
35 class iterator {
36 public:
37 inline iterator();
38 inline iterator(N *value);
39
40 inline N *operator*() const;
41 inline N *operator->() const;
42 inline bool operator==(const iterator &other) const;
43 inline bool operator!=(const iterator &other) const;
45
46 inline iterator &erase();
47
48 private:
49 N *_value;
50 };
52
53 inline N *first() const;
54 static inline N *next(N *current);
55
56 inline iterator begin();
57 inline iterator end();
58
59private:
60 static inline N *nodeToN(QIntrusiveListNode *node);
61
62 QIntrusiveListNode *__first = nullptr;
63};
64
66{
67public:
68 inline QIntrusiveListNode();
69 inline ~QIntrusiveListNode();
70
71 inline void remove();
72 inline bool isInList() const;
73
76};
77
78template<class N, QIntrusiveListNode N::*member>
80: _value(nullptr)
81{
82}
83
84template<class N, QIntrusiveListNode N::*member>
86: _value(value)
87{
88}
89
90template<class N, QIntrusiveListNode N::*member>
92{
93 return _value;
94}
95
96template<class N, QIntrusiveListNode N::*member>
98{
99 return _value;
100}
101
102template<class N, QIntrusiveListNode N::*member>
104{
105 return other._value == _value;
106}
107
108template<class N, QIntrusiveListNode N::*member>
110{
111 return other._value != _value;
112}
113
114template<class N, QIntrusiveListNode N::*member>
116{
117 _value = QIntrusiveList<N, member>::next(_value);
118 return *this;
119}
120
121template<class N, QIntrusiveListNode N::*member>
123{
124 N *old = _value;
125 _value = QIntrusiveList<N, member>::next(_value);
126 (old->*member).remove();
127 return *this;
128}
129
130template<class N, QIntrusiveListNode N::*member>
132
133{
134}
135
136template<class N, QIntrusiveListNode N::*member>
138{
139 while (__first) __first->remove();
140}
141
142template<class N, QIntrusiveListNode N::*member>
144{
145 return __first == nullptr;
146}
147
148template<class N, QIntrusiveListNode N::*member>
150{
151 QIntrusiveListNode *nnode = &(n->*member);
152 nnode->remove();
153
154 nnode->_next = __first;
155 if (nnode->_next) nnode->_next->_prev = &nnode->_next;
156 __first = nnode;
157 nnode->_prev = &__first;
158}
159
160template<class N, QIntrusiveListNode N::*member>
162{
163 QIntrusiveListNode *nnode = &(n->*member);
164 nnode->remove();
165}
166
167template<class N, QIntrusiveListNode N::*member>
169{
170 QIntrusiveListNode *nnode = __first;
171 while (nnode) {
172 if (nodeToN(nnode) == n)
173 return true;
174 nnode = nnode->_next;
175 }
176 return false;
177}
178
179template<class N, QIntrusiveListNode N::*member>
181{
182 return __first?nodeToN(__first):nullptr;
183}
184
185template<class N, QIntrusiveListNode N::*member>
187{
188 QIntrusiveListNode *nextnode = (current->*member)._next;
189 N *nextstruct = nextnode?nodeToN(nextnode):nullptr;
190 return nextstruct;
191}
192
193template<class N, QIntrusiveListNode N::*member>
195{
196 return __first?iterator(nodeToN(__first)):iterator();
197}
198
199template<class N, QIntrusiveListNode N::*member>
201{
202 return iterator();
203}
204
205template<class N, QIntrusiveListNode N::*member>
207{
209#if defined(Q_CC_CLANG) && Q_CC_CLANG >= 1300
210 QT_WARNING_DISABLE_CLANG("-Wnull-pointer-subtraction")
211#endif
212 return (N *)((char *)node - ((char *)&(((N *)nullptr)->*member) - (char *)nullptr));
214}
215
217{
218}
219
221{
222 remove();
223}
224
226{
227 if (_prev) *_prev = _next;
228 if (_next) _next->_prev = _prev;
229 _prev = nullptr;
230 _next = nullptr;
231}
232
234{
235 return _prev != nullptr;
236}
237
239
240#endif // QINTRUSIVELIST_P_H
void remove()
If in a list, remove this node otherwise do nothing.
QIntrusiveListNode * _next
bool isInList() const
Returns true if this node is in a list, false otherwise.
QIntrusiveListNode()
Create a QIntrusiveListNode.
QIntrusiveListNode ** _prev
~QIntrusiveListNode()
Destroy the QIntrusiveListNode.
iterator & erase()
Remove the current object from the list, and return an iterator to the next element.
bool operator!=(const iterator &other) const
bool operator==(const iterator &other) const
The QIntrusiveList class is a template class that provides a list of objects using static storage.
bool isEmpty() const
void insert(N *n)
Insert object into the list.
void remove(N *n)
Remove object from the list.
bool contains(N *) const
Returns true if the list contains object; otherwise returns false.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
QIntrusiveList()
Construct an empty list.
~QIntrusiveList()
Destroy the list.
N * first() const
Returns the first entry in this list, or null if the list is empty.
iterator begin()
Returns an STL-style interator pointing to the first item in the list.
static N * next(N *current)
Returns the next object after current, or null if current is the last object.
Combined button and popup list for selecting options.
#define QT_WARNING_POP
#define QT_WARNING_PUSH
#define QT_WARNING_DISABLE_CLANG(text)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLfloat n
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]