| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/include/qvaluelist.h:1 -->
|
|---|
| 3 | <html>
|
|---|
| 4 | <head>
|
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|---|
| 6 | <title>qvaluelist.h Include File</title>
|
|---|
| 7 | <style type="text/css"><!--
|
|---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
|---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
|---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
|---|
| 11 | body { background: #ffffff; color: black; }
|
|---|
| 12 | --></style>
|
|---|
| 13 | </head>
|
|---|
| 14 | <body>
|
|---|
| 15 |
|
|---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|---|
| 17 | <tr bgcolor="#E5E5E5">
|
|---|
| 18 | <td valign=center>
|
|---|
| 19 | <a href="index.html">
|
|---|
| 20 | <font color="#004faf">Home</font></a>
|
|---|
| 21 | | <a href="classes.html">
|
|---|
| 22 | <font color="#004faf">All Classes</font></a>
|
|---|
| 23 | | <a href="mainclasses.html">
|
|---|
| 24 | <font color="#004faf">Main Classes</font></a>
|
|---|
| 25 | | <a href="annotated.html">
|
|---|
| 26 | <font color="#004faf">Annotated</font></a>
|
|---|
| 27 | | <a href="groups.html">
|
|---|
| 28 | <font color="#004faf">Grouped Classes</font></a>
|
|---|
| 29 | | <a href="functions.html">
|
|---|
| 30 | <font color="#004faf">Functions</font></a>
|
|---|
| 31 | </td>
|
|---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>qvaluelist.h</h1>
|
|---|
| 33 |
|
|---|
| 34 | <p>This is the verbatim text of the qvaluelist.h include file. It is provided only for illustration; the copyright remains with Trolltech.
|
|---|
| 35 | <hr>
|
|---|
| 36 | <pre>
|
|---|
| 37 | /****************************************************************************
|
|---|
| 38 | ** $Id: qvaluelist-h.html 2051 2007-02-21 10:04:20Z chehrlic $
|
|---|
| 39 | **
|
|---|
| 40 | ** Definition of QValueList class
|
|---|
| 41 | **
|
|---|
| 42 | ** Created : 990406
|
|---|
| 43 | **
|
|---|
| 44 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
|---|
| 45 | **
|
|---|
| 46 | ** This file is part of the tools module of the Qt GUI Toolkit.
|
|---|
| 47 | **
|
|---|
| 48 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 49 | ** as defined by Trolltech ASA of Norway and appearing in the file
|
|---|
| 50 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 51 | **
|
|---|
| 52 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 53 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 54 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 55 | ** packaging of this file.
|
|---|
| 56 | **
|
|---|
| 57 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
|---|
| 58 | ** licenses may use this file in accordance with the Qt Commercial License
|
|---|
| 59 | ** Agreement provided with the Software.
|
|---|
| 60 | **
|
|---|
| 61 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 62 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 63 | **
|
|---|
| 64 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 65 | ** information about Qt Commercial License Agreements.
|
|---|
| 66 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 67 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 68 | **
|
|---|
| 69 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 70 | ** not clear to you.
|
|---|
| 71 | **
|
|---|
| 72 | **********************************************************************/
|
|---|
| 73 |
|
|---|
| 74 | #ifndef QVALUELIST_H
|
|---|
| 75 | #define QVALUELIST_H
|
|---|
| 76 |
|
|---|
| 77 | #ifndef QT_H
|
|---|
| 78 | #include "qtl.h"
|
|---|
| 79 | #include "qshared.h"
|
|---|
| 80 | #include "qdatastream.h"
|
|---|
| 81 | #endif // QT_H
|
|---|
| 82 |
|
|---|
| 83 | #ifndef QT_NO_STL
|
|---|
| 84 | #include <iterator>
|
|---|
| 85 | #include <list>
|
|---|
| 86 | #endif
|
|---|
| 87 |
|
|---|
| 88 | //#define QT_CHECK_VALUELIST_RANGE
|
|---|
| 89 |
|
|---|
| 90 | #if defined(Q_CC_MSVC)
|
|---|
| 91 | #pragma warning(disable:4284) // "return type for operator -> is not a UDT"
|
|---|
| 92 | #endif
|
|---|
| 93 |
|
|---|
| 94 | template <class T>
|
|---|
| 95 | class QValueListNode
|
|---|
| 96 | {
|
|---|
| 97 | public:
|
|---|
| 98 | QValueListNode( const T& t ) : data( t ) { }
|
|---|
| 99 | QValueListNode() { }
|
|---|
| 100 | #if defined(Q_TEMPLATEDLL)
|
|---|
| 101 | // Workaround MS bug in memory de/allocation in DLL vs. EXE
|
|---|
| 102 | virtual ~QValueListNode() { }
|
|---|
| 103 | #endif
|
|---|
| 104 |
|
|---|
| 105 | QValueListNode<T>* next;
|
|---|
| 106 | QValueListNode<T>* prev;
|
|---|
| 107 | T data;
|
|---|
| 108 | };
|
|---|
| 109 |
|
|---|
| 110 | template<class T>
|
|---|
| 111 | class QValueListIterator
|
|---|
| 112 | {
|
|---|
| 113 | public:
|
|---|
| 114 | /**
|
|---|
| 115 | * Typedefs
|
|---|
| 116 | */
|
|---|
| 117 | typedef QValueListNode<T>* NodePtr;
|
|---|
| 118 | #ifndef QT_NO_STL
|
|---|
| 119 | typedef std::bidirectional_iterator_tag iterator_category;
|
|---|
| 120 | #endif
|
|---|
| 121 | typedef T value_type;
|
|---|
| 122 | typedef size_t size_type;
|
|---|
| 123 | #ifndef QT_NO_STL
|
|---|
| 124 | typedef ptrdiff_t difference_type;
|
|---|
| 125 | #else
|
|---|
| 126 | typedef int difference_type;
|
|---|
| 127 | #endif
|
|---|
| 128 | typedef T* pointer;
|
|---|
| 129 | typedef T& reference;
|
|---|
| 130 |
|
|---|
| 131 | /**
|
|---|
| 132 | * Variables
|
|---|
| 133 | */
|
|---|
| 134 | NodePtr node;
|
|---|
| 135 |
|
|---|
| 136 | /**
|
|---|
| 137 | * Functions
|
|---|
| 138 | */
|
|---|
| 139 | QValueListIterator() : node( 0 ) {}
|
|---|
| 140 | QValueListIterator( NodePtr p ) : node( p ) {}
|
|---|
| 141 | QValueListIterator( const QValueListIterator<T>& it ) : node( it.node ) {}
|
|---|
| 142 |
|
|---|
| 143 | bool operator==( const QValueListIterator<T>& it ) const { return node == it.node; }
|
|---|
| 144 | bool operator!=( const QValueListIterator<T>& it ) const { return node != it.node; }
|
|---|
| 145 | const T& operator*() const { return node->data; }
|
|---|
| 146 | T& operator*() { return node->data; }
|
|---|
| 147 | // UDT for T = x*
|
|---|
| 148 | // T* operator->() const { return &node->data; }
|
|---|
| 149 |
|
|---|
| 150 | QValueListIterator<T>& operator++() {
|
|---|
| 151 | node = node->next;
|
|---|
| 152 | return *this;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | QValueListIterator<T> operator++(int) {
|
|---|
| 156 | QValueListIterator<T> tmp = *this;
|
|---|
| 157 | node = node->next;
|
|---|
| 158 | return tmp;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | QValueListIterator<T>& operator--() {
|
|---|
| 162 | node = node->prev;
|
|---|
| 163 | return *this;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | QValueListIterator<T> operator--(int) {
|
|---|
| 167 | QValueListIterator<T> tmp = *this;
|
|---|
| 168 | node = node->prev;
|
|---|
| 169 | return tmp;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | QValueListIterator<T>& operator+=( int j ) {
|
|---|
| 173 | while ( j-- )
|
|---|
| 174 | node = node->next;
|
|---|
| 175 | return *this;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | QValueListIterator<T>& operator-=( int j ) {
|
|---|
| 179 | while ( j-- )
|
|---|
| 180 | node = node->prev;
|
|---|
| 181 | return *this;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | };
|
|---|
| 185 |
|
|---|
| 186 | template<class T>
|
|---|
| 187 | class QValueListConstIterator
|
|---|
| 188 | {
|
|---|
| 189 | public:
|
|---|
| 190 | /**
|
|---|
| 191 | * Typedefs
|
|---|
| 192 | */
|
|---|
| 193 | typedef QValueListNode<T>* NodePtr;
|
|---|
| 194 | #ifndef QT_NO_STL
|
|---|
| 195 | typedef std::bidirectional_iterator_tag iterator_category;
|
|---|
| 196 | #endif
|
|---|
| 197 | typedef T value_type;
|
|---|
| 198 | typedef size_t size_type;
|
|---|
| 199 | #ifndef QT_NO_STL
|
|---|
| 200 | typedef ptrdiff_t difference_type;
|
|---|
| 201 | #else
|
|---|
| 202 | typedef int difference_type;
|
|---|
| 203 | #endif
|
|---|
| 204 | typedef const T* pointer;
|
|---|
| 205 | typedef const T& reference;
|
|---|
| 206 |
|
|---|
| 207 | /**
|
|---|
| 208 | * Variables
|
|---|
| 209 | */
|
|---|
| 210 | NodePtr node;
|
|---|
| 211 |
|
|---|
| 212 | /**
|
|---|
| 213 | * Functions
|
|---|
| 214 | */
|
|---|
| 215 | QValueListConstIterator() : node( 0 ) {}
|
|---|
| 216 | QValueListConstIterator( NodePtr p ) : node( p ) {}
|
|---|
| 217 | QValueListConstIterator( const QValueListConstIterator<T>& it ) : node( it.node ) {}
|
|---|
| 218 | QValueListConstIterator( const QValueListIterator<T>& it ) : node( it.node ) {}
|
|---|
| 219 |
|
|---|
| 220 | bool operator==( const QValueListConstIterator<T>& it ) const { return node == it.node; }
|
|---|
| 221 | bool operator!=( const QValueListConstIterator<T>& it ) const { return node != it.node; }
|
|---|
| 222 | const T& operator*() const { return node->data; }
|
|---|
| 223 | // UDT for T = x*
|
|---|
| 224 | // const T* operator->() const { return &node->data; }
|
|---|
| 225 |
|
|---|
| 226 | QValueListConstIterator<T>& operator++() {
|
|---|
| 227 | node = node->next;
|
|---|
| 228 | return *this;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | QValueListConstIterator<T> operator++(int) {
|
|---|
| 232 | QValueListConstIterator<T> tmp = *this;
|
|---|
| 233 | node = node->next;
|
|---|
| 234 | return tmp;
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | QValueListConstIterator<T>& operator--() {
|
|---|
| 238 | node = node->prev;
|
|---|
| 239 | return *this;
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | QValueListConstIterator<T> operator--(int) {
|
|---|
| 243 | QValueListConstIterator<T> tmp = *this;
|
|---|
| 244 | node = node->prev;
|
|---|
| 245 | return tmp;
|
|---|
| 246 | }
|
|---|
| 247 | };
|
|---|
| 248 |
|
|---|
| 249 | template <class T>
|
|---|
| 250 | class QValueListPrivate : public QShared
|
|---|
| 251 | {
|
|---|
| 252 | public:
|
|---|
| 253 | /**
|
|---|
| 254 | * Typedefs
|
|---|
| 255 | */
|
|---|
| 256 | typedef QValueListIterator<T> Iterator;
|
|---|
| 257 | typedef QValueListConstIterator<T> ConstIterator;
|
|---|
| 258 | typedef QValueListNode<T> Node;
|
|---|
| 259 | typedef QValueListNode<T>* NodePtr;
|
|---|
| 260 | typedef size_t size_type;
|
|---|
| 261 |
|
|---|
| 262 | /**
|
|---|
| 263 | * Functions
|
|---|
| 264 | */
|
|---|
| 265 | QValueListPrivate();
|
|---|
| 266 | QValueListPrivate( const QValueListPrivate<T>& _p );
|
|---|
| 267 |
|
|---|
| 268 | void derefAndDelete() // ### hack to get around hp-cc brain damage
|
|---|
| 269 | {
|
|---|
| 270 | if ( deref() )
|
|---|
| 271 | delete this;
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | #if defined(Q_TEMPLATEDLL)
|
|---|
| 275 | // Workaround MS bug in memory de/allocation in DLL vs. EXE
|
|---|
| 276 | virtual
|
|---|
| 277 | #endif
|
|---|
| 278 | ~QValueListPrivate();
|
|---|
| 279 |
|
|---|
| 280 | Iterator insert( Iterator it, const T& x );
|
|---|
| 281 | Iterator remove( Iterator it );
|
|---|
| 282 | NodePtr find( NodePtr start, const T& x ) const;
|
|---|
| 283 | int findIndex( NodePtr start, const T& x ) const;
|
|---|
| 284 | uint contains( const T& x ) const;
|
|---|
| 285 | uint remove( const T& x );
|
|---|
| 286 | NodePtr at( size_type i ) const;
|
|---|
| 287 | void clear();
|
|---|
| 288 |
|
|---|
| 289 | NodePtr node;
|
|---|
| 290 | size_type nodes;
|
|---|
| 291 | };
|
|---|
| 292 |
|
|---|
| 293 | template <class T>
|
|---|
| 294 | Q_INLINE_TEMPLATES QValueListPrivate<T>::QValueListPrivate()
|
|---|
| 295 | {
|
|---|
| 296 | node = new Node; node->next = node->prev = node; nodes = 0;
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | template <class T>
|
|---|
| 300 | Q_INLINE_TEMPLATES QValueListPrivate<T>::QValueListPrivate( const QValueListPrivate<T>& _p )
|
|---|
| 301 | : QShared()
|
|---|
| 302 | {
|
|---|
| 303 | node = new Node; node->next = node->prev = node; nodes = 0;
|
|---|
| 304 | Iterator b( _p.node->next );
|
|---|
| 305 | Iterator e( _p.node );
|
|---|
| 306 | Iterator i( node );
|
|---|
| 307 | while( b != e )
|
|---|
| 308 | insert( i, *b++ );
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | template <class T>
|
|---|
| 312 | Q_INLINE_TEMPLATES QValueListPrivate<T>::~QValueListPrivate() {
|
|---|
| 313 | NodePtr p = node->next;
|
|---|
| 314 | while( p != node ) {
|
|---|
| 315 | NodePtr x = p->next;
|
|---|
| 316 | delete p;
|
|---|
| 317 | p = x;
|
|---|
| 318 | }
|
|---|
| 319 | delete node;
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | template <class T>
|
|---|
| 323 | Q_INLINE_TEMPLATES Q_TYPENAME QValueListPrivate<T>::Iterator QValueListPrivate<T>::insert( Q_TYPENAME QValueListPrivate<T>::Iterator it, const T& x )
|
|---|
| 324 | {
|
|---|
| 325 | NodePtr p = new Node( x );
|
|---|
| 326 | p->next = it.node;
|
|---|
| 327 | p->prev = it.node->prev;
|
|---|
| 328 | it.node->prev->next = p;
|
|---|
| 329 | it.node->prev = p;
|
|---|
| 330 | nodes++;
|
|---|
| 331 | return p;
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | template <class T>
|
|---|
| 335 | Q_INLINE_TEMPLATES Q_TYPENAME QValueListPrivate<T>::Iterator QValueListPrivate<T>::remove( Q_TYPENAME QValueListPrivate<T>::Iterator it )
|
|---|
| 336 | {
|
|---|
| 337 | Q_ASSERT ( it.node != node );
|
|---|
| 338 | NodePtr next = it.node->next;
|
|---|
| 339 | NodePtr prev = it.node->prev;
|
|---|
| 340 | prev->next = next;
|
|---|
| 341 | next->prev = prev;
|
|---|
| 342 | delete it.node;
|
|---|
| 343 | nodes--;
|
|---|
| 344 | return Iterator( next );
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | template <class T>
|
|---|
| 348 | Q_INLINE_TEMPLATES Q_TYPENAME QValueListPrivate<T>::NodePtr QValueListPrivate<T>::find( Q_TYPENAME QValueListPrivate<T>::NodePtr start, const T& x ) const
|
|---|
| 349 | {
|
|---|
| 350 | ConstIterator first( start );
|
|---|
| 351 | ConstIterator last( node );
|
|---|
| 352 | while( first != last) {
|
|---|
| 353 | if ( *first == x )
|
|---|
| 354 | return first.node;
|
|---|
| 355 | ++first;
|
|---|
| 356 | }
|
|---|
| 357 | return last.node;
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | template <class T>
|
|---|
| 361 | Q_INLINE_TEMPLATES int QValueListPrivate<T>::findIndex( Q_TYPENAME QValueListPrivate<T>::NodePtr start, const T& x ) const
|
|---|
| 362 | {
|
|---|
| 363 | ConstIterator first( start );
|
|---|
| 364 | ConstIterator last( node );
|
|---|
| 365 | int pos = 0;
|
|---|
| 366 | while( first != last) {
|
|---|
| 367 | if ( *first == x )
|
|---|
| 368 | return pos;
|
|---|
| 369 | ++first;
|
|---|
| 370 | ++pos;
|
|---|
| 371 | }
|
|---|
| 372 | return -1;
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | template <class T>
|
|---|
| 376 | Q_INLINE_TEMPLATES uint QValueListPrivate<T>::contains( const T& x ) const
|
|---|
| 377 | {
|
|---|
| 378 | uint result = 0;
|
|---|
| 379 | Iterator first = Iterator( node->next );
|
|---|
| 380 | Iterator last = Iterator( node );
|
|---|
| 381 | while( first != last) {
|
|---|
| 382 | if ( *first == x )
|
|---|
| 383 | ++result;
|
|---|
| 384 | ++first;
|
|---|
| 385 | }
|
|---|
| 386 | return result;
|
|---|
| 387 | }
|
|---|
| 388 |
|
|---|
| 389 | template <class T>
|
|---|
| 390 | Q_INLINE_TEMPLATES uint QValueListPrivate<T>::remove( const T& _x )
|
|---|
| 391 | {
|
|---|
| 392 | const T x = _x;
|
|---|
| 393 | uint result = 0;
|
|---|
| 394 | Iterator first = Iterator( node->next );
|
|---|
| 395 | Iterator last = Iterator( node );
|
|---|
| 396 | while( first != last) {
|
|---|
| 397 | if ( *first == x ) {
|
|---|
| 398 | first = remove( first );
|
|---|
| 399 | ++result;
|
|---|
| 400 | } else
|
|---|
| 401 | ++first;
|
|---|
| 402 | }
|
|---|
| 403 | return result;
|
|---|
| 404 | }
|
|---|
| 405 |
|
|---|
| 406 | template <class T>
|
|---|
| 407 | Q_INLINE_TEMPLATES Q_TYPENAME QValueListPrivate<T>::NodePtr QValueListPrivate<T>::at( size_type i ) const
|
|---|
| 408 | {
|
|---|
| 409 | Q_ASSERT( i <= nodes );
|
|---|
| 410 | NodePtr p = node->next;
|
|---|
| 411 | for( size_type x = 0; x < i; ++x )
|
|---|
| 412 | p = p->next;
|
|---|
| 413 | return p;
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | template <class T>
|
|---|
| 417 | Q_INLINE_TEMPLATES void QValueListPrivate<T>::clear()
|
|---|
| 418 | {
|
|---|
| 419 | nodes = 0;
|
|---|
| 420 | NodePtr p = node->next;
|
|---|
| 421 | while( p != node ) {
|
|---|
| 422 | NodePtr next = p->next;
|
|---|
| 423 | delete p;
|
|---|
| 424 | p = next;
|
|---|
| 425 | }
|
|---|
| 426 | node->next = node->prev = node;
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 | #ifdef QT_CHECK_RANGE
|
|---|
| 430 | # if !defined( QT_NO_DEBUG ) && defined( QT_CHECK_VALUELIST_RANGE )
|
|---|
| 431 | # define QT_CHECK_INVALID_LIST_ELEMENT if ( empty() ) qWarning( "QValueList: Warning invalid element" )
|
|---|
| 432 | # define QT_CHECK_INVALID_LIST_ELEMENT_FATAL Q_ASSERT( !empty() );
|
|---|
| 433 | # else
|
|---|
| 434 | # define QT_CHECK_INVALID_LIST_ELEMENT
|
|---|
| 435 | # define QT_CHECK_INVALID_LIST_ELEMENT_FATAL
|
|---|
| 436 | # endif
|
|---|
| 437 | #else
|
|---|
| 438 | # define QT_CHECK_INVALID_LIST_ELEMENT
|
|---|
| 439 | # define QT_CHECK_INVALID_LIST_ELEMENT_FATAL
|
|---|
| 440 | #endif
|
|---|
| 441 |
|
|---|
| 442 | template <class T> class QDeepCopy;
|
|---|
| 443 |
|
|---|
| 444 | template <class T>
|
|---|
| 445 | class QValueList
|
|---|
| 446 | {
|
|---|
| 447 | public:
|
|---|
| 448 | /**
|
|---|
| 449 | * Typedefs
|
|---|
| 450 | */
|
|---|
| 451 | typedef QValueListIterator<T> iterator;
|
|---|
| 452 | typedef QValueListConstIterator<T> const_iterator;
|
|---|
| 453 | typedef T value_type;
|
|---|
| 454 | typedef value_type* pointer;
|
|---|
| 455 | typedef const value_type* const_pointer;
|
|---|
| 456 | typedef value_type& reference;
|
|---|
| 457 | typedef const value_type& const_reference;
|
|---|
| 458 | typedef size_t size_type;
|
|---|
| 459 | #ifndef QT_NO_STL
|
|---|
| 460 | typedef ptrdiff_t difference_type;
|
|---|
| 461 | #else
|
|---|
| 462 | typedef int difference_type;
|
|---|
| 463 | #endif
|
|---|
| 464 |
|
|---|
| 465 | /**
|
|---|
| 466 | * API
|
|---|
| 467 | */
|
|---|
| 468 | QValueList() { sh = new QValueListPrivate<T>; }
|
|---|
| 469 | QValueList( const QValueList<T>& l ) { sh = l.sh; sh->ref(); }
|
|---|
| 470 | #ifndef QT_NO_STL
|
|---|
| 471 | QValueList( const std::list<T>& l )
|
|---|
| 472 | {
|
|---|
| 473 | sh = new QValueListPrivate<T>;
|
|---|
| 474 | qCopy( l.begin(), l.end(), std::back_inserter( *this ) );
|
|---|
| 475 | }
|
|---|
| 476 | #endif
|
|---|
| 477 | ~QValueList() { sh->derefAndDelete(); }
|
|---|
| 478 |
|
|---|
| 479 | QValueList<T>& operator= ( const QValueList<T>& l )
|
|---|
| 480 | {
|
|---|
| 481 | l.sh->ref();
|
|---|
| 482 | sh->derefAndDelete();
|
|---|
| 483 | sh = l.sh;
|
|---|
| 484 | return *this;
|
|---|
| 485 | }
|
|---|
| 486 | #ifndef QT_NO_STL
|
|---|
| 487 | QValueList<T>& operator= ( const std::list<T>& l )
|
|---|
| 488 | {
|
|---|
| 489 | detach();
|
|---|
| 490 | qCopy( l.begin(), l.end(), std::back_inserter( *this ) );
|
|---|
| 491 | return *this;
|
|---|
| 492 | }
|
|---|
| 493 | bool operator== ( const std::list<T>& l ) const
|
|---|
| 494 | {
|
|---|
| 495 | if ( size() != l.size() )
|
|---|
| 496 | return FALSE;
|
|---|
| 497 | const_iterator it2 = begin();
|
|---|
| 498 | #if !defined(Q_CC_MIPS)
|
|---|
| 499 | typename
|
|---|
| 500 | #endif
|
|---|
| 501 | std::list<T>::const_iterator it = l.begin();
|
|---|
| 502 | for ( ; it2 != end(); ++it2, ++it )
|
|---|
| 503 | if ( !((*it2) == (*it)) )
|
|---|
| 504 | return FALSE;
|
|---|
| 505 | return TRUE;
|
|---|
| 506 | }
|
|---|
| 507 | #endif
|
|---|
| 508 | bool operator== ( const QValueList<T>& l ) const;
|
|---|
| 509 | bool operator!= ( const QValueList<T>& l ) const { return !( *this == l ); }
|
|---|
| 510 | iterator begin() { detach(); return iterator( sh->node->next ); }
|
|---|
| 511 | const_iterator begin() const { return const_iterator( sh->node->next ); }
|
|---|
| 512 | const_iterator constBegin() const { return const_iterator( sh->node->next ); }
|
|---|
| 513 | iterator end() { detach(); return iterator( sh->node ); }
|
|---|
| 514 | const_iterator end() const { return const_iterator( sh->node ); }
|
|---|
| 515 | const_iterator constEnd() const { return const_iterator( sh->node ); }
|
|---|
| 516 | iterator insert( iterator it, const T& x ) { detach(); return sh->insert( it, x ); }
|
|---|
| 517 | uint remove( const T& x ) { detach(); return sh->remove( x ); }
|
|---|
| 518 | void clear();
|
|---|
| 519 |
|
|---|
| 520 | // ### 4.0: move out of class
|
|---|
| 521 | QValueList<T>& operator<< ( const T& x )
|
|---|
| 522 | {
|
|---|
| 523 | append( x );
|
|---|
| 524 | return *this;
|
|---|
| 525 | }
|
|---|
| 526 |
|
|---|
| 527 | size_type size() const { return sh->nodes; }
|
|---|
| 528 | bool empty() const { return sh->nodes == 0; }
|
|---|
| 529 | void push_front( const T& x ) { detach(); sh->insert( begin(), x ); }
|
|---|
| 530 | void push_back( const T& x ) { detach(); sh->insert( end(), x ); }
|
|---|
| 531 | iterator erase( iterator pos ) { detach(); return sh->remove( pos ); }
|
|---|
| 532 | iterator erase( iterator first, iterator last );
|
|---|
| 533 | reference front() { QT_CHECK_INVALID_LIST_ELEMENT_FATAL; return *begin(); }
|
|---|
| 534 | const_reference front() const { QT_CHECK_INVALID_LIST_ELEMENT_FATAL; return *begin(); }
|
|---|
| 535 | reference back() { QT_CHECK_INVALID_LIST_ELEMENT_FATAL; return *(--end()); }
|
|---|
| 536 | const_reference back() const { QT_CHECK_INVALID_LIST_ELEMENT_FATAL; return *(--end()); }
|
|---|
| 537 | void pop_front() { QT_CHECK_INVALID_LIST_ELEMENT; erase( begin() ); }
|
|---|
| 538 | void pop_back() {
|
|---|
| 539 | QT_CHECK_INVALID_LIST_ELEMENT;
|
|---|
| 540 | iterator tmp = end();
|
|---|
| 541 | erase( --tmp );
|
|---|
| 542 | }
|
|---|
| 543 | void insert( iterator pos, size_type n, const T& x );
|
|---|
| 544 | // Some compilers (incl. vc++) would instantiate this function even if
|
|---|
| 545 | // it is not used; this would constrain QValueList to classes that provide
|
|---|
| 546 | // an operator<
|
|---|
| 547 | /*
|
|---|
| 548 | void sort()
|
|---|
| 549 | {
|
|---|
| 550 | qHeapSort( *this );
|
|---|
| 551 | }
|
|---|
| 552 | */
|
|---|
| 553 |
|
|---|
| 554 | QValueList<T> operator+ ( const QValueList<T>& l ) const;
|
|---|
| 555 | QValueList<T>& operator+= ( const QValueList<T>& l );
|
|---|
| 556 |
|
|---|
| 557 | iterator fromLast() { detach(); return iterator( sh->node->prev ); }
|
|---|
| 558 | const_iterator fromLast() const { return const_iterator( sh->node->prev ); }
|
|---|
| 559 |
|
|---|
| 560 | bool isEmpty() const { return ( sh->nodes == 0 ); }
|
|---|
| 561 |
|
|---|
| 562 | iterator append( const T& x ) { detach(); return sh->insert( end(), x ); }
|
|---|
| 563 | iterator prepend( const T& x ) { detach(); return sh->insert( begin(), x ); }
|
|---|
| 564 |
|
|---|
| 565 | iterator remove( iterator it ) { detach(); return sh->remove( it ); }
|
|---|
| 566 |
|
|---|
| 567 | T& first() { QT_CHECK_INVALID_LIST_ELEMENT; detach(); return sh->node->next->data; }
|
|---|
| 568 | const T& first() const { QT_CHECK_INVALID_LIST_ELEMENT; return sh->node->next->data; }
|
|---|
| 569 | T& last() { QT_CHECK_INVALID_LIST_ELEMENT; detach(); return sh->node->prev->data; }
|
|---|
| 570 | const T& last() const { QT_CHECK_INVALID_LIST_ELEMENT; return sh->node->prev->data; }
|
|---|
| 571 |
|
|---|
| 572 | T& operator[] ( size_type i ) { QT_CHECK_INVALID_LIST_ELEMENT; detach(); return sh->at(i)->data; }
|
|---|
| 573 | const T& operator[] ( size_type i ) const { QT_CHECK_INVALID_LIST_ELEMENT; return sh->at(i)->data; }
|
|---|
| 574 | iterator at( size_type i ) { QT_CHECK_INVALID_LIST_ELEMENT; detach(); return iterator( sh->at(i) ); }
|
|---|
| 575 | const_iterator at( size_type i ) const { QT_CHECK_INVALID_LIST_ELEMENT; return const_iterator( sh->at(i) ); }
|
|---|
| 576 | iterator find ( const T& x ) { detach(); return iterator( sh->find( sh->node->next, x) ); }
|
|---|
| 577 | const_iterator find ( const T& x ) const { return const_iterator( sh->find( sh->node->next, x) ); }
|
|---|
| 578 | iterator find ( iterator it, const T& x ) { detach(); return iterator( sh->find( it.node, x ) ); }
|
|---|
| 579 | const_iterator find ( const_iterator it, const T& x ) const { return const_iterator( sh->find( it.node, x ) ); }
|
|---|
| 580 | int findIndex( const T& x ) const { return sh->findIndex( sh->node->next, x) ; }
|
|---|
| 581 | size_type contains( const T& x ) const { return sh->contains( x ); }
|
|---|
| 582 |
|
|---|
| 583 | size_type count() const { return sh->nodes; }
|
|---|
| 584 |
|
|---|
| 585 | QValueList<T>& operator+= ( const T& x )
|
|---|
| 586 | {
|
|---|
| 587 | append( x );
|
|---|
| 588 | return *this;
|
|---|
| 589 | }
|
|---|
| 590 | typedef QValueListIterator<T> Iterator;
|
|---|
| 591 | typedef QValueListConstIterator<T> ConstIterator;
|
|---|
| 592 | typedef T ValueType;
|
|---|
| 593 |
|
|---|
| 594 | protected:
|
|---|
| 595 | /**
|
|---|
| 596 | * Helpers
|
|---|
| 597 | */
|
|---|
| 598 | void detach() { if ( sh->count > 1 ) detachInternal(); }
|
|---|
| 599 |
|
|---|
| 600 | /**
|
|---|
| 601 | * Variables
|
|---|
| 602 | */
|
|---|
| 603 | QValueListPrivate<T>* sh;
|
|---|
| 604 |
|
|---|
| 605 | private:
|
|---|
| 606 | void detachInternal();
|
|---|
| 607 |
|
|---|
| 608 | friend class QDeepCopy< QValueList<T> >;
|
|---|
| 609 | };
|
|---|
| 610 |
|
|---|
| 611 | template <class T>
|
|---|
| 612 | Q_INLINE_TEMPLATES bool QValueList<T>::operator== ( const QValueList<T>& l ) const
|
|---|
| 613 | {
|
|---|
| 614 | if ( size() != l.size() )
|
|---|
| 615 | return FALSE;
|
|---|
| 616 | const_iterator it2 = begin();
|
|---|
| 617 | const_iterator it = l.begin();
|
|---|
| 618 | for( ; it != l.end(); ++it, ++it2 )
|
|---|
| 619 | if ( !( *it == *it2 ) )
|
|---|
| 620 | return FALSE;
|
|---|
| 621 | return TRUE;
|
|---|
| 622 | }
|
|---|
| 623 |
|
|---|
| 624 | template <class T>
|
|---|
| 625 | Q_INLINE_TEMPLATES void QValueList<T>::clear()
|
|---|
| 626 | {
|
|---|
| 627 | if ( sh->count == 1 ) sh->clear(); else { sh->deref(); sh = new QValueListPrivate<T>; }
|
|---|
| 628 | }
|
|---|
| 629 |
|
|---|
| 630 | template <class T>
|
|---|
| 631 | Q_INLINE_TEMPLATES Q_TYPENAME QValueList<T>::iterator QValueList<T>::erase( Q_TYPENAME QValueList<T>::iterator first, Q_TYPENAME QValueList<T>::iterator last )
|
|---|
| 632 | {
|
|---|
| 633 | while ( first != last )
|
|---|
| 634 | erase( first++ );
|
|---|
| 635 | return last;
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 | template <class T>
|
|---|
| 640 | Q_INLINE_TEMPLATES void QValueList<T>::insert( Q_TYPENAME QValueList<T>::iterator pos, size_type n, const T& x )
|
|---|
| 641 | {
|
|---|
| 642 | for ( ; n > 0; --n )
|
|---|
| 643 | insert( pos, x );
|
|---|
| 644 | }
|
|---|
| 645 |
|
|---|
| 646 | template <class T>
|
|---|
| 647 | Q_INLINE_TEMPLATES QValueList<T> QValueList<T>::operator+ ( const QValueList<T>& l ) const
|
|---|
| 648 | {
|
|---|
| 649 | QValueList<T> l2( *this );
|
|---|
| 650 | for( const_iterator it = l.begin(); it != l.end(); ++it )
|
|---|
| 651 | l2.append( *it );
|
|---|
| 652 | return l2;
|
|---|
| 653 | }
|
|---|
| 654 |
|
|---|
| 655 | template <class T>
|
|---|
| 656 | Q_INLINE_TEMPLATES QValueList<T>& QValueList<T>::operator+= ( const QValueList<T>& l )
|
|---|
| 657 | {
|
|---|
| 658 | QValueList<T> copy = l;
|
|---|
| 659 | for( const_iterator it = copy.begin(); it != copy.end(); ++it )
|
|---|
| 660 | append( *it );
|
|---|
| 661 | return *this;
|
|---|
| 662 | }
|
|---|
| 663 |
|
|---|
| 664 | template <class T>
|
|---|
| 665 | Q_INLINE_TEMPLATES void QValueList<T>::detachInternal()
|
|---|
| 666 | {
|
|---|
| 667 | sh->deref(); sh = new QValueListPrivate<T>( *sh );
|
|---|
| 668 | }
|
|---|
| 669 |
|
|---|
| 670 | #ifndef QT_NO_DATASTREAM
|
|---|
| 671 | template <class T>
|
|---|
| 672 | Q_INLINE_TEMPLATES QDataStream& operator>>( QDataStream& s, QValueList<T>& l )
|
|---|
| 673 | {
|
|---|
| 674 | l.clear();
|
|---|
| 675 | Q_UINT32 c;
|
|---|
| 676 | s >> c;
|
|---|
| 677 | for( Q_UINT32 i = 0; i < c; ++i )
|
|---|
| 678 | {
|
|---|
| 679 | T t;
|
|---|
| 680 | s >> t;
|
|---|
| 681 | l.append( t );
|
|---|
| 682 | if ( s.atEnd() )
|
|---|
| 683 | break;
|
|---|
| 684 | }
|
|---|
| 685 | return s;
|
|---|
| 686 | }
|
|---|
| 687 |
|
|---|
| 688 | template <class T>
|
|---|
| 689 | Q_INLINE_TEMPLATES QDataStream& operator<<( QDataStream& s, const QValueList<T>& l )
|
|---|
| 690 | {
|
|---|
| 691 | s << (Q_UINT32)l.size();
|
|---|
| 692 | QValueListConstIterator<T> it = l.begin();
|
|---|
| 693 | for( ; it != l.end(); ++it )
|
|---|
| 694 | s << *it;
|
|---|
| 695 | return s;
|
|---|
| 696 | }
|
|---|
| 697 | #endif // QT_NO_DATASTREAM
|
|---|
| 698 |
|
|---|
| 699 | #define Q_DEFINED_QVALUELIST
|
|---|
| 700 | #define Q_DEFINED_QVALUELIST
|
|---|
| 701 | #include "qwinexport.h"
|
|---|
| 702 | #endif // QVALUELIST_H
|
|---|
| 703 | </pre>
|
|---|
| 704 | <!-- eof -->
|
|---|
| 705 | <p><address><hr><div align=center>
|
|---|
| 706 | <table width=100% cellspacing=0 border=0><tr>
|
|---|
| 707 | <td>Copyright © 2007
|
|---|
| 708 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|---|
| 709 | <td align=right><div align=right>Qt 3.3.8</div>
|
|---|
| 710 | </table></div></address></body>
|
|---|
| 711 | </html>
|
|---|