Improve QJSValueIterator implementation.
[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 ** 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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
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