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 #include "qintrusivelist_p.h"
46 \brief The QIntrusiveList class is a template class that provides a list of objects using static storage.
49 QIntrusiveList creates a linked list of objects. Adding and removing objects from the
50 QIntrusiveList is a constant time operation and is very quick. The list performs no memory
51 allocations, but does require the objects being added to the list to contain a QIntrusiveListNode
52 instance for the list's use. Even so, for small lists QIntrusiveList uses less memory than Qt's
55 As QIntrusiveList uses storage inside the objects in the list, each object can only be in one
56 list at a time. Objects are inserted by the insert() method. If the object is already
57 in a list (including the one it is being inserted into) it is first removed, and then inserted
58 at the head of the list. QIntrusiveList is a last-in-first-out list. That is, following an
59 insert() the inserted object becomes the list's first() object.
63 MyObject(int value) : value(value) {}
66 QIntrusiveListNode node;
68 typedef QIntrusiveList<MyObject, &MyObject::node> MyObjectList;
81 // QIntrusiveList is LIFO, so will print: 2... 1... 0...
82 for (MyObjectList::iterator iter = list.begin(); iter != list.end(); ++iter) {
83 qWarning() << iter->value;
91 \fn QIntrusiveList::QIntrusiveList();
93 Construct an empty list.
97 \fn QIntrusiveList::~QIntrusiveList();
99 Destroy the list. All entries are removed.
103 \fn void QIntrusiveList::insert(N *object);
105 Insert \a object into the list. If \a object is a member of this, or another list, it will be
106 removed and inserted at the head of this list.
110 \fn void QIntrusiveList::remove(N *object);
112 Remove \a object from the list. \a object must not be null.
116 \fn N *QIntrusiveList::first() const
118 Returns the first entry in this list, or null if the list is empty.
122 \fn N *QIntrusiveList::next(N *current)
124 Returns the next object after \a current, or null if \a current is the last object. \a current cannot be null.
128 \fn iterator QIntrusiveList::begin()
130 Returns an STL-style interator pointing to the first item in the list.
136 \fn iterator QIntrusiveList::end()
138 Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
144 iterator &QInplacelist::iterator::erase()
146 Remove the current object from the list, and return an iterator to the next element.
151 \fn QIntrusiveListNode::QIntrusiveListNode()
153 Create a QIntrusiveListNode.
157 \fn QIntrusiveListNode::~QIntrusiveListNode()
159 Destroy the QIntrusiveListNode. If the node is in a list, it is removed.
163 \fn void QIntrusiveListNode::remove()
165 If in a list, remove this node otherwise do nothing.
169 \fn bool QIntrusiveListNode::isInList() const
171 Returns true if this node is in a list, false otherwise.