1 /****************************************************************************
2 ** $Id: qt/qgvector.h   3.3.8   edited Jan 11 14:38 $
3 **
4 ** Definition of QGVector class
5 **
6 ** Created : 930907
7 **
8 ** Copyright (C) 1992-2007 Trolltech ASA.  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 ASA 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 "qptrcollection.h"
43 #endif // QT_H
44 
45 
46 class Q_EXPORT QGVector : public QPtrCollection	// 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     bool operator==( const QGVector &v ) const;
64 
data()65     Item	 *data()    const	{ return vec; }
size()66     uint  size()    const	{ return len; }
count()67     uint  count()   const	{ return numItems; }
68 
69     bool  insert( uint index, Item );		// insert item at index
70     bool  remove( uint index );			// remove item
71     Item	  take( uint index );			// take out item
72 
73     void  clear();				// clear vector
74     bool  resize( uint newsize );		// resize vector
75 
76     bool  fill( Item, int flen );		// resize and fill vector
77 
78     void  sort();				// sort vector
79     int	  bsearch( Item ) const;			// binary search (when sorted)
80 
81     int	  findRef( Item, uint index ) const;	// find exact item in vector
82     int	  find( Item, uint index ) const;	// find equal item in vector
83     uint  containsRef( Item ) const;		// get number of exact matches
84     uint  contains( Item ) const;		// get number of equal matches
85 
at(uint index)86     Item	  at( uint index ) const		// return indexed item
87     {
88 #if defined(QT_CHECK_RANGE)
89 	if ( index >= len )
90 	    warningIndexRange( index );
91 #endif
92 	return vec[index];
93     }
94 
95     bool insertExpand( uint index, Item );	// insert, expand if necessary
96 
97     void toList( QGList * ) const;		// put items in list
98 
99 #ifndef QT_NO_DATASTREAM
100     virtual QDataStream &read( QDataStream &, Item & );
101     virtual QDataStream &write( QDataStream &, Item ) const;
102 #endif
103 private:
104     Item	 *vec;
105     uint  len;
106     uint  numItems;
107 
108     static void warningIndexRange( uint );
109 };
110 
111 
112 /*****************************************************************************
113   QGVector stream functions
114  *****************************************************************************/
115 
116 #ifndef QT_NO_DATASTREAM
117 Q_EXPORT QDataStream &operator>>( QDataStream &, QGVector & );
118 Q_EXPORT QDataStream &operator<<( QDataStream &, const QGVector & );
119 #endif
120 
121 #endif // QGVECTOR_H
122