1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include "Qt3Support/q3ptrcollection.h"
34
class Q_COMPAT_EXPORT Q3LNode
37
friend class Q3GListIterator;
38
friend class Q3GListStdIterator;
40
Q3PtrCollection::Item getData() { return data; }
42
Q3PtrCollection::Item data;
45
Q3LNode( Q3PtrCollection::Item d ) { data = d; }
48
class Q3GListIteratorList; // internal helper class
50
class Q_COMPAT_EXPORT Q3GList : public Q3PtrCollection // doubly linked generic list
52
friend class Q3GListIterator;
53
friend class Q3GListIteratorList;
54
friend class Q3GVector; // needed by Q3GVector::toList
56
uint count() const; // return number of nodes
58
#ifndef QT_NO_DATASTREAM
59
QDataStream &read( QDataStream & ); // read list from stream
60
QDataStream &write( QDataStream & ) const; // write list to stream
63
Q3GList(); // create empty list
64
Q3GList( const Q3GList & ); // make copy of other list
67
Q3GList &operator=( const Q3GList & ); // assign from other list
68
bool operator==( const Q3GList& ) const;
70
void inSort( Q3PtrCollection::Item ); // add item sorted in list
71
void append( Q3PtrCollection::Item ); // add item at end of list
72
bool insertAt( uint index, Q3PtrCollection::Item ); // add item at i'th position
73
void relinkNode( Q3LNode * ); // relink as first item
74
bool removeNode( Q3LNode * ); // remove node
75
bool remove( Q3PtrCollection::Item = 0 ); // remove item (0=current)
76
bool removeRef( Q3PtrCollection::Item = 0 ); // remove item (0=current)
77
bool removeFirst(); // remove first item
78
bool removeLast(); // remove last item
79
bool removeAt( uint ); // remove item at i'th position
80
bool replaceAt( uint, Q3PtrCollection::Item ); // replace item at position i with item
81
Q3PtrCollection::Item takeNode( Q3LNode * ); // take out node
82
Q3PtrCollection::Item take(); // take out current item
83
Q3PtrCollection::Item takeAt( uint index ); // take out item at i'th pos
84
Q3PtrCollection::Item takeFirst(); // take out first item
85
Q3PtrCollection::Item takeLast(); // take out last item
87
void sort(); // sort all items;
88
void clear(); // remove all items
90
int findRef( Q3PtrCollection::Item, bool = true ); // find exact item in list
91
int find( Q3PtrCollection::Item, bool = true ); // find equal item in list
93
uint containsRef( Q3PtrCollection::Item ) const; // get number of exact matches
94
uint contains( Q3PtrCollection::Item ) const; // get number of equal matches
96
Q3PtrCollection::Item at( uint index ); // access item at i'th pos
97
int at() const; // get current index
98
Q3LNode *currentNode() const; // get current node
100
Q3PtrCollection::Item get() const; // get current item
102
Q3PtrCollection::Item cfirst() const; // get ptr to first list item
103
Q3PtrCollection::Item clast() const; // get ptr to last list item
104
Q3PtrCollection::Item first(); // set first item in list curr
105
Q3PtrCollection::Item last(); // set last item in list curr
106
Q3PtrCollection::Item next(); // set next item in list curr
107
Q3PtrCollection::Item prev(); // set prev item in list curr
109
void toVector( Q3GVector * ) const; // put items in vector
111
virtual int compareItems( Q3PtrCollection::Item, Q3PtrCollection::Item );
113
#ifndef QT_NO_DATASTREAM
114
virtual QDataStream &read( QDataStream &, Q3PtrCollection::Item & );
115
virtual QDataStream &write( QDataStream &, Q3PtrCollection::Item ) const;
118
Q3LNode* begin() const { return firstNode; }
119
Q3LNode* end() const { return 0; }
120
Q3LNode* erase( Q3LNode* it );
123
void prepend( Q3PtrCollection::Item ); // add item at start of list
125
void heapSortPushDown( Q3PtrCollection::Item* heap, int first, int last );
127
Q3LNode *firstNode; // first node
128
Q3LNode *lastNode; // last node
129
Q3LNode *curNode; // current node
130
int curIndex; // current index
131
uint numNodes; // number of nodes
132
Q3GListIteratorList *iterators; // list of iterators
134
Q3LNode *locate( uint ); // get node at i'th pos
135
Q3LNode *unlink(); // unlink node
139
inline uint Q3GList::count() const
144
inline bool Q3GList::removeFirst()
150
inline bool Q3GList::removeLast()
156
inline int Q3GList::at() const
161
inline Q3PtrCollection::Item Q3GList::at( uint index )
163
Q3LNode *n = locate( index );
164
return n ? n->data : 0;
167
inline Q3LNode *Q3GList::currentNode() const
172
inline Q3PtrCollection::Item Q3GList::get() const
174
return curNode ? curNode->data : 0;
177
inline Q3PtrCollection::Item Q3GList::cfirst() const
179
return firstNode ? firstNode->data : 0;
182
inline Q3PtrCollection::Item Q3GList::clast() const
184
return lastNode ? lastNode->data : 0;
188
/*****************************************************************************
189
Q3GList stream functions
190
*****************************************************************************/
192
#ifndef QT_NO_DATASTREAM
193
Q_COMPAT_EXPORT QDataStream &operator>>( QDataStream &, Q3GList & );
194
Q_COMPAT_EXPORT QDataStream &operator<<( QDataStream &, const Q3GList & );
197
/*****************************************************************************
198
Q3GListIterator class
199
*****************************************************************************/
201
class Q_COMPAT_EXPORT Q3GListIterator // Q3GList iterator
203
friend class Q3GList;
204
friend class Q3GListIteratorList;
206
Q3GListIterator( const Q3GList & );
207
Q3GListIterator( const Q3GListIterator & );
208
Q3GListIterator &operator=( const Q3GListIterator & );
211
bool atFirst() const; // test if at first item
212
bool atLast() const; // test if at last item
213
Q3PtrCollection::Item toFirst(); // move to first item
214
Q3PtrCollection::Item toLast(); // move to last item
216
Q3PtrCollection::Item get() const; // get current item
217
Q3PtrCollection::Item operator()(); // get current and move to next
218
Q3PtrCollection::Item operator++(); // move to next item (prefix)
219
Q3PtrCollection::Item operator+=(uint); // move n positions forward
220
Q3PtrCollection::Item operator--(); // move to prev item (prefix)
221
Q3PtrCollection::Item operator-=(uint); // move n positions backward
224
Q3GList *list; // reference to list
227
Q3LNode *curNode; // current node in list
231
inline bool Q3GListIterator::atFirst() const
233
return curNode == list->firstNode;
236
inline bool Q3GListIterator::atLast() const
238
return curNode == list->lastNode;
241
inline Q3PtrCollection::Item Q3GListIterator::get() const
243
return curNode ? curNode->data : 0;
246
class Q_COMPAT_EXPORT Q3GListStdIterator
249
inline Q3GListStdIterator( Q3LNode* n ) : node( n ){}
250
inline operator Q3LNode* () { return node; }
252
inline Q3LNode *next() { return node->next; }