00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef QGLIST_H
00039 #define QGLIST_H
00040
00041 #ifndef QT_H
00042 #include "qptrcollection.h"
00043 #endif // QT_H
00044
00045 class Q_EXPORT QLNode
00046 {
00047 friend class QGList;
00048 friend class QGListIterator;
00049 public:
00050 QPtrCollection::Item getData() { return data; }
00051 private:
00052 QPtrCollection::Item data;
00053 QLNode *prev;
00054 QLNode *next;
00055 QLNode( QPtrCollection::Item d ) { data = d; }
00056 };
00057
00058 class QGListIteratorList;
00059
00060 class Q_EXPORT QGList : public QPtrCollection
00061 {
00062 friend class QGListIterator;
00063 friend class QGListIteratorList;
00064 friend class QGVector;
00065 public:
00066 uint count() const;
00067
00068 #ifndef QT_NO_DATASTREAM
00069 QDataStream &read( QDataStream & );
00070 QDataStream &write( QDataStream & ) const;
00071 #endif
00072 protected:
00073 QGList();
00074 QGList( const QGList & );
00075 virtual ~QGList();
00076
00077 QGList &operator=( const QGList & );
00078 bool operator==( const QGList& ) const;
00079
00080 void inSort( QPtrCollection::Item );
00081 void append( QPtrCollection::Item );
00082 bool insertAt( uint index, QPtrCollection::Item );
00083 void relinkNode( QLNode * );
00084 bool removeNode( QLNode * );
00085 bool remove( QPtrCollection::Item = 0 );
00086 bool removeRef( QPtrCollection::Item = 0 );
00087 bool removeFirst();
00088 bool removeLast();
00089 bool removeAt( uint );
00090 bool replaceAt( uint, QPtrCollection::Item );
00091 QPtrCollection::Item takeNode( QLNode * );
00092 QPtrCollection::Item take();
00093 QPtrCollection::Item takeAt( uint index );
00094 QPtrCollection::Item takeFirst();
00095 QPtrCollection::Item takeLast();
00096
00097 void sort();
00098 void clear();
00099
00100 int findRef( QPtrCollection::Item, bool = TRUE );
00101 int find( QPtrCollection::Item, bool = TRUE );
00102
00103 uint containsRef( QPtrCollection::Item ) const;
00104 uint contains( QPtrCollection::Item ) const;
00105
00106 QPtrCollection::Item at( uint index );
00107 int at() const;
00108 QLNode *currentNode() const;
00109
00110 QPtrCollection::Item get() const;
00111
00112 QPtrCollection::Item cfirst() const;
00113 QPtrCollection::Item clast() const;
00114 QPtrCollection::Item first();
00115 QPtrCollection::Item last();
00116 QPtrCollection::Item next();
00117 QPtrCollection::Item prev();
00118
00119 void toVector( QGVector * ) const;
00120
00121 virtual int compareItems( QPtrCollection::Item, QPtrCollection::Item );
00122
00123 #ifndef QT_NO_DATASTREAM
00124 virtual QDataStream &read( QDataStream &, QPtrCollection::Item & );
00125 virtual QDataStream &write( QDataStream &, QPtrCollection::Item ) const;
00126 #endif
00127 private:
00128 void prepend( QPtrCollection::Item );
00129
00130 void heapSortPushDown( QPtrCollection::Item* heap, int first, int last );
00131
00132 QLNode *firstNode;
00133 QLNode *lastNode;
00134 QLNode *curNode;
00135 int curIndex;
00136 uint numNodes;
00137 QGListIteratorList *iterators;
00138
00139 QLNode *locate( uint );
00140 QLNode *unlink();
00141 };
00142
00143
00144 inline uint QGList::count() const
00145 {
00146 return numNodes;
00147 }
00148
00149 inline bool QGList::removeFirst()
00150 {
00151 first();
00152 return remove();
00153 }
00154
00155 inline bool QGList::removeLast()
00156 {
00157 last();
00158 return remove();
00159 }
00160
00161 inline int QGList::at() const
00162 {
00163 return curIndex;
00164 }
00165
00166 inline QPtrCollection::Item QGList::at( uint index )
00167 {
00168 QLNode *n = locate( index );
00169 return n ? n->data : 0;
00170 }
00171
00172 inline QLNode *QGList::currentNode() const
00173 {
00174 return curNode;
00175 }
00176
00177 inline QPtrCollection::Item QGList::get() const
00178 {
00179 return curNode ? curNode->data : 0;
00180 }
00181
00182 inline QPtrCollection::Item QGList::cfirst() const
00183 {
00184 return firstNode ? firstNode->data : 0;
00185 }
00186
00187 inline QPtrCollection::Item QGList::clast() const
00188 {
00189 return lastNode ? lastNode->data : 0;
00190 }
00191
00192
00193
00194
00195
00196
00197 #ifndef QT_NO_DATASTREAM
00198 Q_EXPORT QDataStream &operator>>( QDataStream &, QGList & );
00199 Q_EXPORT QDataStream &operator<<( QDataStream &, const QGList & );
00200 #endif
00201
00202
00203
00204
00205
00206 class Q_EXPORT QGListIterator
00207 {
00208 friend class QGList;
00209 friend class QGListIteratorList;
00210 protected:
00211 QGListIterator( const QGList & );
00212 QGListIterator( const QGListIterator & );
00213 QGListIterator &operator=( const QGListIterator & );
00214 ~QGListIterator();
00215
00216 bool atFirst() const;
00217 bool atLast() const;
00218 QPtrCollection::Item toFirst();
00219 QPtrCollection::Item toLast();
00220
00221 QPtrCollection::Item get() const;
00222 QPtrCollection::Item operator()();
00223 QPtrCollection::Item operator++();
00224 QPtrCollection::Item operator+=(uint);
00225 QPtrCollection::Item operator--();
00226 QPtrCollection::Item operator-=(uint);
00227
00228 protected:
00229 QGList *list;
00230
00231 private:
00232 QLNode *curNode;
00233 };
00234
00235
00236 inline bool QGListIterator::atFirst() const
00237 {
00238 return curNode == list->firstNode;
00239 }
00240
00241 inline bool QGListIterator::atLast() const
00242 {
00243 return curNode == list->lastNode;
00244 }
00245
00246 inline QPtrCollection::Item QGListIterator::get() const
00247 {
00248 return curNode ? curNode->data : 0;
00249 }
00250
00251
00252 #endif // QGLIST_H