Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qglist.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of QGList and QGListIterator classes 00005 ** 00006 ** Created : 920624 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file is part of the tools module of the Qt GUI Toolkit. 00011 ** 00012 ** This file may be distributed under the terms of the Q Public License 00013 ** as defined by Trolltech ASA of Norway and appearing in the file 00014 ** LICENSE.QPL included in the packaging of this file. 00015 ** 00016 ** This file may be distributed and/or modified under the terms of the 00017 ** GNU General Public License version 2 as published by the Free Software 00018 ** Foundation and appearing in the file LICENSE.GPL included in the 00019 ** packaging of this file. 00020 ** 00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00022 ** licenses may use this file in accordance with the Qt Commercial License 00023 ** Agreement provided with the Software. 00024 ** 00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00027 ** 00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00029 ** information about Qt Commercial License Agreements. 00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00032 ** 00033 ** Contact info@trolltech.com if any conditions of this licensing are 00034 ** not clear to you. 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 friend class QGListStdIterator; 00050 public: 00051 QPtrCollection::Item getData() { return data; } 00052 private: 00053 QPtrCollection::Item data; 00054 QLNode *prev; 00055 QLNode *next; 00056 QLNode( QPtrCollection::Item d ) { data = d; } 00057 }; 00058 00059 class QGListIteratorList; // internal helper class 00060 00061 class Q_EXPORT QGList : public QPtrCollection // doubly linked generic list 00062 { 00063 friend class QGListIterator; 00064 friend class QGListIteratorList; 00065 friend class QGVector; // needed by QGVector::toList 00066 public: 00067 uint count() const; // return number of nodes 00068 00069 #ifndef QT_NO_DATASTREAM 00070 QDataStream &read( QDataStream & ); // read list from stream 00071 QDataStream &write( QDataStream & ) const; // write list to stream 00072 #endif 00073 protected: 00074 QGList(); // create empty list 00075 QGList( const QGList & ); // make copy of other list 00076 virtual ~QGList(); 00077 00078 QGList &operator=( const QGList & ); // assign from other list 00079 bool operator==( const QGList& ) const; 00080 00081 void inSort( QPtrCollection::Item ); // add item sorted in list 00082 void append( QPtrCollection::Item ); // add item at end of list 00083 bool insertAt( uint index, QPtrCollection::Item ); // add item at i'th position 00084 void relinkNode( QLNode * ); // relink as first item 00085 bool removeNode( QLNode * ); // remove node 00086 bool remove( QPtrCollection::Item = 0 ); // remove item (0=current) 00087 bool removeRef( QPtrCollection::Item = 0 ); // remove item (0=current) 00088 bool removeFirst(); // remove first item 00089 bool removeLast(); // remove last item 00090 bool removeAt( uint ); // remove item at i'th position 00091 bool replaceAt( uint, QPtrCollection::Item ); // replace item at position i with item 00092 QPtrCollection::Item takeNode( QLNode * ); // take out node 00093 QPtrCollection::Item take(); // take out current item 00094 QPtrCollection::Item takeAt( uint index ); // take out item at i'th pos 00095 QPtrCollection::Item takeFirst(); // take out first item 00096 QPtrCollection::Item takeLast(); // take out last item 00097 00098 void sort(); // sort all items; 00099 void clear(); // remove all items 00100 00101 int findRef( QPtrCollection::Item, bool = TRUE ); // find exact item in list 00102 int find( QPtrCollection::Item, bool = TRUE ); // find equal item in list 00103 00104 uint containsRef( QPtrCollection::Item ) const; // get number of exact matches 00105 uint contains( QPtrCollection::Item ) const; // get number of equal matches 00106 00107 QPtrCollection::Item at( uint index ); // access item at i'th pos 00108 int at() const; // get current index 00109 QLNode *currentNode() const; // get current node 00110 00111 QPtrCollection::Item get() const; // get current item 00112 00113 QPtrCollection::Item cfirst() const; // get ptr to first list item 00114 QPtrCollection::Item clast() const; // get ptr to last list item 00115 QPtrCollection::Item first(); // set first item in list curr 00116 QPtrCollection::Item last(); // set last item in list curr 00117 QPtrCollection::Item next(); // set next item in list curr 00118 QPtrCollection::Item prev(); // set prev item in list curr 00119 00120 void toVector( QGVector * ) const; // put items in vector 00121 00122 virtual int compareItems( QPtrCollection::Item, QPtrCollection::Item ); 00123 00124 #ifndef QT_NO_DATASTREAM 00125 virtual QDataStream &read( QDataStream &, QPtrCollection::Item & ); 00126 virtual QDataStream &write( QDataStream &, QPtrCollection::Item ) const; 00127 #endif 00128 00129 QLNode* begin() const { return firstNode; } 00130 QLNode* end() const { return 0; } 00131 QLNode* erase( QLNode* it ); 00132 00133 private: 00134 void prepend( QPtrCollection::Item ); // add item at start of list 00135 00136 void heapSortPushDown( QPtrCollection::Item* heap, int first, int last ); 00137 00138 QLNode *firstNode; // first node 00139 QLNode *lastNode; // last node 00140 QLNode *curNode; // current node 00141 int curIndex; // current index 00142 uint numNodes; // number of nodes 00143 QGListIteratorList *iterators; // list of iterators 00144 00145 QLNode *locate( uint ); // get node at i'th pos 00146 QLNode *unlink(); // unlink node 00147 }; 00148 00149 00150 inline uint QGList::count() const 00151 { 00152 return numNodes; 00153 } 00154 00155 inline bool QGList::removeFirst() 00156 { 00157 first(); 00158 return remove(); 00159 } 00160 00161 inline bool QGList::removeLast() 00162 { 00163 last(); 00164 return remove(); 00165 } 00166 00167 inline int QGList::at() const 00168 { 00169 return curIndex; 00170 } 00171 00172 inline QPtrCollection::Item QGList::at( uint index ) 00173 { 00174 QLNode *n = locate( index ); 00175 return n ? n->data : 0; 00176 } 00177 00178 inline QLNode *QGList::currentNode() const 00179 { 00180 return curNode; 00181 } 00182 00183 inline QPtrCollection::Item QGList::get() const 00184 { 00185 return curNode ? curNode->data : 0; 00186 } 00187 00188 inline QPtrCollection::Item QGList::cfirst() const 00189 { 00190 return firstNode ? firstNode->data : 0; 00191 } 00192 00193 inline QPtrCollection::Item QGList::clast() const 00194 { 00195 return lastNode ? lastNode->data : 0; 00196 } 00197 00198 00199 /***************************************************************************** 00200 QGList stream functions 00201 *****************************************************************************/ 00202 00203 #ifndef QT_NO_DATASTREAM 00204 Q_EXPORT QDataStream &operator>>( QDataStream &, QGList & ); 00205 Q_EXPORT QDataStream &operator<<( QDataStream &, const QGList & ); 00206 #endif 00207 00208 /***************************************************************************** 00209 QGListIterator class 00210 *****************************************************************************/ 00211 00212 class Q_EXPORT QGListIterator // QGList iterator 00213 { 00214 friend class QGList; 00215 friend class QGListIteratorList; 00216 protected: 00217 QGListIterator( const QGList & ); 00218 QGListIterator( const QGListIterator & ); 00219 QGListIterator &operator=( const QGListIterator & ); 00220 ~QGListIterator(); 00221 00222 bool atFirst() const; // test if at first item 00223 bool atLast() const; // test if at last item 00224 QPtrCollection::Item toFirst(); // move to first item 00225 QPtrCollection::Item toLast(); // move to last item 00226 00227 QPtrCollection::Item get() const; // get current item 00228 QPtrCollection::Item operator()(); // get current and move to next 00229 QPtrCollection::Item operator++(); // move to next item (prefix) 00230 QPtrCollection::Item operator+=(uint); // move n positions forward 00231 QPtrCollection::Item operator--(); // move to prev item (prefix) 00232 QPtrCollection::Item operator-=(uint); // move n positions backward 00233 00234 protected: 00235 QGList *list; // reference to list 00236 00237 private: 00238 QLNode *curNode; // current node in list 00239 }; 00240 00241 00242 inline bool QGListIterator::atFirst() const 00243 { 00244 return curNode == list->firstNode; 00245 } 00246 00247 inline bool QGListIterator::atLast() const 00248 { 00249 return curNode == list->lastNode; 00250 } 00251 00252 inline QPtrCollection::Item QGListIterator::get() const 00253 { 00254 return curNode ? curNode->data : 0; 00255 } 00256 00257 class Q_EXPORT QGListStdIterator 00258 { 00259 public: 00260 inline QGListStdIterator( QLNode* n ) : node( n ){} 00261 inline operator QLNode* () { return node; } 00262 protected: 00263 inline QLNode *next() { return node->next; } 00264 QLNode *node; 00265 }; 00266 00267 00268 #endif // QGLIST_H