1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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);
75 inline iterator(N *value);
77 inline N *operator*() const;
78 inline N *operator->() const;
79 inline bool operator==(const iterator &other) const;
80 inline bool operator!=(const iterator &other) const;
81 inline iterator &operator++();
83 inline iterator &erase();
88 typedef iterator Iterator;
90 inline N *first() const;
91 static inline N *next(N *current);
93 inline iterator begin();
94 inline iterator end();
97 static inline N *nodeToN(QIntrusiveListNode *node);
99 QIntrusiveListNode *__first;
102 class QIntrusiveListNode
105 inline QIntrusiveListNode();
106 inline ~QIntrusiveListNode();
108 inline void remove();
109 inline bool isInList() const;
111 QIntrusiveListNode *_next;
112 QIntrusiveListNode**_prev;
115 template<class N, QIntrusiveListNode N::*member>
116 QIntrusiveList<N, member>::iterator::iterator()
121 template<class N, QIntrusiveListNode N::*member>
122 QIntrusiveList<N, member>::iterator::iterator(N *value)
127 template<class N, QIntrusiveListNode N::*member>
128 N *QIntrusiveList<N, member>::iterator::operator*() const
133 template<class N, QIntrusiveListNode N::*member>
134 N *QIntrusiveList<N, member>::iterator::operator->() const
139 template<class N, QIntrusiveListNode N::*member>
140 bool QIntrusiveList<N, member>::iterator::operator==(const iterator &other) const
142 return other._value == _value;
145 template<class N, QIntrusiveListNode N::*member>
146 bool QIntrusiveList<N, member>::iterator::operator!=(const iterator &other) const
148 return other._value != _value;
151 template<class N, QIntrusiveListNode N::*member>
152 typename QIntrusiveList<N, member>::iterator &QIntrusiveList<N, member>::iterator::operator++()
154 _value = QIntrusiveList<N, member>::next(_value);
158 template<class N, QIntrusiveListNode N::*member>
159 typename QIntrusiveList<N, member>::iterator &QIntrusiveList<N, member>::iterator::erase()
162 _value = QIntrusiveList<N, member>::next(_value);
163 (old->*member).remove();
167 template<class N, QIntrusiveListNode N::*member>
168 QIntrusiveList<N, member>::QIntrusiveList()
173 template<class N, QIntrusiveListNode N::*member>
174 QIntrusiveList<N, member>::~QIntrusiveList()
176 while (__first) __first->remove();
179 template<class N, QIntrusiveListNode N::*member>
180 bool QIntrusiveList<N, member>::isEmpty() const
185 template<class N, QIntrusiveListNode N::*member>
186 void QIntrusiveList<N, member>::insert(N *n)
188 QIntrusiveListNode *nnode = &(n->*member);
191 nnode->_next = __first;
192 if (nnode->_next) nnode->_next->_prev = &nnode->_next;
194 nnode->_prev = &__first;
197 template<class N, QIntrusiveListNode N::*member>
198 void QIntrusiveList<N, member>::remove(N *n)
200 QIntrusiveListNode *nnode = &(n->*member);
204 template<class N, QIntrusiveListNode N::*member>
205 N *QIntrusiveList<N, member>::first() const
207 return __first?nodeToN(__first):0;
210 template<class N, QIntrusiveListNode N::*member>
211 N *QIntrusiveList<N, member>::next(N *current)
213 QIntrusiveListNode *nextnode = (current->*member)._next;
214 N *nextstruct = nextnode?nodeToN(nextnode):0;
218 template<class N, QIntrusiveListNode N::*member>
219 typename QIntrusiveList<N, member>::iterator QIntrusiveList<N, member>::begin()
221 return __first?iterator(nodeToN(__first)):iterator();
224 template<class N, QIntrusiveListNode N::*member>
225 typename QIntrusiveList<N, member>::iterator QIntrusiveList<N, member>::end()
230 template<class N, QIntrusiveListNode N::*member>
231 N *QIntrusiveList<N, member>::nodeToN(QIntrusiveListNode *node)
233 return (N *)((char *)node - ((char *)&(((N *)0)->*member) - (char *)0));
236 QIntrusiveListNode::QIntrusiveListNode()
241 QIntrusiveListNode::~QIntrusiveListNode()
246 void QIntrusiveListNode::remove()
248 if (_prev) *_prev = _next;
249 if (_next) _next->_prev = _prev;
254 bool QIntrusiveListNode::isInList() const
261 #endif // QINTRUSIVELIST_P_H