qgdict.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 **
4 ** Definition of QGDict and QGDictIterator classes
5 **
6 ** Created : 920529
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 QGDICT_H
39 #define QGDICT_H
40 
41 #ifndef QT_H
42 #include "qcollection.h"
43 #include "qstring.h"
44 #endif // QT_H
45 
46 class QGDictIterator;
47 class QGDItList;
48 
49 
50 class QBaseBucket // internal dict node
51 {
52 public:
55  QBaseBucket *getNext() { return next; }
56  void setNext( QBaseBucket *n) { next = n; }
57 protected:
61 };
62 
63 class QStringBucket : public QBaseBucket
64 {
65 public:
67  : QBaseBucket(d,n), key(k) {}
68  const QString &getKey() const { return key; }
69 private:
71 };
72 
73 class QAsciiBucket : public QBaseBucket
74 {
75 public:
77  : QBaseBucket(d,n), key(k) {}
78  const char *getKey() const { return key; }
79 private:
80  const char *key;
81 };
82 
83 class QIntBucket : public QBaseBucket
84 {
85 public:
87  : QBaseBucket(d,n), key(k) {}
88  intptr_t getKey() const { return key; }
89 private:
90  intptr_t key;
91 };
92 
93 class QPtrBucket : public QBaseBucket
94 {
95 public:
97  : QBaseBucket(d,n), key(k) {}
98  void *getKey() const { return key; }
99 private:
100  void *key;
101 };
102 
103 
104 class Q_EXPORT QGDict : public QCollection // generic dictionary class
105 {
106 public:
107  uint count() const { return numItems; }
108  uint size() const { return vlen; }
109  QCollection::Item look_string( const QString& key, QCollection::Item,
110  int );
111  QCollection::Item look_ascii( const char *key, QCollection::Item, int );
112  QCollection::Item look_int( long key, QCollection::Item, int );
113  QCollection::Item look_ptr( void *key, QCollection::Item, int );
114 #ifndef QT_NO_DATASTREAM
116  QDataStream &write( QDataStream & ) const;
117 #endif
118 protected:
119  enum KeyType { StringKey, AsciiKey, IntKey, PtrKey };
120 
121  QGDict( uint len, KeyType kt, bool cs, bool ck );
122  QGDict( const QGDict & );
123  ~QGDict();
124 
125  QGDict &operator=( const QGDict & );
126 
127  bool remove_string( const QString &key, QCollection::Item item=0 );
128  bool remove_ascii( const char *key, QCollection::Item item=0 );
129  bool remove_int( long key, QCollection::Item item=0 );
130  bool remove_ptr( void *key, QCollection::Item item=0 );
131  QCollection::Item take_string( const QString &key );
132  QCollection::Item take_ascii( const char *key );
133  QCollection::Item take_int( long key );
134  QCollection::Item take_ptr( void *key );
135 
136  void clear();
137  void resize( uint );
138 
139  int hashKeyString( const QString & );
140  int hashKeyAscii( const char * );
141 
142  void statistics() const;
143 
144 #ifndef QT_NO_DATASTREAM
146  virtual QDataStream &write( QDataStream &, QCollection::Item ) const;
147 #endif
148 private:
152  uint keytype : 2;
153  uint cases : 1;
154  uint copyk : 1;
156  void unlink_common( int, QBaseBucket *, QBaseBucket * );
157  QStringBucket *unlink_string( const QString &,
158  QCollection::Item item = 0 );
159  QAsciiBucket *unlink_ascii( const char *, QCollection::Item item = 0 );
160  QIntBucket *unlink_int( long, QCollection::Item item = 0 );
161  QPtrBucket *unlink_ptr( void *, QCollection::Item item = 0 );
162  void init( uint, KeyType, bool, bool );
163  friend class QGDictIterator;
164 };
165 
166 
167 class Q_EXPORT QGDictIterator // generic dictionary iterator
168 {
169 friend class QGDict;
170 public:
171  QGDictIterator( const QGDict & );
172  QGDictIterator( const QGDictIterator & );
174  ~QGDictIterator();
175 
176  QCollection::Item toFirst();
177 
178  QCollection::Item get() const;
179  QString getKeyString() const;
180  const char *getKeyAscii() const;
181  intptr_t getKeyInt() const;
182  void *getKeyPtr() const;
183 
184  QCollection::Item operator()();
185  QCollection::Item operator++();
187 
188 protected:
190 
191 private:
194 };
195 
197 {
198  return curNode ? curNode->getData() : 0;
199 }
200 
202 {
203  return curNode ? ((QStringBucket*)curNode)->getKey() : QString::null;
204 }
205 
206 inline const char *QGDictIterator::getKeyAscii() const
207 {
208  return curNode ? ((QAsciiBucket*)curNode)->getKey() : 0;
209 }
210 
211 inline intptr_t QGDictIterator::getKeyInt() const
212 {
213  return curNode ? ((QIntBucket*)curNode)->getKey() : 0;
214 }
215 
216 inline void *QGDictIterator::getKeyPtr() const
217 {
218  return curNode ? ((QPtrBucket*)curNode)->getKey() : 0;
219 }
220 
221 
222 #endif // QGDICT_H
uint count() const
Definition: qgdict.h:107
QBaseBucket * next
Definition: qgdict.h:60
DoubleProduct & operator+=(DoubleProduct &left, DoubleProduct const &right)
Definition: ToyProducts.h:103
QAsciiBucket(const char *k, QCollection::Item d, QBaseBucket *n)
Definition: qgdict.h:76
QBaseBucket ** vec
Definition: qgdict.h:149
QString key
Definition: qgdict.h:70
void statistics()
Definition: doxygen.cpp:257
QCollection::Item get() const
Definition: qgdict.h:196
size_t write(int, const char *, size_t)
Writes count bytes from buf to the filedescriptor fd.
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QCollection::Item getData()
Definition: qgdict.h:53
const QString & getKey() const
Definition: qgdict.h:68
QBaseBucket * curNode
Definition: qgdict.h:192
uint vlen
Definition: qgdict.h:150
init
Definition: train.py:42
void resize(Vector< T > &vec1, Index n1, const V &val)
QCollection::Item setData(QCollection::Item d)
Definition: qgdict.h:54
void * getKeyPtr() const
Definition: qgdict.h:216
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
intptr_t key
Definition: qgdict.h:90
QGDict & operator=(const QGDict &)
Definition: qgdict.cpp:309
void * key
Definition: qgdict.h:100
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
const char * getKey() const
Definition: qgdict.h:78
QPtrBucket(void *k, QCollection::Item d, QBaseBucket *n)
Definition: qgdict.h:96
const char * getKeyAscii() const
Definition: qgdict.h:206
friend class QGDictIterator
Definition: qgdict.h:163
The QCollection class is the base class of all Qt collections.
Definition: qcollection.h:51
QBaseBucket(QCollection::Item d, QBaseBucket *n)
Definition: qgdict.h:58
const char * key
Definition: qgdict.h:80
uint curIndex
Definition: qgdict.h:193
An internal class for implementing QDictIterator and QIntDictIterator.
Definition: qgdict.h:167
QGDict * dict
Definition: qgdict.h:189
The QGDict class is an internal class for implementing QDict template classes.
Definition: qgdict.h:104
void * getKey() const
Definition: qgdict.h:98
intptr_t getKeyInt() const
Definition: qgdict.h:211
KeyType
Definition: qgdict.h:119
QStringBucket(const QString &k, QCollection::Item d, QBaseBucket *n)
Definition: qgdict.h:66
QGDItList * iterators
Definition: qgdict.h:155
void setNext(QBaseBucket *n)
Definition: qgdict.h:56
uint size() const
Definition: qgdict.h:108
int read(int, char *, size_t)
Read bytes from a file descriptor.
vector< vector< double > > clear
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:47
static const Null null
Definition: qstring.h:376
QCollection::Item data
Definition: qgdict.h:59
const char * cs
intptr_t getKey() const
Definition: qgdict.h:88
unsigned uint
Definition: qglobal.h:351
#define Q_EXPORT
Definition: qglobal.h:468
QString getKeyString() const
Definition: qgdict.h:201
QIntBucket(intptr_t k, QCollection::Item d, QBaseBucket *n)
Definition: qgdict.h:86
void * Item
Definition: qcollection.h:60