|
1 /**************************************************************************** |
|
2 ** |
|
3 ** |
|
4 ** Definition of QGVector class |
|
5 ** |
|
6 ** Created : 930907 |
|
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 QGVECTOR_H |
|
39 #define QGVECTOR_H |
|
40 |
|
41 #ifndef QT_H |
|
42 #include "qcollection.h" |
|
43 #endif // QT_H |
|
44 |
|
45 |
|
46 class Q_EXPORT QGVector : public QCollection // generic vector |
|
47 { |
|
48 friend class QGList; // needed by QGList::toVector |
|
49 public: |
|
50 #ifndef QT_NO_DATASTREAM |
|
51 QDataStream &read( QDataStream & ); // read vector from stream |
|
52 QDataStream &write( QDataStream & ) const; // write vector to stream |
|
53 #endif |
|
54 virtual int compareItems( Item, Item ); |
|
55 |
|
56 protected: |
|
57 QGVector(); // create empty vector |
|
58 QGVector( uint size ); // create vector with nullptrs |
|
59 QGVector( const QGVector &v ); // make copy of other vector |
|
60 ~QGVector(); |
|
61 |
|
62 QGVector &operator=( const QGVector &v ); // assign from other vector |
|
63 |
|
64 Item *data() const { return vec; } |
|
65 uint size() const { return len; } |
|
66 uint count() const { return numItems; } |
|
67 |
|
68 bool insert( uint index, Item ); // insert item at index |
|
69 bool remove( uint index ); // remove item |
|
70 Item take( uint index ); // take out item |
|
71 |
|
72 void clear(); // clear vector |
|
73 bool resize( uint newsize ); // resize vector |
|
74 |
|
75 bool fill( Item, int flen ); // resize and fill vector |
|
76 |
|
77 void sort(); // sort vector |
|
78 int bsearch( Item ) const; // binary search (when sorted) |
|
79 |
|
80 int findRef( Item, uint index ) const; // find exact item in vector |
|
81 int find( Item, uint index ) const; // find equal item in vector |
|
82 uint containsRef( Item ) const; // get number of exact matches |
|
83 uint contains( Item ) const; // get number of equal matches |
|
84 |
|
85 Item at( uint index ) const // return indexed item |
|
86 { |
|
87 #if defined(CHECK_RANGE) |
|
88 if ( index >= len ) |
|
89 warningIndexRange( index ); |
|
90 #endif |
|
91 return vec[index]; |
|
92 } |
|
93 |
|
94 bool insertExpand( uint index, Item ); // insert, expand if necessary |
|
95 |
|
96 void toList( QGList * ) const; // put items in list |
|
97 |
|
98 #ifndef QT_NO_DATASTREAM |
|
99 virtual QDataStream &read( QDataStream &, Item & ); |
|
100 virtual QDataStream &write( QDataStream &, Item ) const; |
|
101 #endif |
|
102 private: |
|
103 Item *vec; |
|
104 uint len; |
|
105 uint numItems; |
|
106 |
|
107 static void warningIndexRange( uint ); |
|
108 }; |
|
109 |
|
110 |
|
111 /***************************************************************************** |
|
112 QGVector stream functions |
|
113 *****************************************************************************/ |
|
114 |
|
115 #ifndef QT_NO_DATASTREAM |
|
116 Q_EXPORT QDataStream &operator>>( QDataStream &, QGVector & ); |
|
117 Q_EXPORT QDataStream &operator<<( QDataStream &, const QGVector & ); |
|
118 #endif |
|
119 |
|
120 #endif // QGVECTOR_H |