4#ifndef QINTRUSIVELIST_P_H
5#define QINTRUSIVELIST_P_H
18#include <QtCore/private/qglobal_p.h>
22class QIntrusiveListNode
25 ~QIntrusiveListNode() { remove(); }
29 if (_prev) *_prev = _next;
30 if (_next) _next->_prev = _prev;
35 bool isInList()
const {
return _prev !=
nullptr; }
38 template<
class N, QIntrusiveListNode N::*member>
39 friend class QIntrusiveList;
41 QIntrusiveListNode *_next =
nullptr;
42 QIntrusiveListNode**_prev =
nullptr;
45template<
class N, QIntrusiveListNode N::*member>
52 iterator_impl() =
default;
53 iterator_impl(O value) : _value(value) {}
55 O operator*()
const {
return _value; }
56 O operator->()
const {
return _value; }
57 bool operator==(
const iterator_impl &other)
const {
return other._value == _value; }
58 bool operator!=(
const iterator_impl &other)
const {
return other._value != _value; }
59 iterator_impl &operator++()
61 _value = QIntrusiveList<N, member>::next(_value);
74 iterator(N *value) : iterator_impl<N *>(value) {}
78 N *old =
this->_value;
79 this->_value = QIntrusiveList<N, member>::next(
this->_value);
80 (old->*member).remove();
92 bool isEmpty()
const {
return __first ==
nullptr; }
96 QIntrusiveListNode *nnode = &(n->*member);
99 nnode->_next = __first;
100 if (nnode->_next) nnode->_next->_prev = &nnode->_next;
102 nnode->_prev = &__first;
107 QIntrusiveListNode *nnode = &(n->*member);
113 QIntrusiveListNode *nnode = __first;
115 if (nodeToN(nnode) == n)
117 nnode = nnode->_next;
122 const N *
first()
const {
return __first ? nodeToN(__first) :
nullptr; }
123 N *
first() {
return __first ? nodeToN(__first) :
nullptr; }
128 QIntrusiveListNode *nextnode = (current->*member)._next;
129 return nextnode ? nodeToN(nextnode) :
nullptr;
144 static N *nodeToN(QIntrusiveListNode *node)
147#if defined(Q_CC_CLANG) && Q_CC_CLANG >= 1300
148 QT_WARNING_DISABLE_CLANG(
"-Wnull-pointer-subtraction")
150 return (N *)((
char *)node - ((
char *)&(((N *)
nullptr)->*member) - (
char *)
nullptr));
154 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