[190] | 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/qvaluevector.h:1 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>qvaluevector.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>qvaluevector.h</h1>
|
---|
| 33 |
|
---|
| 34 | <p>This is the verbatim text of the qvaluevector.h include file. It is provided only for illustration; the copyright remains with Trolltech.
|
---|
| 35 | <hr>
|
---|
| 36 | <pre>
|
---|
| 37 | /****************************************************************************
|
---|
| 38 | ** $Id: qvaluevector-h.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 39 | **
|
---|
| 40 | ** Definition of QValueVector class
|
---|
| 41 | **
|
---|
| 42 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 43 | **
|
---|
| 44 | ** This file is part of the tools module of the Qt GUI Toolkit.
|
---|
| 45 | **
|
---|
| 46 | ** This file may be distributed under the terms of the Q Public License
|
---|
| 47 | ** as defined by Trolltech ASA of Norway and appearing in the file
|
---|
| 48 | ** LICENSE.QPL included in the packaging of this file.
|
---|
| 49 | **
|
---|
| 50 | ** This file may be distributed and/or modified under the terms of the
|
---|
| 51 | ** GNU General Public License version 2 as published by the Free Software
|
---|
| 52 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 53 | ** packaging of this file.
|
---|
| 54 | **
|
---|
| 55 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
| 56 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
| 57 | ** Agreement provided with the Software.
|
---|
| 58 | **
|
---|
| 59 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
| 60 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 61 | **
|
---|
| 62 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
| 63 | ** information about Qt Commercial License Agreements.
|
---|
| 64 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
| 65 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
| 66 | **
|
---|
| 67 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
| 68 | ** not clear to you.
|
---|
| 69 | **
|
---|
| 70 | **********************************************************************/
|
---|
| 71 |
|
---|
| 72 | #ifndef QVALUEVECTOR_H
|
---|
| 73 | #define QVALUEVECTOR_H
|
---|
| 74 |
|
---|
| 75 | #ifndef QT_H
|
---|
| 76 | #include "qtl.h"
|
---|
| 77 | #include "qshared.h"
|
---|
| 78 | #include "qdatastream.h"
|
---|
| 79 | #endif // QT_H
|
---|
| 80 |
|
---|
| 81 | #ifndef QT_NO_STL
|
---|
| 82 | #include <vector>
|
---|
| 83 | #endif
|
---|
| 84 |
|
---|
| 85 | template <class T>
|
---|
| 86 | class QValueVectorPrivate : public QShared
|
---|
| 87 | {
|
---|
| 88 | public:
|
---|
| 89 | typedef T value_type;
|
---|
| 90 | typedef T* pointer;
|
---|
| 91 |
|
---|
| 92 | QValueVectorPrivate()
|
---|
| 93 | : start( 0 ), finish( 0 ), end( 0 )
|
---|
| 94 | {
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | QValueVectorPrivate( const QValueVectorPrivate<T>& x );
|
---|
| 98 | QValueVectorPrivate( size_t size );
|
---|
| 99 |
|
---|
| 100 | void derefAndDelete() // work-around for hp-cc
|
---|
| 101 | {
|
---|
| 102 | if ( deref() )
|
---|
| 103 | delete this;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | #if defined(Q_TEMPLATEDLL)
|
---|
| 107 | // Workaround MS bug in memory de/allocation in DLL vs. EXE
|
---|
| 108 | virtual
|
---|
| 109 | #endif
|
---|
| 110 | ~QValueVectorPrivate()
|
---|
| 111 | {
|
---|
| 112 | delete[] start;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | size_t size() const
|
---|
| 116 | {
|
---|
| 117 | return finish - start;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | bool empty() const
|
---|
| 121 | {
|
---|
| 122 | return start == finish;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | size_t capacity() const
|
---|
| 126 | {
|
---|
| 127 | return end - start;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | void insert( pointer pos, const T& x );
|
---|
| 131 | void insert( pointer pos, size_t n, const T& x );
|
---|
| 132 | void reserve( size_t n );
|
---|
| 133 |
|
---|
| 134 | void clear()
|
---|
| 135 | {
|
---|
| 136 | delete[] start;
|
---|
| 137 | start = 0;
|
---|
| 138 | finish = 0;
|
---|
| 139 | end = 0;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 | pointer start;
|
---|
| 144 | pointer finish;
|
---|
| 145 | pointer end;
|
---|
| 146 |
|
---|
| 147 | private:
|
---|
| 148 | pointer growAndCopy( size_t n, pointer s, pointer f );
|
---|
| 149 |
|
---|
| 150 | QValueVectorPrivate<T>& operator=( const QValueVectorPrivate<T>& x );
|
---|
| 151 |
|
---|
| 152 | };
|
---|
| 153 |
|
---|
| 154 | template <class T>
|
---|
| 155 | Q_INLINE_TEMPLATES QValueVectorPrivate<T>::QValueVectorPrivate( const QValueVectorPrivate<T>& x )
|
---|
| 156 | : QShared()
|
---|
| 157 | {
|
---|
| 158 | size_t i = x.size();
|
---|
| 159 | if ( i > 0 ) {
|
---|
| 160 | start = new T[ i ];
|
---|
| 161 | finish = start + i;
|
---|
| 162 | end = start + i;
|
---|
| 163 | #if defined(__xlC__) && __xlC__ < 0x400 // xlC 3.6 confused by const
|
---|
| 164 | qCopy( (pointer)x.start, (pointer)x.finish, start );
|
---|
| 165 | #else
|
---|
| 166 | qCopy( x.start, x.finish, start );
|
---|
| 167 | #endif
|
---|
| 168 | } else {
|
---|
| 169 | start = 0;
|
---|
| 170 | finish = 0;
|
---|
| 171 | end = 0;
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | template <class T>
|
---|
| 176 | Q_INLINE_TEMPLATES QValueVectorPrivate<T>::QValueVectorPrivate( size_t size )
|
---|
| 177 | {
|
---|
| 178 | if ( size > 0 ) {
|
---|
| 179 | start = new T[size];
|
---|
| 180 | finish = start + size;
|
---|
| 181 | end = start + size;
|
---|
| 182 | } else {
|
---|
| 183 | start = 0;
|
---|
| 184 | finish = 0;
|
---|
| 185 | end = 0;
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | template <class T>
|
---|
| 190 | Q_INLINE_TEMPLATES void QValueVectorPrivate<T>::insert( pointer pos, const T& x )
|
---|
| 191 | {
|
---|
| 192 | const size_t lastSize = size();
|
---|
| 193 | const size_t n = lastSize !=0 ? 2*lastSize : 1;
|
---|
| 194 | const size_t offset = pos - start;
|
---|
| 195 | pointer newStart = new T[n];
|
---|
| 196 | pointer newFinish = newStart + offset;
|
---|
| 197 | qCopy( start, pos, newStart );
|
---|
| 198 | *newFinish = x;
|
---|
| 199 | qCopy( pos, finish, ++newFinish );
|
---|
| 200 | delete[] start;
|
---|
| 201 | start = newStart;
|
---|
| 202 | finish = newStart + lastSize + 1;
|
---|
| 203 | end = newStart + n;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | template <class T>
|
---|
| 207 | Q_INLINE_TEMPLATES void QValueVectorPrivate<T>::insert( pointer pos, size_t n, const T& x )
|
---|
| 208 | {
|
---|
| 209 | if ( size_t( end - finish ) >= n ) {
|
---|
| 210 | // enough room
|
---|
| 211 | const size_t elems_after = finish - pos;
|
---|
| 212 | pointer old_finish = finish;
|
---|
| 213 | if ( elems_after > n ) {
|
---|
| 214 | qCopy( finish - n, finish, finish );
|
---|
| 215 | finish += n;
|
---|
| 216 | qCopyBackward( pos, old_finish - n, old_finish );
|
---|
| 217 | qFill( pos, pos + n, x );
|
---|
| 218 | } else {
|
---|
| 219 | pointer filler = finish;
|
---|
| 220 | size_t i = n - elems_after;
|
---|
| 221 | for ( ; i > 0; --i, ++filler )
|
---|
| 222 | *filler = x;
|
---|
| 223 | finish += n - elems_after;
|
---|
| 224 | qCopy( pos, old_finish, finish );
|
---|
| 225 | finish += elems_after;
|
---|
| 226 | qFill( pos, old_finish, x );
|
---|
| 227 | }
|
---|
| 228 | } else {
|
---|
| 229 | // not enough room
|
---|
| 230 | const size_t lastSize = size();
|
---|
| 231 | const size_t len = lastSize + QMAX( lastSize, n );
|
---|
| 232 | pointer newStart = new T[len];
|
---|
| 233 | pointer newFinish = qCopy( start, pos, newStart );
|
---|
| 234 | // fill up inserted space
|
---|
| 235 | size_t i = n;
|
---|
| 236 | for ( ; i > 0; --i, ++newFinish )
|
---|
| 237 | *newFinish = x;
|
---|
| 238 | newFinish = qCopy( pos, finish, newFinish );
|
---|
| 239 | delete[] start;
|
---|
| 240 | start = newStart;
|
---|
| 241 | finish = newFinish;
|
---|
| 242 | end = newStart + len;
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | template <class T>
|
---|
| 247 | Q_INLINE_TEMPLATES void QValueVectorPrivate<T>::reserve( size_t n )
|
---|
| 248 | {
|
---|
| 249 | const size_t lastSize = size();
|
---|
| 250 | pointer tmp = growAndCopy( n, start, finish );
|
---|
| 251 | start = tmp;
|
---|
| 252 | finish = tmp + lastSize;
|
---|
| 253 | end = start + n;
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | template <class T>
|
---|
| 257 | Q_INLINE_TEMPLATES Q_TYPENAME QValueVectorPrivate<T>::pointer QValueVectorPrivate<T>::growAndCopy( size_t n, pointer s, pointer f )
|
---|
| 258 | {
|
---|
| 259 | pointer newStart = new T[n];
|
---|
| 260 | qCopy( s, f, newStart );
|
---|
| 261 | delete[] start;
|
---|
| 262 | return newStart;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | template <class T> class QDeepCopy;
|
---|
| 266 |
|
---|
| 267 | template <class T>
|
---|
| 268 | class QValueVector
|
---|
| 269 | {
|
---|
| 270 | public:
|
---|
| 271 | typedef T value_type;
|
---|
| 272 | typedef value_type* pointer;
|
---|
| 273 | typedef const value_type* const_pointer;
|
---|
| 274 | typedef value_type* iterator;
|
---|
| 275 | typedef const value_type* const_iterator;
|
---|
| 276 | typedef value_type& reference;
|
---|
| 277 | typedef const value_type& const_reference;
|
---|
| 278 | typedef size_t size_type;
|
---|
| 279 | #ifndef QT_NO_STL
|
---|
| 280 | typedef ptrdiff_t difference_type;
|
---|
| 281 | #else
|
---|
| 282 | typedef int difference_type;
|
---|
| 283 | #endif
|
---|
| 284 |
|
---|
| 285 | QValueVector()
|
---|
| 286 | {
|
---|
| 287 | sh = new QValueVectorPrivate<T>;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | QValueVector( const QValueVector<T>& v )
|
---|
| 291 | {
|
---|
| 292 | sh = v.sh;
|
---|
| 293 | sh->ref();
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | QValueVector( size_type n, const T& val = T() );
|
---|
| 297 |
|
---|
| 298 | #ifndef QT_NO_STL
|
---|
| 299 | QValueVector( std::vector<T>& v ) // ### remove in 4.0
|
---|
| 300 | {
|
---|
| 301 | sh = new QValueVectorPrivate<T>( v.size() );
|
---|
| 302 | qCopy( v.begin(), v.end(), begin() );
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | QValueVector( const std::vector<T>& v )
|
---|
| 306 | {
|
---|
| 307 | sh = new QValueVectorPrivate<T>( v.size() );
|
---|
| 308 | qCopy( v.begin(), v.end(), begin() );
|
---|
| 309 | }
|
---|
| 310 | #endif
|
---|
| 311 |
|
---|
| 312 | ~QValueVector()
|
---|
| 313 | {
|
---|
| 314 | sh->derefAndDelete();
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | QValueVector<T>& operator= ( const QValueVector<T>& v )
|
---|
| 318 | {
|
---|
| 319 | v.sh->ref();
|
---|
| 320 | sh->derefAndDelete();
|
---|
| 321 | sh = v.sh;
|
---|
| 322 | return *this;
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | #ifndef QT_NO_STL
|
---|
| 326 | QValueVector<T>& operator= ( const std::vector<T>& v )
|
---|
| 327 | {
|
---|
| 328 | clear();
|
---|
| 329 | resize( v.size() );
|
---|
| 330 | qCopy( v.begin(), v.end(), begin() );
|
---|
| 331 | return *this;
|
---|
| 332 | }
|
---|
| 333 | #endif
|
---|
| 334 |
|
---|
| 335 | size_type size() const { return sh->size(); }
|
---|
| 336 |
|
---|
| 337 | bool empty() const { return sh->empty(); }
|
---|
| 338 |
|
---|
| 339 | size_type capacity() const
|
---|
| 340 | {
|
---|
| 341 | return size_type( sh->capacity() );
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | iterator begin()
|
---|
| 345 | {
|
---|
| 346 | detach();
|
---|
| 347 | return sh->start;
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | const_iterator begin() const
|
---|
| 351 | {
|
---|
| 352 | return sh->start;
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | const_iterator constBegin() const
|
---|
| 356 | {
|
---|
| 357 | return sh->start;
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 | iterator end()
|
---|
| 361 | {
|
---|
| 362 | detach();
|
---|
| 363 | return sh->finish;
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | const_iterator end() const
|
---|
| 367 | {
|
---|
| 368 | return sh->finish;
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | const_iterator constEnd() const
|
---|
| 372 | {
|
---|
| 373 | return sh->finish;
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | reference at( size_type i, bool* ok = 0 )
|
---|
| 377 | {
|
---|
| 378 | detach();
|
---|
| 379 | if ( ok )
|
---|
| 380 | *ok = ( i < size() );
|
---|
| 381 | return *( begin() + i );
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | const_reference at( size_type i, bool* ok = 0 ) const
|
---|
| 385 | {
|
---|
| 386 | if ( ok )
|
---|
| 387 | *ok = ( i < size() );
|
---|
| 388 | return *( begin() + i );
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 | reference operator[]( size_type i )
|
---|
| 392 | {
|
---|
| 393 | detach();
|
---|
| 394 | return *( begin() + i );
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | const_reference operator[]( size_type i ) const
|
---|
| 398 | {
|
---|
| 399 | return *( begin() + i );
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | reference front()
|
---|
| 403 | {
|
---|
| 404 | Q_ASSERT( !empty() );
|
---|
| 405 | detach();
|
---|
| 406 | return *begin();
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | const_reference front() const
|
---|
| 410 | {
|
---|
| 411 | Q_ASSERT( !empty() );
|
---|
| 412 | return *begin();
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | reference back()
|
---|
| 416 | {
|
---|
| 417 | Q_ASSERT( !empty() );
|
---|
| 418 | detach();
|
---|
| 419 | return *( end() - 1 );
|
---|
| 420 | }
|
---|
| 421 |
|
---|
| 422 | const_reference back() const
|
---|
| 423 | {
|
---|
| 424 | Q_ASSERT( !empty() );
|
---|
| 425 | return *( end() - 1 );
|
---|
| 426 | }
|
---|
| 427 |
|
---|
| 428 | void push_back( const T& x )
|
---|
| 429 | {
|
---|
| 430 | detach();
|
---|
| 431 | if ( sh->finish == sh->end ) {
|
---|
| 432 | sh->reserve( size()+size()/2+1 );
|
---|
| 433 | }
|
---|
| 434 | *sh->finish = x;
|
---|
| 435 | ++sh->finish;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 | void pop_back()
|
---|
| 439 | {
|
---|
| 440 | detach();
|
---|
| 441 | if ( empty() )
|
---|
| 442 | return;
|
---|
| 443 | --sh->finish;
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | iterator insert( iterator pos, const T& x );
|
---|
| 447 | iterator insert( iterator pos, size_type n, const T& x );
|
---|
| 448 |
|
---|
| 449 | void reserve( size_type n )
|
---|
| 450 | {
|
---|
| 451 | if ( capacity() < n ) {
|
---|
| 452 | detach();
|
---|
| 453 | sh->reserve( n );
|
---|
| 454 | }
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | void resize( size_type n, const T& val = T() )
|
---|
| 458 | {
|
---|
| 459 | if ( n < size() )
|
---|
| 460 | erase( begin() + n, end() );
|
---|
| 461 | else
|
---|
| 462 | insert( end(), n - size(), val );
|
---|
| 463 | }
|
---|
| 464 |
|
---|
| 465 | void clear()
|
---|
| 466 | {
|
---|
| 467 | detach();
|
---|
| 468 | sh->clear();
|
---|
| 469 | }
|
---|
| 470 |
|
---|
| 471 | iterator erase( iterator pos )
|
---|
| 472 | {
|
---|
| 473 | detach();
|
---|
| 474 | if ( pos + 1 != end() )
|
---|
| 475 | qCopy( pos + 1, sh->finish, pos );
|
---|
| 476 | --sh->finish;
|
---|
| 477 | return pos;
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 | iterator erase( iterator first, iterator last )
|
---|
| 481 | {
|
---|
| 482 | detach();
|
---|
| 483 | qCopy( last, sh->finish, first );
|
---|
| 484 | sh->finish = sh->finish - ( last - first );
|
---|
| 485 | return first;
|
---|
| 486 | }
|
---|
| 487 |
|
---|
| 488 | // ### remove in Qt 4.0
|
---|
| 489 | bool operator==( const QValueVector<T>& x )
|
---|
| 490 | {
|
---|
| 491 | return size()==x.size() ? qEqual( constBegin(), constEnd(), x.begin()) : FALSE;
|
---|
| 492 | }
|
---|
| 493 |
|
---|
| 494 | bool operator==( const QValueVector<T>& x ) const
|
---|
| 495 | {
|
---|
| 496 | return size()==x.size() ? qEqual( begin(), end(), x.begin() ) : FALSE;
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | typedef T ValueType;
|
---|
| 500 | typedef ValueType *Iterator;
|
---|
| 501 | typedef const ValueType *ConstIterator;
|
---|
| 502 |
|
---|
| 503 | size_type count() const { return size(); }
|
---|
| 504 | bool isEmpty() const { return empty(); }
|
---|
| 505 |
|
---|
| 506 | reference first() { return front(); }
|
---|
| 507 | const_reference first() const { return front(); }
|
---|
| 508 | reference last() { return back(); }
|
---|
| 509 | const_reference last() const { return back(); }
|
---|
| 510 | void append( const T& x ) { push_back( x ); }
|
---|
| 511 |
|
---|
| 512 | protected:
|
---|
| 513 | void detach()
|
---|
| 514 | {
|
---|
| 515 | if ( sh->count > 1 ) { detachInternal(); }
|
---|
| 516 | }
|
---|
| 517 | void detachInternal();
|
---|
| 518 | QValueVectorPrivate<T>* sh;
|
---|
| 519 |
|
---|
| 520 | private:
|
---|
| 521 | friend class QDeepCopy< QValueVector<T> >;
|
---|
| 522 | };
|
---|
| 523 |
|
---|
| 524 | template <class T>
|
---|
| 525 | Q_INLINE_TEMPLATES QValueVector<T>::QValueVector( size_type n, const T& val )
|
---|
| 526 | {
|
---|
| 527 | sh = new QValueVectorPrivate<T>( n );
|
---|
| 528 | qFill( begin(), end(), val );
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | template <class T>
|
---|
| 532 | Q_INLINE_TEMPLATES void QValueVector<T>::detachInternal()
|
---|
| 533 | {
|
---|
| 534 | sh->deref();
|
---|
| 535 | sh = new QValueVectorPrivate<T>( *sh );
|
---|
| 536 | }
|
---|
| 537 |
|
---|
| 538 | template <class T>
|
---|
| 539 | Q_INLINE_TEMPLATES Q_TYPENAME QValueVector<T>::iterator QValueVector<T>::insert( iterator pos, const T& x )
|
---|
| 540 | {
|
---|
| 541 | size_type offset = pos - sh->start;
|
---|
| 542 | detach();
|
---|
| 543 | if ( pos == end() ) {
|
---|
| 544 | if ( sh->finish == sh->end )
|
---|
| 545 | push_back( x );
|
---|
| 546 | else {
|
---|
| 547 | *sh->finish = x;
|
---|
| 548 | ++sh->finish;
|
---|
| 549 | }
|
---|
| 550 | } else {
|
---|
| 551 | if ( sh->finish == sh->end ) {
|
---|
| 552 | sh->insert( pos, x );
|
---|
| 553 | } else {
|
---|
| 554 | *sh->finish = *(sh->finish - 1);
|
---|
| 555 | ++sh->finish;
|
---|
| 556 | qCopyBackward( pos, sh->finish - 2, sh->finish - 1 );
|
---|
| 557 | *pos = x;
|
---|
| 558 | }
|
---|
| 559 | }
|
---|
| 560 | return begin() + offset;
|
---|
| 561 | }
|
---|
| 562 |
|
---|
| 563 | template <class T>
|
---|
| 564 | Q_INLINE_TEMPLATES Q_TYPENAME QValueVector<T>::iterator QValueVector<T>::insert( iterator pos, size_type n, const T& x )
|
---|
| 565 | {
|
---|
| 566 | if ( n != 0 ) {
|
---|
| 567 | size_type offset = pos - sh->start;
|
---|
| 568 | detach();
|
---|
| 569 | pos = begin() + offset;
|
---|
| 570 | sh->insert( pos, n, x );
|
---|
| 571 | }
|
---|
| 572 | return pos;
|
---|
| 573 | }
|
---|
| 574 |
|
---|
| 575 |
|
---|
| 576 | #ifndef QT_NO_DATASTREAM
|
---|
| 577 | template<class T>
|
---|
| 578 | Q_INLINE_TEMPLATES QDataStream& operator>>( QDataStream& s, QValueVector<T>& v )
|
---|
| 579 | {
|
---|
| 580 | v.clear();
|
---|
| 581 | Q_UINT32 c;
|
---|
| 582 | s >> c;
|
---|
| 583 | v.resize( c );
|
---|
| 584 | for( Q_UINT32 i = 0; i < c; ++i )
|
---|
| 585 | {
|
---|
| 586 | T t;
|
---|
| 587 | s >> t;
|
---|
| 588 | v[i] = t;
|
---|
| 589 | }
|
---|
| 590 | return s;
|
---|
| 591 | }
|
---|
| 592 |
|
---|
| 593 | template<class T>
|
---|
| 594 | Q_INLINE_TEMPLATES QDataStream& operator<<( QDataStream& s, const QValueVector<T>& v )
|
---|
| 595 | {
|
---|
| 596 | s << (Q_UINT32)v.size();
|
---|
| 597 | // ### use typename QValueVector<T>::const_iterator once all supported
|
---|
| 598 | // ### compilers know about the 'typename' keyword.
|
---|
| 599 | const T* it = v.begin();
|
---|
| 600 | for( ; it != v.end(); ++it )
|
---|
| 601 | s << *it;
|
---|
| 602 | return s;
|
---|
| 603 | }
|
---|
| 604 | #endif // QT_NO_DATASTREAM
|
---|
| 605 |
|
---|
| 606 | #define Q_DEFINED_QVALUEVECTOR
|
---|
| 607 | #include "qwinexport.h"
|
---|
| 608 | #endif // QVALUEVECTOR_H
|
---|
| 609 | </pre>
|
---|
| 610 | <!-- eof -->
|
---|
| 611 | <p><address><hr><div align=center>
|
---|
| 612 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 613 | <td>Copyright © 2007
|
---|
| 614 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 615 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 616 | </table></div></address></body>
|
---|
| 617 | </html>
|
---|