-rw-r--r-- | qmake/include/qglist.h | 252 |
1 files changed, 252 insertions, 0 deletions
diff --git a/qmake/include/qglist.h b/qmake/include/qglist.h new file mode 100644 index 0000000..d6db3ed --- a/dev/null +++ b/qmake/include/qglist.h | |||
@@ -0,0 +1,252 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Definition of QGList and QGListIterator classes | ||
5 | ** | ||
6 | ** Created : 920624 | ||
7 | ** | ||
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | ||
9 | ** | ||
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | ||
11 | ** | ||
12 | ** This file may be distributed under the terms of the Q Public License | ||
13 | ** as defined by Trolltech AS of Norway and appearing in the file | ||
14 | ** LICENSE.QPL included in the packaging of this file. | ||
15 | ** | ||
16 | ** This file may be distributed and/or modified under the terms of the | ||
17 | ** GNU General Public License version 2 as published by the Free Software | ||
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
19 | ** packaging of this file. | ||
20 | ** | ||
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
22 | ** licenses may use this file in accordance with the Qt Commercial License | ||
23 | ** Agreement provided with the Software. | ||
24 | ** | ||
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
27 | ** | ||
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
29 | ** information about Qt Commercial License Agreements. | ||
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
32 | ** | ||
33 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
34 | ** not clear to you. | ||
35 | ** | ||
36 | **********************************************************************/ | ||
37 | |||
38 | #ifndef QGLIST_H | ||
39 | #define QGLIST_H | ||
40 | |||
41 | #ifndef QT_H | ||
42 | #include "qptrcollection.h" | ||
43 | #endif // QT_H | ||
44 | |||
45 | class Q_EXPORT QLNode | ||
46 | { | ||
47 | friend class QGList; | ||
48 | friend class QGListIterator; | ||
49 | public: | ||
50 | QPtrCollection::Item getData(){ return data; } | ||
51 | private: | ||
52 | QPtrCollection::Item data; | ||
53 | QLNode *prev; | ||
54 | QLNode *next; | ||
55 | QLNode( QPtrCollection::Item d ) { data = d; } | ||
56 | }; | ||
57 | |||
58 | class QGListIteratorList; // internal helper class | ||
59 | |||
60 | class Q_EXPORT QGList : public QPtrCollection// doubly linked generic list | ||
61 | { | ||
62 | friend class QGListIterator; | ||
63 | friend class QGListIteratorList; | ||
64 | friend class QGVector; // needed by QGVector::toList | ||
65 | public: | ||
66 | uint count() const; // return number of nodes | ||
67 | |||
68 | #ifndef QT_NO_DATASTREAM | ||
69 | QDataStream &read( QDataStream & ); // read list from stream | ||
70 | QDataStream &write( QDataStream & ) const;// write list to stream | ||
71 | #endif | ||
72 | protected: | ||
73 | QGList(); // create empty list | ||
74 | QGList( const QGList & ); // make copy of other list | ||
75 | virtual ~QGList(); | ||
76 | |||
77 | QGList &operator=( const QGList & );// assign from other list | ||
78 | bool operator==( const QGList& ) const; | ||
79 | |||
80 | void inSort( QPtrCollection::Item ); // add item sorted in list | ||
81 | void append( QPtrCollection::Item ); // add item at end of list | ||
82 | bool insertAt( uint index, QPtrCollection::Item ); // add item at i'th position | ||
83 | void relinkNode( QLNode * ); // relink as first item | ||
84 | bool removeNode( QLNode * ); // remove node | ||
85 | bool remove( QPtrCollection::Item = 0 );// remove item (0=current) | ||
86 | bool removeRef( QPtrCollection::Item = 0 );// remove item (0=current) | ||
87 | bool removeFirst(); // remove first item | ||
88 | bool removeLast(); // remove last item | ||
89 | bool removeAt( uint ); // remove item at i'th position | ||
90 | bool replaceAt( uint, QPtrCollection::Item ); // replace item at position i with item | ||
91 | QPtrCollection::Item takeNode( QLNode * );// take out node | ||
92 | QPtrCollection::Item take(); // take out current item | ||
93 | QPtrCollection::Item takeAt( uint index );// take out item at i'th pos | ||
94 | QPtrCollection::Item takeFirst(); // take out first item | ||
95 | QPtrCollection::Item takeLast(); // take out last item | ||
96 | |||
97 | void sort(); // sort all items; | ||
98 | void clear(); // remove all items | ||
99 | |||
100 | int findRef( QPtrCollection::Item, bool = TRUE ); // find exact item in list | ||
101 | int find( QPtrCollection::Item, bool = TRUE ); // find equal item in list | ||
102 | |||
103 | uint containsRef( QPtrCollection::Item ) const;// get number of exact matches | ||
104 | uint contains( QPtrCollection::Item ) const;// get number of equal matches | ||
105 | |||
106 | QPtrCollection::Item at( uint index );// access item at i'th pos | ||
107 | int at() const; // get current index | ||
108 | QLNode *currentNode() const; // get current node | ||
109 | |||
110 | QPtrCollection::Item get() const; // get current item | ||
111 | |||
112 | QPtrCollection::Item cfirst() const;// get ptr to first list item | ||
113 | QPtrCollection::Item clast() const;// get ptr to last list item | ||
114 | QPtrCollection::Item first(); // set first item in list curr | ||
115 | QPtrCollection::Item last(); // set last item in list curr | ||
116 | QPtrCollection::Item next(); // set next item in list curr | ||
117 | QPtrCollection::Item prev(); // set prev item in list curr | ||
118 | |||
119 | void toVector( QGVector * ) const; // put items in vector | ||
120 | |||
121 | virtual int compareItems( QPtrCollection::Item, QPtrCollection::Item ); | ||
122 | |||
123 | #ifndef QT_NO_DATASTREAM | ||
124 | virtual QDataStream &read( QDataStream &, QPtrCollection::Item & ); | ||
125 | virtual QDataStream &write( QDataStream &, QPtrCollection::Item ) const; | ||
126 | #endif | ||
127 | private: | ||
128 | void prepend( QPtrCollection::Item );// add item at start of list | ||
129 | |||
130 | void heapSortPushDown( QPtrCollection::Item* heap, int first, int last ); | ||
131 | |||
132 | QLNode *firstNode; // first node | ||
133 | QLNode *lastNode; // last node | ||
134 | QLNode *curNode; // current node | ||
135 | int curIndex; // current index | ||
136 | uint numNodes; // number of nodes | ||
137 | QGListIteratorList *iterators; // list of iterators | ||
138 | |||
139 | QLNode *locate( uint ); // get node at i'th pos | ||
140 | QLNode *unlink(); // unlink node | ||
141 | }; | ||
142 | |||
143 | |||
144 | inline uint QGList::count() const | ||
145 | { | ||
146 | return numNodes; | ||
147 | } | ||
148 | |||
149 | inline bool QGList::removeFirst() | ||
150 | { | ||
151 | first(); | ||
152 | return remove(); | ||
153 | } | ||
154 | |||
155 | inline bool QGList::removeLast() | ||
156 | { | ||
157 | last(); | ||
158 | return remove(); | ||
159 | } | ||
160 | |||
161 | inline int QGList::at() const | ||
162 | { | ||
163 | return curIndex; | ||
164 | } | ||
165 | |||
166 | inline QPtrCollection::Item QGList::at( uint index ) | ||
167 | { | ||
168 | QLNode *n = locate( index ); | ||
169 | return n ? n->data : 0; | ||
170 | } | ||
171 | |||
172 | inline QLNode *QGList::currentNode() const | ||
173 | { | ||
174 | return curNode; | ||
175 | } | ||
176 | |||
177 | inline QPtrCollection::Item QGList::get() const | ||
178 | { | ||
179 | return curNode ? curNode->data : 0; | ||
180 | } | ||
181 | |||
182 | inline QPtrCollection::Item QGList::cfirst() const | ||
183 | { | ||
184 | return firstNode ? firstNode->data : 0; | ||
185 | } | ||
186 | |||
187 | inline QPtrCollection::Item QGList::clast() const | ||
188 | { | ||
189 | return lastNode ? lastNode->data : 0; | ||
190 | } | ||
191 | |||
192 | |||
193 | /***************************************************************************** | ||
194 | QGList stream functions | ||
195 | *****************************************************************************/ | ||
196 | |||
197 | #ifndef QT_NO_DATASTREAM | ||
198 | Q_EXPORT QDataStream &operator>>( QDataStream &, QGList & ); | ||
199 | Q_EXPORT QDataStream &operator<<( QDataStream &, const QGList & ); | ||
200 | #endif | ||
201 | |||
202 | /***************************************************************************** | ||
203 | QGListIterator class | ||
204 | *****************************************************************************/ | ||
205 | |||
206 | class Q_EXPORT QGListIterator // QGList iterator | ||
207 | { | ||
208 | friend class QGList; | ||
209 | friend class QGListIteratorList; | ||
210 | protected: | ||
211 | QGListIterator( const QGList & ); | ||
212 | QGListIterator( const QGListIterator & ); | ||
213 | QGListIterator &operator=( const QGListIterator & ); | ||
214 | ~QGListIterator(); | ||
215 | |||
216 | bool atFirst() const; // test if at first item | ||
217 | bool atLast() const; // test if at last item | ||
218 | QPtrCollection::Item toFirst(); // move to first item | ||
219 | QPtrCollection::Item toLast(); // move to last item | ||
220 | |||
221 | QPtrCollection::Item get() const; // get current item | ||
222 | QPtrCollection::Item operator()(); // get current and move to next | ||
223 | QPtrCollection::Item operator++(); // move to next item (prefix) | ||
224 | QPtrCollection::Item operator+=(uint); // move n positions forward | ||
225 | QPtrCollection::Item operator--(); // move to prev item (prefix) | ||
226 | QPtrCollection::Item operator-=(uint); // move n positions backward | ||
227 | |||
228 | protected: | ||
229 | QGList *list; // reference to list | ||
230 | |||
231 | private: | ||
232 | QLNode *curNode; // current node in list | ||
233 | }; | ||
234 | |||
235 | |||
236 | inline bool QGListIterator::atFirst() const | ||
237 | { | ||
238 | return curNode == list->firstNode; | ||
239 | } | ||
240 | |||
241 | inline bool QGListIterator::atLast() const | ||
242 | { | ||
243 | return curNode == list->lastNode; | ||
244 | } | ||
245 | |||
246 | inline QPtrCollection::Item QGListIterator::get() const | ||
247 | { | ||
248 | return curNode ? curNode->data : 0; | ||
249 | } | ||
250 | |||
251 | |||
252 | #endif// QGLIST_H | ||