qgvector.h
Go to the documentation of this file.
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:
106 
107  static void warningIndexRange( uint );
108 };
109 
110 
111 /*****************************************************************************
112  QGVector stream functions
113  *****************************************************************************/
114 
115 #ifndef QT_NO_DATASTREAM
118 #endif
119 
120 #endif // QGVECTOR_H
uint contains(QCollection::Item) const
Definition: qglist.cpp:751
QCollection::Item take()
Definition: qglist.cpp:595
virtual int compareItems(QCollection::Item, QCollection::Item)
Definition: qglist.cpp:125
size_t write(int, const char *, size_t)
Writes count bytes from buf to the filedescriptor fd.
friend class QGVector
Definition: qglist.h:71
Q_EXPORT QDataStream & operator>>(QDataStream &, QGVector &)
Definition: qgvector.cpp:592
void resize(Vector< T > &vec1, Index n1, const V &val)
uint containsRef(QCollection::Item) const
Definition: qglist.cpp:734
Item at(uint index) const
Definition: qgvector.h:85
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
uint size() const
Definition: qgvector.h:65
The QGList class is an internal class for implementing Qt collection classes.
Definition: qglist.h:68
The QCollection class is the base class of all Qt collections.
Definition: qcollection.h:51
virtual void clear()=0
The QGVector class is an internal class for implementing Qt collection classes.
Definition: qgvector.h:46
uint count() const
Definition: qgvector.h:66
void sort()
Definition: qglist.cpp:934
int findRef(QCollection::Item, bool=TRUE)
Definition: qglist.cpp:683
Item * vec
Definition: qgvector.h:103
def fill(s)
Definition: translator.py:93
Item * data() const
Definition: qgvector.h:64
Q_EXPORT QDataStream & operator<<(QDataStream &, const QGVector &)
Definition: qgvector.cpp:597
uint numItems
Definition: qgvector.h:105
int read(int, char *, size_t)
Read bytes from a file descriptor.
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:47
uint len
Definition: qgvector.h:104
unsigned uint
Definition: qglobal.h:351
QGList & operator=(const QGList &)
Definition: qglist.cpp:222
#define Q_EXPORT
Definition: qglobal.h:468
void * Item
Definition: qcollection.h:60
int find(QCollection::Item, bool=TRUE)
Definition: qglist.cpp:708