summaryrefslogtreecommitdiff
path: root/qmake/tools/qgvector.cpp
Unidiff
Diffstat (limited to 'qmake/tools/qgvector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qgvector.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/qmake/tools/qgvector.cpp b/qmake/tools/qgvector.cpp
index 1985f03..3c903ed 100644
--- a/qmake/tools/qgvector.cpp
+++ b/qmake/tools/qgvector.cpp
@@ -1,85 +1,91 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Implementation of QGVector class 4** Implementation of QGVector class
5** 5**
6** Created : 930907 6** Created : 930907
7** 7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the tools module of the Qt GUI Toolkit. 10** This file is part of the tools module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 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 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 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 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 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "qglobal.h"
39#if defined(Q_CC_BOR)
40// needed for qsort() because of a std namespace problem on Borland
41#include "qplatformdefs.h"
42#endif
43
38 #define QGVECTOR_CPP 44 #define QGVECTOR_CPP
39#include "qgvector.h" 45#include "qgvector.h"
40#include "qglist.h" 46#include "qglist.h"
41#include "qstring.h" 47#include "qstring.h"
42#include "qdatastream.h" 48#include "qdatastream.h"
43#include <stdlib.h> 49#include <stdlib.h>
44 50
45#ifdef QT_THREAD_SUPPORT 51#ifdef QT_THREAD_SUPPORT
46# include <private/qmutexpool_p.h> 52# include <private/qmutexpool_p.h>
47#endif // QT_THREAD_SUPPORT 53#endif // QT_THREAD_SUPPORT
48 54
49 #define USE_MALLOC // comment to use new/delete 55 #define USE_MALLOC // comment to use new/delete
50 56
51#undef NEW 57#undef NEW
52#undef DELETE 58#undef DELETE
53 59
54#if defined(USE_MALLOC) 60#if defined(USE_MALLOC)
55 #define NEW(type,size)((type*)malloc(size*sizeof(type))) 61 #define NEW(type,size)((type*)malloc(size*sizeof(type)))
56 #define DELETE(array)(free((char*)array)) 62 #define DELETE(array)(free((char*)array))
57#else 63#else
58 #define NEW(type,size)(new type[size]) 64 #define NEW(type,size)(new type[size])
59 #define DELETE(array)(delete[] array) 65 #define DELETE(array)(delete[] array)
60 #define DONT_USE_REALLOC // comment to use realloc() 66 #define DONT_USE_REALLOC // comment to use realloc()
61#endif 67#endif
62 68
63/*! 69/*!
64 \class QGVector 70 \class QGVector
65 \reentrant 71 \reentrant
66 \ingroup collection 72 \ingroup collection
67 73
68 \brief The QGVector class is an internal class for implementing Qt 74 \brief The QGVector class is an internal class for implementing Qt
69 collection classes. 75 collection classes.
70 76
71 \internal 77 \internal
72 78
73 QGVector is an internal class that acts as a base class for the 79 QGVector is an internal class that acts as a base class for the
74 QPtrVector collection class. 80 QPtrVector collection class.
75 81
76 QGVector has some virtual functions that may be reimplemented in 82 QGVector has some virtual functions that may be reimplemented in
77 subclasses to customize behavior. 83 subclasses to customize behavior.
78 84
79 \list 85 \list
80 \i compareItems() compares two collection/vector items. 86 \i compareItems() compares two collection/vector items.
81 \i read() reads a collection/vector item from a QDataStream. 87 \i read() reads a collection/vector item from a QDataStream.
82 \i write() writes a collection/vector item to a QDataStream. 88 \i write() writes a collection/vector item to a QDataStream.
83 \endlist 89 \endlist
84*/ 90*/
85 91
@@ -348,97 +354,98 @@ bool QGVector::fill( Item d, int flen ) // resize and fill vector
348 insert( i, d ); 354 insert( i, d );
349 return TRUE; 355 return TRUE;
350} 356}
351 357
352 358
353 static QGVector *sort_vec=0; // current sort vector 359 static QGVector *sort_vec=0; // current sort vector
354 360
355 361
356#if defined(Q_C_CALLBACKS) 362#if defined(Q_C_CALLBACKS)
357extern "C" { 363extern "C" {
358#endif 364#endif
359 365
360#ifdef Q_OS_TEMP 366#ifdef Q_OS_TEMP
361static int _cdecl cmp_vec( const void *n1, const void *n2 ) 367static int _cdecl cmp_vec( const void *n1, const void *n2 )
362#else 368#else
363static int cmp_vec( const void *n1, const void *n2 ) 369static int cmp_vec( const void *n1, const void *n2 )
364#endif 370#endif
365{ 371{
366 return sort_vec->compareItems( *((QPtrCollection::Item*)n1), *((QPtrCollection::Item*)n2) ); 372 return sort_vec->compareItems( *((QPtrCollection::Item*)n1), *((QPtrCollection::Item*)n2) );
367} 373}
368 374
369#if defined(Q_C_CALLBACKS) 375#if defined(Q_C_CALLBACKS)
370} 376}
371#endif 377#endif
372 378
373 379
374 void QGVector::sort() // sort vector 380 void QGVector::sort() // sort vector
375{ 381{
376 if ( count() == 0 ) // no elements 382 if ( count() == 0 ) // no elements
377 return; 383 return;
378 register Item *start = &vec[0]; 384 register Item *start = &vec[0];
379 register Item *end= &vec[len-1]; 385 register Item *end= &vec[len-1];
380 Item tmp; 386 Item tmp;
381 for (;;) { // put all zero elements behind 387 for (;;) { // put all zero elements behind
382 while ( start < end && *start != 0 ) 388 while ( start < end && *start != 0 )
383 start++; 389 start++;
384 while ( end > start && *end == 0 ) 390 while ( end > start && *end == 0 )
385 end--; 391 end--;
386 if ( start < end ) { 392 if ( start < end ) {
387 tmp = *start; 393 tmp = *start;
388 *start = *end; 394 *start = *end;
389 *end = tmp; 395 *end = tmp;
390 } else { 396 } else {
391 break; 397 break;
392 } 398 }
393 } 399 }
394 400
395#ifdef QT_THREAD_SUPPORT 401#ifdef QT_THREAD_SUPPORT
396 QMutexLocker locker( qt_global_mutexpool->get( &sort_vec ) ); 402 QMutexLocker locker( qt_global_mutexpool ?
403 qt_global_mutexpool->get( &sort_vec ) : 0 );
397#endif // QT_THREAD_SUPPORT 404#endif // QT_THREAD_SUPPORT
398 405
399 sort_vec = (QGVector*)this; 406 sort_vec = (QGVector*)this;
400 qsort( vec, count(), sizeof(Item), cmp_vec ); 407 qsort( vec, count(), sizeof(Item), cmp_vec );
401 sort_vec = 0; 408 sort_vec = 0;
402} 409}
403 410
404 int QGVector::bsearch( Item d ) const // binary search; when sorted 411 int QGVector::bsearch( Item d ) const // binary search; when sorted
405{ 412{
406 if ( !len ) 413 if ( !len )
407 return -1; 414 return -1;
408 if ( !d ) { 415 if ( !d ) {
409#if defined(QT_CHECK_NULL) 416#if defined(QT_CHECK_NULL)
410 qWarning( "QGVector::bsearch: Cannot search for null object" ); 417 qWarning( "QGVector::bsearch: Cannot search for null object" );
411#endif 418#endif
412 return -1; 419 return -1;
413 } 420 }
414 int n1 = 0; 421 int n1 = 0;
415 int n2 = len - 1; 422 int n2 = len - 1;
416 int mid = 0; 423 int mid = 0;
417 bool found = FALSE; 424 bool found = FALSE;
418 while ( n1 <= n2 ) { 425 while ( n1 <= n2 ) {
419 int res; 426 int res;
420 mid = (n1 + n2)/2; 427 mid = (n1 + n2)/2;
421 if ( vec[mid] == 0 ) // null item greater 428 if ( vec[mid] == 0 ) // null item greater
422 res = -1; 429 res = -1;
423 else 430 else
424 res = ((QGVector*)this)->compareItems( d, vec[mid] ); 431 res = ((QGVector*)this)->compareItems( d, vec[mid] );
425 if ( res < 0 ) 432 if ( res < 0 )
426 n2 = mid - 1; 433 n2 = mid - 1;
427 else if ( res > 0 ) 434 else if ( res > 0 )
428 n1 = mid + 1; 435 n1 = mid + 1;
429 else { // found it 436 else { // found it
430 found = TRUE; 437 found = TRUE;
431 break; 438 break;
432 } 439 }
433 } 440 }
434 if ( !found ) 441 if ( !found )
435 return -1; 442 return -1;
436 // search to first of equal items 443 // search to first of equal items
437 while ( (mid - 1 >= 0) && !((QGVector*)this)->compareItems(d, vec[mid-1]) ) 444 while ( (mid - 1 >= 0) && !((QGVector*)this)->compareItems(d, vec[mid-1]) )
438 mid--; 445 mid--;
439 return mid; 446 return mid;
440} 447}
441 448
442int QGVector::findRef( Item d, uint index) const // find exact item in vector 449int QGVector::findRef( Item d, uint index) const // find exact item in vector
443{ 450{
444#if defined(QT_CHECK_RANGE) 451#if defined(QT_CHECK_RANGE)