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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
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 void insert(N *n);
69 inline void remove(N *n);
74 inline iterator(N *value);
76 inline N *operator*() const;
77 inline N *operator->() const;
78 inline bool operator==(const iterator &other) const;
79 inline bool operator!=(const iterator &other) const;
80 inline iterator &operator++();
82 inline iterator &erase();
87 typedef iterator Iterator;
89 inline N *first() const;
90 static inline N *next(N *current);
92 inline iterator begin();
93 inline iterator end();
96 static inline N *nodeToN(QIntrusiveListNode *node);
98 QIntrusiveListNode *__first;
101 class QIntrusiveListNode
104 inline QIntrusiveListNode();
105 inline ~QIntrusiveListNode();
107 inline void remove();
108 inline bool isInList() const;
110 QIntrusiveListNode *_next;
111 QIntrusiveListNode**_prev;
114 template<class N, QIntrusiveListNode N::*member>
115 QIntrusiveList<N, member>::iterator::iterator()
120 template<class N, QIntrusiveListNode N::*member>
121 QIntrusiveList<N, member>::iterator::iterator(N *value)
126 template<class N, QIntrusiveListNode N::*member>
127 N *QIntrusiveList<N, member>::iterator::operator*() const
132 template<class N, QIntrusiveListNode N::*member>
133 N *QIntrusiveList<N, member>::iterator::operator->() const
138 template<class N, QIntrusiveListNode N::*member>
139 bool QIntrusiveList<N, member>::iterator::operator==(const iterator &other) const
141 return other._value == _value;
144 template<class N, QIntrusiveListNode N::*member>
145 bool QIntrusiveList<N, member>::iterator::operator!=(const iterator &other) const
147 return other._value != _value;
150 template<class N, QIntrusiveListNode N::*member>
151 typename QIntrusiveList<N, member>::iterator &QIntrusiveList<N, member>::iterator::operator++()
153 _value = QIntrusiveList<N, member>::next(_value);
157 template<class N, QIntrusiveListNode N::*member>
158 typename QIntrusiveList<N, member>::iterator &QIntrusiveList<N, member>::iterator::erase()
161 _value = QIntrusiveList<N, member>::next(_value);
162 (old->*member).remove();
166 template<class N, QIntrusiveListNode N::*member>
167 QIntrusiveList<N, member>::QIntrusiveList()
172 template<class N, QIntrusiveListNode N::*member>
173 QIntrusiveList<N, member>::~QIntrusiveList()
175 while (__first) __first->remove();
178 template<class N, QIntrusiveListNode N::*member>
179 void QIntrusiveList<N, member>::insert(N *n)
181 QIntrusiveListNode *nnode = &(n->*member);
184 nnode->_next = __first;
185 if (nnode->_next) nnode->_next->_prev = &nnode->_next;
187 nnode->_prev = &__first;
190 template<class N, QIntrusiveListNode N::*member>
191 void QIntrusiveList<N, member>::remove(N *n)
193 QIntrusiveListNode *nnode = &(n->*member);
197 template<class N, QIntrusiveListNode N::*member>
198 N *QIntrusiveList<N, member>::first() const
200 return __first?nodeToN(__first):0;
203 template<class N, QIntrusiveListNode N::*member>
204 N *QIntrusiveList<N, member>::next(N *current)
206 QIntrusiveListNode *nextnode = (current->*member)._next;
207 N *nextstruct = nextnode?nodeToN(nextnode):0;
211 template<class N, QIntrusiveListNode N::*member>
212 typename QIntrusiveList<N, member>::iterator QIntrusiveList<N, member>::begin()
214 return __first?iterator(nodeToN(__first)):iterator();
217 template<class N, QIntrusiveListNode N::*member>
218 typename QIntrusiveList<N, member>::iterator QIntrusiveList<N, member>::end()
223 template<class N, QIntrusiveListNode N::*member>
224 N *QIntrusiveList<N, member>::nodeToN(QIntrusiveListNode *node)
226 return (N *)((char *)node - ((char *)&(((N *)0)->*member) - (char *)0));
229 QIntrusiveListNode::QIntrusiveListNode()
234 QIntrusiveListNode::~QIntrusiveListNode()
239 void QIntrusiveListNode::remove()
241 if (_prev) *_prev = _next;
242 if (_next) _next->_prev = _prev;
247 bool QIntrusiveListNode::isInList() const
254 #endif // QINTRUSIVELIST_P_H