5#ifndef QINTRUSIVELIST_P_H
6#define QINTRUSIVELIST_P_H
19#include <QtCore/private/qglobal_p.h>
23class QIntrusiveListNode
26 ~QIntrusiveListNode() { remove(); }
30 if (_prev) *_prev = _next;
31 if (_next) _next->_prev = _prev;
36 bool isInList()
const {
return _prev !=
nullptr; }
39 template<
class N, QIntrusiveListNode N::*member>
40 friend class QIntrusiveList;
42 QIntrusiveListNode *_next =
nullptr;
43 QIntrusiveListNode**_prev =
nullptr;
46template<
class N, QIntrusiveListNode N::*member>
53 iterator_impl() =
default;
54 iterator_impl(O value) : _value(value) {}
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++()
62 _value = QIntrusiveList<N, member>::next(_value);
75 iterator(N *value) : iterator_impl<N *>(value) {}
79 N *old =
this->_value;
80 this->_value = QIntrusiveList<N, member>::next(
this->_value);
81 (old->*member).remove();
93 bool isEmpty()
const {
return __first ==
nullptr; }
97 QIntrusiveListNode *nnode = &(n->*member);
100 nnode->_next = __first;
101 if (nnode->_next) nnode->_next->_prev = &nnode->_next;
103 nnode->_prev = &__first;
108 QIntrusiveListNode *nnode = &(n->*member);
114 QIntrusiveListNode *nnode = __first;
116 if (nodeToN(nnode) == n)
118 nnode = nnode->_next;
123 const N *
first()
const {
return __first ? nodeToN(__first) :
nullptr; }
124 N *
first() {
return __first ? nodeToN(__first) :
nullptr; }
129 QIntrusiveListNode *nextnode = (current->*member)._next;
130 return nextnode ? nodeToN(nextnode) :
nullptr;
145 static N *nodeToN(QIntrusiveListNode *node)
148#if defined(Q_CC_CLANG) && Q_CC_CLANG >= 1300
149 QT_WARNING_DISABLE_CLANG(
"-Wnull-pointer-subtraction")
151 return (N *)((
char *)node - ((
char *)&(((N *)
nullptr)->*member) - (
char *)
nullptr));
155 QIntrusiveListNode *__first =
nullptr;
iterator & erase()
Remove the current object from the list, and return an iterator to the next element.
The QIntrusiveList class is a template class that provides a list of objects using static storage.
void insert(N *n)
Insert object into the list.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
void remove(N *n)
Remove object from the list.
static O next(O current)
Returns the next object after current, or null if current is the last object.
~QIntrusiveList()
Destroy the list.
iterator_impl< const N * > const_iterator
iterator begin()
Returns an STL-style interator pointing to the first item in the list.
const N * first() const
Returns the first entry in this list, or null if the list is empty.
const_iterator ConstIterator
bool contains(const N *n) const
Returns true if the list contains object; otherwise returns false.
const_iterator begin() const
const_iterator end() const