Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qtdeclarative
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qintrusivelist.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
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
14 ** this package.
15 **
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.
23 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qintrusivelist_p.h"
43
44 /*!
45 \class QIntrusiveList
46 \brief The QIntrusiveList class is a template class that provides a list of objects using static storage.
47 \internal
48
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
53 other list classes.
54
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.
60
61 \code
62 struct MyObject {
63     MyObject(int value) : value(value) {}
64
65     int value;
66     QIntrusiveListNode node;
67 };
68 typedef QIntrusiveList<MyObject, &MyObject::node> MyObjectList;
69
70 void foo() {
71     MyObjectList list;
72
73     MyObject m0(0);
74     MyObject m1(1);
75     MyObject m2(2);
76
77     list.insert(&m0);
78     list.insert(&m1);
79     list.insert(&m2);
80
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;
84     }
85 }
86 \endcode
87 */
88
89
90 /*!
91 \fn QIntrusiveList::QIntrusiveList();
92
93 Construct an empty list.
94 */
95
96 /*!
97 \fn QIntrusiveList::~QIntrusiveList();
98
99 Destroy the list.  All entries are removed.
100 */
101
102 /*!
103 \fn void QIntrusiveList::insert(N *object);
104
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.
107 */
108
109 /*!
110 \fn void QIntrusiveList::remove(N *object);
111
112 Remove \a object from the list.  \a object must not be null.
113 */
114
115 /*!
116 \fn N *QIntrusiveList::first() const
117
118 Returns the first entry in this list, or null if the list is empty.
119 */
120
121 /*!
122 \fn N *QIntrusiveList::next(N *current)
123
124 Returns the next object after \a current, or null if \a current is the last object.  \a current cannot be null.
125 */
126
127 /*!
128 \fn iterator QIntrusiveList::begin()
129
130 Returns an STL-style interator pointing to the first item in the list.
131
132 \sa end()
133 */
134
135 /*!
136 \fn iterator QIntrusiveList::end()
137
138 Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
139
140 \sa begin()
141 */
142
143 /*!
144 iterator &QInplacelist::iterator::erase()
145
146 Remove the current object from the list, and return an iterator to the next element.
147 */
148
149
150 /*!
151 \fn QIntrusiveListNode::QIntrusiveListNode()
152
153 Create a QIntrusiveListNode.
154 */
155
156 /*!
157 \fn QIntrusiveListNode::~QIntrusiveListNode()
158
159 Destroy the QIntrusiveListNode.  If the node is in a list, it is removed.
160 */
161
162 /*!
163 \fn void QIntrusiveListNode::remove()
164
165 If in a list, remove this node otherwise do nothing.
166 */
167
168 /*!
169 \fn bool QIntrusiveListNode::isInList() const
170
171 Returns true if this node is in a list, false otherwise.
172 */
173