source: trunk/src/qt3support/tools/q3gdict.h@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 7.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt3Support module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef Q3GDICT_H
43#define Q3GDICT_H
44
45#include <Qt3Support/q3ptrcollection.h>
46#include <QtCore/qstring.h>
47
48QT_BEGIN_HEADER
49
50QT_BEGIN_NAMESPACE
51
52QT_MODULE(Qt3SupportLight)
53
54class Q3GDictIterator;
55class Q3GDItList;
56
57
58class Q3BaseBucket // internal dict node
59{
60public:
61 Q3PtrCollection::Item getData() { return data; }
62 Q3PtrCollection::Item setData( Q3PtrCollection::Item d ) { return data = d; }
63 Q3BaseBucket *getNext() { return next; }
64 void setNext( Q3BaseBucket *n) { next = n; }
65protected:
66 Q3BaseBucket( Q3PtrCollection::Item d, Q3BaseBucket *n ) : data(d), next(n) {}
67 Q3PtrCollection::Item data;
68 Q3BaseBucket *next;
69};
70
71class Q3StringBucket : public Q3BaseBucket
72{
73public:
74 Q3StringBucket( const QString &k, Q3PtrCollection::Item d, Q3BaseBucket *n )
75 : Q3BaseBucket(d,n), key(k) {}
76 const QString &getKey() const { return key; }
77private:
78 QString key;
79};
80
81class Q3AsciiBucket : public Q3BaseBucket
82{
83public:
84 Q3AsciiBucket( const char *k, Q3PtrCollection::Item d, Q3BaseBucket *n )
85 : Q3BaseBucket(d,n), key(k) {}
86 const char *getKey() const { return key; }
87private:
88 const char *key;
89};
90
91class Q3IntBucket : public Q3BaseBucket
92{
93public:
94 Q3IntBucket( long k, Q3PtrCollection::Item d, Q3BaseBucket *n )
95 : Q3BaseBucket(d,n), key(k) {}
96 long getKey() const { return key; }
97private:
98 long key;
99};
100
101class Q3PtrBucket : public Q3BaseBucket
102{
103public:
104 Q3PtrBucket( void *k, Q3PtrCollection::Item d, Q3BaseBucket *n )
105 : Q3BaseBucket(d,n), key(k) {}
106 void *getKey() const { return key; }
107private:
108 void *key;
109};
110
111
112class Q_COMPAT_EXPORT Q3GDict : public Q3PtrCollection // generic dictionary class
113{
114public:
115 uint count() const { return numItems; }
116 uint size() const { return vlen; }
117 Q3PtrCollection::Item look_string( const QString& key, Q3PtrCollection::Item,
118 int );
119 Q3PtrCollection::Item look_ascii( const char *key, Q3PtrCollection::Item, int );
120 Q3PtrCollection::Item look_int( long key, Q3PtrCollection::Item, int );
121 Q3PtrCollection::Item look_ptr( void *key, Q3PtrCollection::Item, int );
122#ifndef QT_NO_DATASTREAM
123 QDataStream &read( QDataStream & );
124 QDataStream &write( QDataStream & ) const;
125#endif
126protected:
127 enum KeyType { StringKey, AsciiKey, IntKey, PtrKey };
128
129 Q3GDict( uint len, KeyType kt, bool cs, bool ck );
130 Q3GDict( const Q3GDict & );
131 ~Q3GDict();
132
133 Q3GDict &operator=( const Q3GDict & );
134
135 bool remove_string( const QString &key, Q3PtrCollection::Item item=0 );
136 bool remove_ascii( const char *key, Q3PtrCollection::Item item=0 );
137 bool remove_int( long key, Q3PtrCollection::Item item=0 );
138 bool remove_ptr( void *key, Q3PtrCollection::Item item=0 );
139 Q3PtrCollection::Item take_string( const QString &key );
140 Q3PtrCollection::Item take_ascii( const char *key );
141 Q3PtrCollection::Item take_int( long key );
142 Q3PtrCollection::Item take_ptr( void *key );
143
144 void clear();
145 void resize( uint );
146
147 int hashKeyString( const QString & );
148 int hashKeyAscii( const char * );
149
150 void statistics() const;
151
152#ifndef QT_NO_DATASTREAM
153 virtual QDataStream &read( QDataStream &, Q3PtrCollection::Item & );
154 virtual QDataStream &write( QDataStream &, Q3PtrCollection::Item ) const;
155#endif
156private:
157 Q3BaseBucket **vec;
158 uint vlen;
159 uint numItems;
160 uint keytype : 2;
161 uint cases : 1;
162 uint copyk : 1;
163 Q3GDItList *iterators;
164 void unlink_common( int, Q3BaseBucket *, Q3BaseBucket * );
165 Q3StringBucket *unlink_string( const QString &,
166 Q3PtrCollection::Item item = 0 );
167 Q3AsciiBucket *unlink_ascii( const char *, Q3PtrCollection::Item item = 0 );
168 Q3IntBucket *unlink_int( long, Q3PtrCollection::Item item = 0 );
169 Q3PtrBucket *unlink_ptr( void *, Q3PtrCollection::Item item = 0 );
170 void init( uint, KeyType, bool, bool );
171 friend class Q3GDictIterator;
172};
173
174
175class Q_COMPAT_EXPORT Q3GDictIterator // generic dictionary iterator
176{
177friend class Q3GDict;
178public:
179 Q3GDictIterator( const Q3GDict & );
180 Q3GDictIterator( const Q3GDictIterator & );
181 Q3GDictIterator &operator=( const Q3GDictIterator & );
182 ~Q3GDictIterator();
183
184 Q3PtrCollection::Item toFirst();
185
186 Q3PtrCollection::Item get() const;
187 QString getKeyString() const;
188 const char *getKeyAscii() const;
189 long getKeyInt() const;
190 void *getKeyPtr() const;
191
192 Q3PtrCollection::Item operator()();
193 Q3PtrCollection::Item operator++();
194 Q3PtrCollection::Item operator+=(uint);
195
196protected:
197 Q3GDict *dict;
198
199private:
200 Q3BaseBucket *curNode;
201 uint curIndex;
202};
203
204inline Q3PtrCollection::Item Q3GDictIterator::get() const
205{
206 return curNode ? curNode->getData() : 0;
207}
208
209inline QString Q3GDictIterator::getKeyString() const
210{
211 return curNode ? ((Q3StringBucket*)curNode)->getKey() : QString();
212}
213
214inline const char *Q3GDictIterator::getKeyAscii() const
215{
216 return curNode ? ((Q3AsciiBucket*)curNode)->getKey() : 0;
217}
218
219inline long Q3GDictIterator::getKeyInt() const
220{
221 return curNode ? ((Q3IntBucket*)curNode)->getKey() : 0;
222}
223
224inline void *Q3GDictIterator::getKeyPtr() const
225{
226 return curNode ? ((Q3PtrBucket*)curNode)->getKey() : 0;
227}
228
229QT_END_NAMESPACE
230
231QT_END_HEADER
232
233#endif // Q3GDICT_H
Note: See TracBrowser for help on using the repository browser.