author | kergoth <kergoth> | 2002-11-01 00:10:42 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-11-01 00:10:42 (UTC) |
commit | 5042e3cf0d3514552769e441f5aad590c8eaf967 (patch) (unidiff) | |
tree | 4a5ea45f3519d981a172ab5275bf38c6fa778dec /qmake/include/qvaluelist.h | |
parent | 108c1c753e74e989cc13923086996791428c9af4 (diff) | |
download | opie-5042e3cf0d3514552769e441f5aad590c8eaf967.zip opie-5042e3cf0d3514552769e441f5aad590c8eaf967.tar.gz opie-5042e3cf0d3514552769e441f5aad590c8eaf967.tar.bz2 |
Adding qmake in preperation for new build system
-rw-r--r-- | qmake/include/qvaluelist.h | 665 |
1 files changed, 665 insertions, 0 deletions
diff --git a/qmake/include/qvaluelist.h b/qmake/include/qvaluelist.h new file mode 100644 index 0000000..54f7aec --- a/dev/null +++ b/qmake/include/qvaluelist.h | |||
@@ -0,0 +1,665 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Definition of QValueList class | ||
5 | ** | ||
6 | ** Created : 990406 | ||
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 QVALUELIST_H | ||
39 | #define QVALUELIST_H | ||
40 | |||
41 | #ifndef QT_H | ||
42 | #include "qtl.h" | ||
43 | #include "qshared.h" | ||
44 | #include "qdatastream.h" | ||
45 | #endif // QT_H | ||
46 | |||
47 | #ifndef QT_NO_STL | ||
48 | #include <iterator> | ||
49 | #include <list> | ||
50 | #endif | ||
51 | |||
52 | //#define QT_CHECK_VALUELIST_RANGE | ||
53 | |||
54 | #if defined(Q_CC_MSVC) | ||
55 | #pragma warning(disable:4284) // "return type for operator -> is not a UDT" | ||
56 | #endif | ||
57 | |||
58 | template <class T> | ||
59 | class QValueListNode | ||
60 | { | ||
61 | public: | ||
62 | QValueListNode( const T& t ) : data( t ) { } | ||
63 | QValueListNode() { } | ||
64 | #if defined(Q_TEMPLATEDLL) | ||
65 | // Workaround MS bug in memory de/allocation in DLL vs. EXE | ||
66 | virtual ~QValueListNode() { } | ||
67 | #endif | ||
68 | |||
69 | QValueListNode<T>* next; | ||
70 | QValueListNode<T>* prev; | ||
71 | T data; | ||
72 | }; | ||
73 | |||
74 | template<class T> | ||
75 | class QValueListIterator | ||
76 | { | ||
77 | public: | ||
78 | /** | ||
79 | * Typedefs | ||
80 | */ | ||
81 | typedef QValueListNode<T>* NodePtr; | ||
82 | #ifndef QT_NO_STL | ||
83 | typedef std::bidirectional_iterator_tag iterator_category; | ||
84 | #endif | ||
85 | typedef T value_type; | ||
86 | typedef size_t size_type; | ||
87 | #ifndef QT_NO_STL | ||
88 | typedef ptrdiff_t difference_type; | ||
89 | #else | ||
90 | typedef int difference_type; | ||
91 | #endif | ||
92 | typedef T* pointer; | ||
93 | typedef T& reference; | ||
94 | |||
95 | /** | ||
96 | * Variables | ||
97 | */ | ||
98 | NodePtr node; | ||
99 | |||
100 | /** | ||
101 | * Functions | ||
102 | */ | ||
103 | QValueListIterator() : node( 0 ) {} | ||
104 | QValueListIterator( NodePtr p ) : node( p ) {} | ||
105 | QValueListIterator( const QValueListIterator<T>& it ) : node( it.node ) {} | ||
106 | |||
107 | bool operator==( const QValueListIterator<T>& it ) const { return node == it.node; } | ||
108 | bool operator!=( const QValueListIterator<T>& it ) const { return node != it.node; } | ||
109 | const T& operator*() const { return node->data; } | ||
110 | T& operator*() { return node->data; } | ||
111 | // UDT for T = x* | ||
112 | // T* operator->() const { return &node->data; } | ||
113 | |||
114 | QValueListIterator<T>& operator++() { | ||
115 | node = node->next; | ||
116 | return *this; | ||
117 | } | ||
118 | |||
119 | QValueListIterator<T> operator++(int) { | ||
120 | QValueListIterator<T> tmp = *this; | ||
121 | node = node->next; | ||
122 | return tmp; | ||
123 | } | ||
124 | |||
125 | QValueListIterator<T>& operator--() { | ||
126 | node = node->prev; | ||
127 | return *this; | ||
128 | } | ||
129 | |||
130 | QValueListIterator<T> operator--(int) { | ||
131 | QValueListIterator<T> tmp = *this; | ||
132 | node = node->prev; | ||
133 | return tmp; | ||
134 | } | ||
135 | |||
136 | QValueListIterator<T>& operator+=( int j ) { | ||
137 | while ( j-- ) | ||
138 | node = node->next; | ||
139 | return *this; | ||
140 | } | ||
141 | |||
142 | QValueListIterator<T>& operator-=( int j ) { | ||
143 | while ( j-- ) | ||
144 | node = node->prev; | ||
145 | return *this; | ||
146 | } | ||
147 | |||
148 | }; | ||
149 | |||
150 | template<class T> | ||
151 | class QValueListConstIterator | ||
152 | { | ||
153 | public: | ||
154 | /** | ||
155 | * Typedefs | ||
156 | */ | ||
157 | typedef QValueListNode<T>* NodePtr; | ||
158 | #ifndef QT_NO_STL | ||
159 | typedef std::bidirectional_iterator_tag iterator_category; | ||
160 | #endif | ||
161 | typedef T value_type; | ||
162 | typedef size_t size_type; | ||
163 | #ifndef QT_NO_STL | ||
164 | typedef ptrdiff_t difference_type; | ||
165 | #else | ||
166 | typedef int difference_type; | ||
167 | #endif | ||
168 | typedef const T* pointer; | ||
169 | typedef const T& reference; | ||
170 | |||
171 | /** | ||
172 | * Variables | ||
173 | */ | ||
174 | NodePtr node; | ||
175 | |||
176 | /** | ||
177 | * Functions | ||
178 | */ | ||
179 | QValueListConstIterator() : node( 0 ) {} | ||
180 | QValueListConstIterator( NodePtr p ) : node( p ) {} | ||
181 | QValueListConstIterator( const QValueListConstIterator<T>& it ) : node( it.node ) {} | ||
182 | QValueListConstIterator( const QValueListIterator<T>& it ) : node( it.node ) {} | ||
183 | |||
184 | bool operator==( const QValueListConstIterator<T>& it ) const { return node == it.node; } | ||
185 | bool operator!=( const QValueListConstIterator<T>& it ) const { return node != it.node; } | ||
186 | const T& operator*() const { return node->data; } | ||
187 | // UDT for T = x* | ||
188 | // const T* operator->() const { return &node->data; } | ||
189 | |||
190 | QValueListConstIterator<T>& operator++() { | ||
191 | node = node->next; | ||
192 | return *this; | ||
193 | } | ||
194 | |||
195 | QValueListConstIterator<T> operator++(int) { | ||
196 | QValueListConstIterator<T> tmp = *this; | ||
197 | node = node->next; | ||
198 | return tmp; | ||
199 | } | ||
200 | |||
201 | QValueListConstIterator<T>& operator--() { | ||
202 | node = node->prev; | ||
203 | return *this; | ||
204 | } | ||
205 | |||
206 | QValueListConstIterator<T> operator--(int) { | ||
207 | QValueListConstIterator<T> tmp = *this; | ||
208 | node = node->prev; | ||
209 | return tmp; | ||
210 | } | ||
211 | }; | ||
212 | |||
213 | template <class T> | ||
214 | class QValueListPrivate : public QShared | ||
215 | { | ||
216 | public: | ||
217 | /** | ||
218 | * Typedefs | ||
219 | */ | ||
220 | typedef QValueListIterator<T> Iterator; | ||
221 | typedef QValueListConstIterator<T> ConstIterator; | ||
222 | typedef QValueListNode<T> Node; | ||
223 | typedef QValueListNode<T>* NodePtr; | ||
224 | typedef size_t size_type; | ||
225 | |||
226 | /** | ||
227 | * Functions | ||
228 | */ | ||
229 | QValueListPrivate(); | ||
230 | QValueListPrivate( const QValueListPrivate<T>& _p ); | ||
231 | |||
232 | void derefAndDelete() // ### hack to get around hp-cc brain damage | ||
233 | { | ||
234 | if ( deref() ) | ||
235 | delete this; | ||
236 | } | ||
237 | |||
238 | #if defined(Q_TEMPLATEDLL) | ||
239 | // Workaround MS bug in memory de/allocation in DLL vs. EXE | ||
240 | virtual | ||
241 | #endif | ||
242 | ~QValueListPrivate(); | ||
243 | |||
244 | Iterator insert( Iterator it, const T& x ); | ||
245 | Iterator remove( Iterator it ); | ||
246 | NodePtr find( NodePtr start, const T& x ) const; | ||
247 | int findIndex( NodePtr start, const T& x ) const; | ||
248 | uint contains( const T& x ) const; | ||
249 | uint remove( const T& x ); | ||
250 | NodePtr at( size_type i ) const; | ||
251 | void clear(); | ||
252 | |||
253 | NodePtr node; | ||
254 | size_type nodes; | ||
255 | }; | ||
256 | |||
257 | template <class T> | ||
258 | Q_INLINE_TEMPLATES QValueListPrivate<T>::QValueListPrivate() | ||
259 | { | ||
260 | node = new Node; node->next = node->prev = node; nodes = 0; | ||
261 | } | ||
262 | |||
263 | template <class T> | ||
264 | Q_INLINE_TEMPLATES QValueListPrivate<T>::QValueListPrivate( const QValueListPrivate<T>& _p ) | ||
265 | : QShared() | ||
266 | { | ||
267 | node = new Node; node->next = node->prev = node; nodes = 0; | ||
268 | Iterator b( _p.node->next ); | ||
269 | Iterator e( _p.node ); | ||
270 | Iterator i( node ); | ||
271 | while( b != e ) | ||
272 | insert( i, *b++ ); | ||
273 | } | ||
274 | |||
275 | template <class T> | ||
276 | Q_INLINE_TEMPLATES QValueListPrivate<T>::~QValueListPrivate() { | ||
277 | NodePtr p = node->next; | ||
278 | while( p != node ) { | ||
279 | NodePtr x = p->next; | ||
280 | delete p; | ||
281 | p = x; | ||
282 | } | ||
283 | delete node; | ||
284 | } | ||
285 | |||
286 | template <class T> | ||
287 | Q_INLINE_TEMPLATES Q_TYPENAME QValueListPrivate<T>::Iterator QValueListPrivate<T>::insert( Q_TYPENAME QValueListPrivate<T>::Iterator it, const T& x ) | ||
288 | { | ||
289 | NodePtr p = new Node( x ); | ||
290 | p->next = it.node; | ||
291 | p->prev = it.node->prev; | ||
292 | it.node->prev->next = p; | ||
293 | it.node->prev = p; | ||
294 | nodes++; | ||
295 | return p; | ||
296 | } | ||
297 | |||
298 | template <class T> | ||
299 | Q_INLINE_TEMPLATES Q_TYPENAME QValueListPrivate<T>::Iterator QValueListPrivate<T>::remove( Q_TYPENAME QValueListPrivate<T>::Iterator it ) | ||
300 | { | ||
301 | Q_ASSERT ( it.node != node ); | ||
302 | NodePtr next = it.node->next; | ||
303 | NodePtr prev = it.node->prev; | ||
304 | prev->next = next; | ||
305 | next->prev = prev; | ||
306 | delete it.node; | ||
307 | nodes--; | ||
308 | return Iterator( next ); | ||
309 | } | ||
310 | |||
311 | template <class T> | ||
312 | Q_INLINE_TEMPLATES Q_TYPENAME QValueListPrivate<T>::NodePtr QValueListPrivate<T>::find( Q_TYPENAME QValueListPrivate<T>::NodePtr start, const T& x ) const | ||
313 | { | ||
314 | ConstIterator first( start ); | ||
315 | ConstIterator last( node ); | ||
316 | while( first != last) { | ||
317 | if ( *first == x ) | ||
318 | return first.node; | ||
319 | ++first; | ||
320 | } | ||
321 | return last.node; | ||
322 | } | ||
323 | |||
324 | template <class T> | ||
325 | Q_INLINE_TEMPLATES int QValueListPrivate<T>::findIndex( Q_TYPENAME QValueListPrivate<T>::NodePtr start, const T& x ) const | ||
326 | { | ||
327 | ConstIterator first( start ); | ||
328 | ConstIterator last( node ); | ||
329 | int pos = 0; | ||
330 | while( first != last) { | ||
331 | if ( *first == x ) | ||
332 | return pos; | ||
333 | ++first; | ||
334 | ++pos; | ||
335 | } | ||
336 | return -1; | ||
337 | } | ||
338 | |||
339 | template <class T> | ||
340 | Q_INLINE_TEMPLATES uint QValueListPrivate<T>::contains( const T& x ) const | ||
341 | { | ||
342 | uint result = 0; | ||
343 | Iterator first = Iterator( node->next ); | ||
344 | Iterator last = Iterator( node ); | ||
345 | while( first != last) { | ||
346 | if ( *first == x ) | ||
347 | ++result; | ||
348 | ++first; | ||
349 | } | ||
350 | return result; | ||
351 | } | ||
352 | |||
353 | template <class T> | ||
354 | Q_INLINE_TEMPLATES uint QValueListPrivate<T>::remove( const T& x ) | ||
355 | { | ||
356 | uint result = 0; | ||
357 | Iterator first = Iterator( node->next ); | ||
358 | Iterator last = Iterator( node ); | ||
359 | while( first != last) { | ||
360 | if ( *first == x ) { | ||
361 | first = remove( first ); | ||
362 | ++result; | ||
363 | } else | ||
364 | ++first; | ||
365 | } | ||
366 | return result; | ||
367 | } | ||
368 | |||
369 | template <class T> | ||
370 | Q_INLINE_TEMPLATES Q_TYPENAME QValueListPrivate<T>::NodePtr QValueListPrivate<T>::at( size_type i ) const | ||
371 | { | ||
372 | Q_ASSERT( i <= nodes ); | ||
373 | NodePtr p = node->next; | ||
374 | for( size_type x = 0; x < i; ++x ) | ||
375 | p = p->next; | ||
376 | return p; | ||
377 | } | ||
378 | |||
379 | template <class T> | ||
380 | Q_INLINE_TEMPLATES void QValueListPrivate<T>::clear() | ||
381 | { | ||
382 | nodes = 0; | ||
383 | NodePtr p = node->next; | ||
384 | while( p != node ) { | ||
385 | NodePtr next = p->next; | ||
386 | delete p; | ||
387 | p = next; | ||
388 | } | ||
389 | node->next = node->prev = node; | ||
390 | } | ||
391 | |||
392 | #ifdef QT_CHECK_RANGE | ||
393 | # if !defined( QT_NO_DEBUG ) && defined( QT_CHECK_VALUELIST_RANGE ) | ||
394 | # define QT_CHECK_INVALID_LIST_ELEMENT if ( empty() ) qWarning( "QValueList: Warning invalid element" ) | ||
395 | # define QT_CHECK_INVALID_LIST_ELEMENT_FATAL Q_ASSERT( !empty() ); | ||
396 | # else | ||
397 | # define QT_CHECK_INVALID_LIST_ELEMENT | ||
398 | # define QT_CHECK_INVALID_LIST_ELEMENT_FATAL | ||
399 | # endif | ||
400 | #else | ||
401 | # define QT_CHECK_INVALID_LIST_ELEMENT | ||
402 | # define QT_CHECK_INVALID_LIST_ELEMENT_FATAL | ||
403 | #endif | ||
404 | |||
405 | template <class T> class QDeepCopy; | ||
406 | |||
407 | template <class T> | ||
408 | class QValueList | ||
409 | { | ||
410 | public: | ||
411 | /** | ||
412 | * Typedefs | ||
413 | */ | ||
414 | typedef QValueListIterator<T> iterator; | ||
415 | typedef QValueListConstIterator<T> const_iterator; | ||
416 | typedef T value_type; | ||
417 | typedef value_type* pointer; | ||
418 | typedef const value_type* const_pointer; | ||
419 | typedef value_type& reference; | ||
420 | typedef const value_type& const_reference; | ||
421 | typedef size_t size_type; | ||
422 | #ifndef QT_NO_STL | ||
423 | typedef ptrdiff_t difference_type; | ||
424 | #else | ||
425 | typedef int difference_type; | ||
426 | #endif | ||
427 | |||
428 | /** | ||
429 | * API | ||
430 | */ | ||
431 | QValueList() { sh = new QValueListPrivate<T>; } | ||
432 | QValueList( const QValueList<T>& l ) { sh = l.sh; sh->ref(); } | ||
433 | #ifndef QT_NO_STL | ||
434 | # ifdef Q_CC_HPACC // HP-UX aCC does require typename in some place | ||
435 | # undef Q_TYPENAME // but not accept them at others. | ||
436 | # define Q_TYPENAME // also doesn't like re-defines ... | ||
437 | # endif | ||
438 | QValueList( const Q_TYPENAME std::list<T>& l ) | ||
439 | { | ||
440 | sh = new QValueListPrivate<T>; | ||
441 | qCopy( l.begin(), l.end(), std::back_inserter( *this ) ); | ||
442 | } | ||
443 | #endif | ||
444 | ~QValueList() { sh->derefAndDelete(); } | ||
445 | |||
446 | QValueList<T>& operator= ( const QValueList<T>& l ) | ||
447 | { | ||
448 | l.sh->ref(); | ||
449 | sh->derefAndDelete(); | ||
450 | sh = l.sh; | ||
451 | return *this; | ||
452 | } | ||
453 | #ifndef QT_NO_STL | ||
454 | QValueList<T>& operator= ( const Q_TYPENAME std::list<T>& l ) | ||
455 | { | ||
456 | detach(); | ||
457 | qCopy( l.begin(), l.end(), std::back_inserter( *this ) ); | ||
458 | return *this; | ||
459 | } | ||
460 | bool operator== ( const Q_TYPENAME std::list<T>& l ) const | ||
461 | { | ||
462 | if ( size() != l.size() ) | ||
463 | return FALSE; | ||
464 | const_iterator it2 = begin(); | ||
465 | #if !defined(Q_CC_MIPS) | ||
466 | typename | ||
467 | #endif | ||
468 | std::list<T>::const_iterator it = l.begin(); | ||
469 | for ( ; it2 != end(); ++it2, ++it ) | ||
470 | if ( !((*it2) == (*it)) ) | ||
471 | return FALSE; | ||
472 | return TRUE; | ||
473 | } | ||
474 | # ifdef Q_CC_HPACC // undo the HP-UX aCC hackery done above | ||
475 | # undef Q_TYPENAME | ||
476 | # define Q_TYPENAME typename | ||
477 | # endif | ||
478 | #endif | ||
479 | bool operator== ( const QValueList<T>& l ) const; | ||
480 | bool operator!= ( const QValueList<T>& l ) const { return !( *this == l ); } | ||
481 | iterator begin() { detach(); return iterator( sh->node->next ); } | ||
482 | const_iterator begin() const { return const_iterator( sh->node->next ); } | ||
483 | iterator end() { detach(); return iterator( sh->node ); } | ||
484 | const_iterator end() const { return const_iterator( sh->node ); } | ||
485 | iterator insert( iterator it, const T& x ) { detach(); return sh->insert( it, x ); } | ||
486 | uint remove( const T& x ) { detach(); return sh->remove( x ); } | ||
487 | void clear(); | ||
488 | |||
489 | QValueList<T>& operator<< ( const T& x ) | ||
490 | { | ||
491 | append( x ); | ||
492 | return *this; | ||
493 | } | ||
494 | |||
495 | size_type size() const { return sh->nodes; } | ||
496 | bool empty() const { return sh->nodes == 0; } | ||
497 | void push_front( const T& x ) { detach(); sh->insert( begin(), x ); } | ||
498 | void push_back( const T& x ) { detach(); sh->insert( end(), x ); } | ||
499 | iterator erase( iterator pos ) { detach(); return sh->remove( pos ); } | ||
500 | iterator erase( iterator first, iterator last ); | ||
501 | reference front() { QT_CHECK_INVALID_LIST_ELEMENT_FATAL; return *begin(); } | ||
502 | const_reference front() const { QT_CHECK_INVALID_LIST_ELEMENT_FATAL; return *begin(); } | ||
503 | reference back() { QT_CHECK_INVALID_LIST_ELEMENT_FATAL; return *(--end()); } | ||
504 | const_reference back() const { QT_CHECK_INVALID_LIST_ELEMENT_FATAL; return *(--end()); } | ||
505 | void pop_front() { QT_CHECK_INVALID_LIST_ELEMENT; erase( begin() ); } | ||
506 | void pop_back() { | ||
507 | QT_CHECK_INVALID_LIST_ELEMENT; | ||
508 | iterator tmp = end(); | ||
509 | erase( --tmp ); | ||
510 | } | ||
511 | void insert( iterator pos, size_type n, const T& x ); | ||
512 | // Some compilers (incl. vc++) would instantiate this function even if | ||
513 | // it is not used; this would constrain QValueList to classes that provide | ||
514 | // an operator< | ||
515 | /* | ||
516 | void sort() | ||
517 | { | ||
518 | qHeapSort( *this ); | ||
519 | } | ||
520 | */ | ||
521 | |||
522 | QValueList<T> operator+ ( const QValueList<T>& l ) const; | ||
523 | QValueList<T>& operator+= ( const QValueList<T>& l ); | ||
524 | |||
525 | iterator fromLast() { detach(); return iterator( sh->node->prev ); } | ||
526 | const_iterator fromLast() const { return const_iterator( sh->node->prev ); } | ||
527 | |||
528 | bool isEmpty() const { return ( sh->nodes == 0 ); } | ||
529 | |||
530 | iterator append( const T& x ) { detach(); return sh->insert( end(), x ); } | ||
531 | iterator prepend( const T& x ) { detach(); return sh->insert( begin(), x ); } | ||
532 | |||
533 | iterator remove( iterator it ) { detach(); return sh->remove( it ); } | ||
534 | |||
535 | T& first() { QT_CHECK_INVALID_LIST_ELEMENT; detach(); return sh->node->next->data; } | ||
536 | const T& first() const { QT_CHECK_INVALID_LIST_ELEMENT; return sh->node->next->data; } | ||
537 | T& last() { QT_CHECK_INVALID_LIST_ELEMENT; detach(); return sh->node->prev->data; } | ||
538 | const T& last() const { QT_CHECK_INVALID_LIST_ELEMENT; return sh->node->prev->data; } | ||
539 | |||
540 | T& operator[] ( size_type i ) { QT_CHECK_INVALID_LIST_ELEMENT; detach(); return sh->at(i)->data; } | ||
541 | const T& operator[] ( size_type i ) const { QT_CHECK_INVALID_LIST_ELEMENT; return sh->at(i)->data; } | ||
542 | iterator at( size_type i ) { QT_CHECK_INVALID_LIST_ELEMENT; detach(); return iterator( sh->at(i) ); } | ||
543 | const_iterator at( size_type i ) const { QT_CHECK_INVALID_LIST_ELEMENT; return const_iterator( sh->at(i) ); } | ||
544 | iterator find ( const T& x ) { detach(); return iterator( sh->find( sh->node->next, x) ); } | ||
545 | const_iterator find ( const T& x ) const { return const_iterator( sh->find( sh->node->next, x) ); } | ||
546 | iterator find ( iterator it, const T& x ) { detach(); return iterator( sh->find( it.node, x ) ); } | ||
547 | const_iterator find ( const_iterator it, const T& x ) const { return const_iterator( sh->find( it.node, x ) ); } | ||
548 | int findIndex( const T& x ) const { return sh->findIndex( sh->node->next, x) ; } | ||
549 | size_type contains( const T& x ) const { return sh->contains( x ); } | ||
550 | |||
551 | size_type count() const { return sh->nodes; } | ||
552 | |||
553 | QValueList<T>& operator+= ( const T& x ) | ||
554 | { | ||
555 | append( x ); | ||
556 | return *this; | ||
557 | } | ||
558 | typedef QValueListIterator<T> Iterator; | ||
559 | typedef QValueListConstIterator<T> ConstIterator; | ||
560 | typedef T ValueType; | ||
561 | |||
562 | protected: | ||
563 | /** | ||
564 | * Helpers | ||
565 | */ | ||
566 | void detach() { if ( sh->count > 1 ) detachInternal(); } | ||
567 | |||
568 | /** | ||
569 | * Variables | ||
570 | */ | ||
571 | QValueListPrivate<T>* sh; | ||
572 | |||
573 | private: | ||
574 | void detachInternal(); | ||
575 | |||
576 | friend class QDeepCopy< QValueList<T> >; | ||
577 | }; | ||
578 | |||
579 | template <class T> | ||
580 | Q_INLINE_TEMPLATES bool QValueList<T>::operator== ( const QValueList<T>& l ) const | ||
581 | { | ||
582 | if ( size() != l.size() ) | ||
583 | return FALSE; | ||
584 | const_iterator it2 = begin(); | ||
585 | const_iterator it = l.begin(); | ||
586 | for( ; it != l.end(); ++it, ++it2 ) | ||
587 | if ( !( *it == *it2 ) ) | ||
588 | return FALSE; | ||
589 | return TRUE; | ||
590 | } | ||
591 | |||
592 | template <class T> | ||
593 | Q_INLINE_TEMPLATES void QValueList<T>::clear() | ||
594 | { | ||
595 | if ( sh->count == 1 ) sh->clear(); else { sh->deref(); sh = new QValueListPrivate<T>; } | ||
596 | } | ||
597 | |||
598 | template <class T> | ||
599 | Q_INLINE_TEMPLATES Q_TYPENAME QValueList<T>::iterator QValueList<T>::erase( Q_TYPENAME QValueList<T>::iterator first, Q_TYPENAME QValueList<T>::iterator last ) | ||
600 | { | ||
601 | while ( first != last ) | ||
602 | erase( first++ ); | ||
603 | return last; | ||
604 | } | ||
605 | |||
606 | |||
607 | template <class T> | ||
608 | Q_INLINE_TEMPLATES void QValueList<T>::insert( Q_TYPENAME QValueList<T>::iterator pos, size_type n, const T& x ) | ||
609 | { | ||
610 | for ( ; n > 0; --n ) | ||
611 | insert( pos, x ); | ||
612 | } | ||
613 | |||
614 | template <class T> | ||
615 | Q_INLINE_TEMPLATES QValueList<T> QValueList<T>::operator+ ( const QValueList<T>& l ) const | ||
616 | { | ||
617 | QValueList<T> l2( *this ); | ||
618 | for( const_iterator it = l.begin(); it != l.end(); ++it ) | ||
619 | l2.append( *it ); | ||
620 | return l2; | ||
621 | } | ||
622 | |||
623 | template <class T> | ||
624 | Q_INLINE_TEMPLATES QValueList<T>& QValueList<T>::operator+= ( const QValueList<T>& l ) | ||
625 | { | ||
626 | for( const_iterator it = l.begin(); it != l.end(); ++it ) | ||
627 | append( *it ); | ||
628 | return *this; | ||
629 | } | ||
630 | |||
631 | template <class T> | ||
632 | Q_INLINE_TEMPLATES void QValueList<T>::detachInternal() | ||
633 | { | ||
634 | sh->deref(); sh = new QValueListPrivate<T>( *sh ); | ||
635 | } | ||
636 | |||
637 | #ifndef QT_NO_DATASTREAM | ||
638 | template <class T> | ||
639 | Q_INLINE_TEMPLATES QDataStream& operator>>( QDataStream& s, QValueList<T>& l ) | ||
640 | { | ||
641 | l.clear(); | ||
642 | Q_UINT32 c; | ||
643 | s >> c; | ||
644 | for( Q_UINT32 i = 0; i < c; ++i ) | ||
645 | { | ||
646 | T t; | ||
647 | s >> t; | ||
648 | l.append( t ); | ||
649 | if ( s.atEnd() ) | ||
650 | break; | ||
651 | } | ||
652 | return s; | ||
653 | } | ||
654 | |||
655 | template <class T> | ||
656 | Q_INLINE_TEMPLATES QDataStream& operator<<( QDataStream& s, const QValueList<T>& l ) | ||
657 | { | ||
658 | s << (Q_UINT32)l.size(); | ||
659 | QValueListConstIterator<T> it = l.begin(); | ||
660 | for( ; it != l.end(); ++it ) | ||
661 | s << *it; | ||
662 | return s; | ||
663 | } | ||
664 | #endif // QT_NO_DATASTREAM | ||
665 | #endif // QVALUELIST_H | ||