1
/****************************************************************************
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/
6
** This file is part of the QtQml module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** GNU Lesser General Public License Usage
10
** This file may be used under the terms of the GNU Lesser General Public
11
** License version 2.1 as published by the Free Software Foundation and
12
** appearing in the file LICENSE.LGPL included in the packaging of this
13
** file. Please review the following information to ensure the GNU Lesser
14
** General Public License version 2.1 requirements will be met:
15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
** In addition, as a special exception, Nokia gives you certain additional
18
** rights. These rights are described in the Nokia Qt LGPL Exception
19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21
** GNU General Public License Usage
22
** Alternatively, this file may be used under the terms of the GNU General
23
** Public License version 3.0 as published by the Free Software Foundation
24
** and appearing in the file LICENSE.GPL included in the packaging of this
25
** file. Please review the following information to ensure the GNU General
26
** Public License version 3.0 requirements will be met:
27
** http://www.gnu.org/copyleft/gpl.html.
30
** Alternatively, this file may be used in accordance with the terms and
31
** conditions contained in a signed written agreement between you and Nokia.
40
****************************************************************************/
42
#ifndef QINTRUSIVELIST_P_H
43
#define QINTRUSIVELIST_P_H
49
// This file is not part of the Qt API. It exists purely as an
50
// implementation detail. This header file may change from version to
51
// version without notice, or even be removed.
56
#include <QtCore/qglobal.h>
60
class QIntrusiveListNode;
61
template<class N, QIntrusiveListNode N::*member>
65
inline QIntrusiveList();
66
inline ~QIntrusiveList();
68
inline bool isEmpty() const;
69
inline void insert(N *n);
70
inline void remove(N *n);
71
inline bool contains(N *) const;
76
inline iterator(N *value);
78
inline N *operator*() const;
79
inline N *operator->() const;
80
inline bool operator==(const iterator &other) const;
81
inline bool operator!=(const iterator &other) const;
82
inline iterator &operator++();
84
inline iterator &erase();
89
typedef iterator Iterator;
91
inline N *first() const;
92
static inline N *next(N *current);
94
inline iterator begin();
95
inline iterator end();
98
static inline N *nodeToN(QIntrusiveListNode *node);
100
QIntrusiveListNode *__first;
103
class QIntrusiveListNode
106
inline QIntrusiveListNode();
107
inline ~QIntrusiveListNode();
109
inline void remove();
110
inline bool isInList() const;
112
QIntrusiveListNode *_next;
113
QIntrusiveListNode**_prev;
116
template<class N, QIntrusiveListNode N::*member>
117
QIntrusiveList<N, member>::iterator::iterator()
122
template<class N, QIntrusiveListNode N::*member>
123
QIntrusiveList<N, member>::iterator::iterator(N *value)
128
template<class N, QIntrusiveListNode N::*member>
129
N *QIntrusiveList<N, member>::iterator::operator*() const
134
template<class N, QIntrusiveListNode N::*member>
135
N *QIntrusiveList<N, member>::iterator::operator->() const
140
template<class N, QIntrusiveListNode N::*member>
141
bool QIntrusiveList<N, member>::iterator::operator==(const iterator &other) const
143
return other._value == _value;
146
template<class N, QIntrusiveListNode N::*member>
147
bool QIntrusiveList<N, member>::iterator::operator!=(const iterator &other) const
149
return other._value != _value;
152
template<class N, QIntrusiveListNode N::*member>
153
typename QIntrusiveList<N, member>::iterator &QIntrusiveList<N, member>::iterator::operator++()
155
_value = QIntrusiveList<N, member>::next(_value);
159
template<class N, QIntrusiveListNode N::*member>
160
typename QIntrusiveList<N, member>::iterator &QIntrusiveList<N, member>::iterator::erase()
163
_value = QIntrusiveList<N, member>::next(_value);
164
(old->*member).remove();
168
template<class N, QIntrusiveListNode N::*member>
169
QIntrusiveList<N, member>::QIntrusiveList()
174
template<class N, QIntrusiveListNode N::*member>
175
QIntrusiveList<N, member>::~QIntrusiveList()
177
while (__first) __first->remove();
180
template<class N, QIntrusiveListNode N::*member>
181
bool QIntrusiveList<N, member>::isEmpty() const
186
template<class N, QIntrusiveListNode N::*member>
187
void QIntrusiveList<N, member>::insert(N *n)
189
QIntrusiveListNode *nnode = &(n->*member);
192
nnode->_next = __first;
193
if (nnode->_next) nnode->_next->_prev = &nnode->_next;
195
nnode->_prev = &__first;
198
template<class N, QIntrusiveListNode N::*member>
199
void QIntrusiveList<N, member>::remove(N *n)
201
QIntrusiveListNode *nnode = &(n->*member);
205
template<class N, QIntrusiveListNode N::*member>
206
bool QIntrusiveList<N, member>::contains(N *n) const
208
QIntrusiveListNode *nnode = __first;
210
if (nodeToN(nnode) == n)
212
nnode = nnode->_next;
217
template<class N, QIntrusiveListNode N::*member>
218
N *QIntrusiveList<N, member>::first() const
220
return __first?nodeToN(__first):0;
223
template<class N, QIntrusiveListNode N::*member>
224
N *QIntrusiveList<N, member>::next(N *current)
226
QIntrusiveListNode *nextnode = (current->*member)._next;
227
N *nextstruct = nextnode?nodeToN(nextnode):0;
231
template<class N, QIntrusiveListNode N::*member>
232
typename QIntrusiveList<N, member>::iterator QIntrusiveList<N, member>::begin()
234
return __first?iterator(nodeToN(__first)):iterator();
237
template<class N, QIntrusiveListNode N::*member>
238
typename QIntrusiveList<N, member>::iterator QIntrusiveList<N, member>::end()
243
template<class N, QIntrusiveListNode N::*member>
244
N *QIntrusiveList<N, member>::nodeToN(QIntrusiveListNode *node)
246
return (N *)((char *)node - ((char *)&(((N *)0)->*member) - (char *)0));
249
QIntrusiveListNode::QIntrusiveListNode()
254
QIntrusiveListNode::~QIntrusiveListNode()
259
void QIntrusiveListNode::remove()
261
if (_prev) *_prev = _next;
262
if (_next) _next->_prev = _prev;
267
bool QIntrusiveListNode::isInList() const
274
#endif // QINTRUSIVELIST_P_H