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
qintrusivelist.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 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
#
include
"qintrusivelist_p.h"
6
7
/*!
8
\class QIntrusiveList
9
\brief The QIntrusiveList class is a template class that provides a list of objects using static storage.
10
\internal
11
12
QIntrusiveList creates a linked list of objects. Adding and removing objects from the
13
QIntrusiveList is a constant time operation and is very quick. The list performs no memory
14
allocations, but does require the objects being added to the list to contain a QIntrusiveListNode
15
instance for the list's use. Even so, for small lists QIntrusiveList uses less memory than Qt's
16
other list classes.
17
18
As QIntrusiveList uses storage inside the objects in the list, each object can only be in one
19
list at a time. Objects are inserted by the insert() method. If the object is already
20
in a list (including the one it is being inserted into) it is first removed, and then inserted
21
at the head of the list. QIntrusiveList is a last-in-first-out list. That is, following an
22
insert() the inserted object becomes the list's first() object.
23
24
\code
25
struct MyObject {
26
MyObject(int value) : value(value) {}
27
28
int value;
29
QIntrusiveListNode node;
30
};
31
typedef QIntrusiveList<MyObject, &MyObject::node> MyObjectList;
32
33
void foo() {
34
MyObjectList list;
35
36
MyObject m0(0);
37
MyObject m1(1);
38
MyObject m2(2);
39
40
list.insert(&m0);
41
list.insert(&m1);
42
list.insert(&m2);
43
44
// QIntrusiveList is LIFO, so will print: 2... 1... 0...
45
for (MyObjectList::iterator iter = list.begin(); iter != list.end(); ++iter) {
46
qWarning() << iter->value;
47
}
48
}
49
\endcode
50
*/
51
52
53
/*!
54
\fn QIntrusiveList::QIntrusiveList();
55
56
Construct an empty list.
57
*/
58
59
/*!
60
\fn QIntrusiveList::~QIntrusiveList();
61
62
Destroy the list. All entries are removed.
63
*/
64
65
/*!
66
\fn void QIntrusiveList::insert(N *object);
67
68
Insert \a object into the list. If \a object is a member of this, or another list, it will be
69
removed and inserted at the head of this list.
70
*/
71
72
/*!
73
\fn void QIntrusiveList::remove(N *object);
74
75
Remove \a object from the list. \a object must not be null.
76
*/
77
78
/*!
79
\fn bool QIntrusiveList::contains(N *object) const
80
81
Returns true if the list contains \a object; otherwise returns false.
82
*/
83
84
/*!
85
\fn N *QIntrusiveList::first() const
86
87
Returns the first entry in this list, or null if the list is empty.
88
*/
89
90
/*!
91
\fn N *QIntrusiveList::next(N *current)
92
93
Returns the next object after \a current, or null if \a current is the last object. \a current cannot be null.
94
*/
95
96
/*!
97
\fn iterator QIntrusiveList::begin()
98
99
Returns an STL-style interator pointing to the first item in the list.
100
101
\sa end()
102
*/
103
104
/*!
105
\fn iterator QIntrusiveList::end()
106
107
Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
108
109
\sa begin()
110
*/
111
112
/*!
113
\fn iterator &QIntrusiveList::iterator::erase()
114
115
Remove the current object from the list, and return an iterator to the next element.
116
*/
117
118
/*!
119
\class QIntrusiveListNode
120
\internal
121
*/
122
123
/*!
124
\fn QIntrusiveListNode::QIntrusiveListNode()
125
126
Create a QIntrusiveListNode.
127
*/
128
129
/*!
130
\fn QIntrusiveListNode::~QIntrusiveListNode()
131
132
Destroy the QIntrusiveListNode. If the node is in a list, it is removed.
133
*/
134
135
/*!
136
\fn void QIntrusiveListNode::remove()
137
138
If in a list, remove this node otherwise do nothing.
139
*/
140
141
/*!
142
\fn bool QIntrusiveListNode::isInList() const
143
144
Returns true if this node is in a list, false otherwise.
145
*/
qtdeclarative
src
qml
qml
ftw
qintrusivelist.cpp
Generated on
for Qt by
1.16.1