1 | /****************************************************************************
|
---|
2 | ** $Id: qdict.h 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Definition of QDict template class
|
---|
5 | **
|
---|
6 | ** Created : 920821
|
---|
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 QDICT_H
|
---|
39 | #define QDICT_H
|
---|
40 |
|
---|
41 | #ifndef QT_H
|
---|
42 | #include "qgdict.h"
|
---|
43 | #endif // QT_H
|
---|
44 |
|
---|
45 | template<class type>
|
---|
46 | class QDict
|
---|
47 | #ifdef Q_QDOC
|
---|
48 | : public QPtrCollection
|
---|
49 | #else
|
---|
50 | : public QGDict
|
---|
51 | #endif
|
---|
52 | {
|
---|
53 | public:
|
---|
54 | QDict( int size = 17, bool caseSensitive = TRUE )
|
---|
55 | : QGDict( size, StringKey, caseSensitive, FALSE ) { }
|
---|
56 | QDict( const QDict<type> &d ) : QGDict( d ) { }
|
---|
57 | ~QDict() { clear(); }
|
---|
58 | QDict<type> &operator=(const QDict<type> &d)
|
---|
59 | { return (QDict<type>&)QGDict::operator=(d); }
|
---|
60 | uint count() const { return QGDict::count(); }
|
---|
61 | uint size() const { return QGDict::size(); }
|
---|
62 | bool isEmpty() const { return QGDict::count() == 0; }
|
---|
63 |
|
---|
64 | void insert( const QString &k, const type *d )
|
---|
65 | { QGDict::look_string(k,(Item)d,1); }
|
---|
66 | void replace( const QString &k, const type *d )
|
---|
67 | { QGDict::look_string(k,(Item)d,2); }
|
---|
68 | bool remove( const QString &k ) { return QGDict::remove_string(k); }
|
---|
69 | type *take( const QString &k ) { return (type *)QGDict::take_string(k); }
|
---|
70 | type *find( const QString &k ) const
|
---|
71 | { return (type *)((QGDict*)this)->QGDict::look_string(k,0,0); }
|
---|
72 | type *operator[]( const QString &k ) const
|
---|
73 | { return (type *)((QGDict*)this)->QGDict::look_string(k,0,0); }
|
---|
74 |
|
---|
75 | void clear() { QGDict::clear(); }
|
---|
76 | void resize( uint n ) { QGDict::resize(n); }
|
---|
77 | void statistics() const { QGDict::statistics(); }
|
---|
78 |
|
---|
79 | #ifdef Q_QDOC
|
---|
80 | protected:
|
---|
81 | virtual QDataStream& read( QDataStream &, QPtrCollection::Item & );
|
---|
82 | virtual QDataStream& write( QDataStream &, QPtrCollection::Item ) const;
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | private:
|
---|
86 | void deleteItem( Item d );
|
---|
87 | };
|
---|
88 |
|
---|
89 | #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION)
|
---|
90 | template<> inline void QDict<void>::deleteItem( Item )
|
---|
91 | {
|
---|
92 | }
|
---|
93 | #endif
|
---|
94 |
|
---|
95 | template<class type> inline void QDict<type>::deleteItem( QPtrCollection::Item d )
|
---|
96 | {
|
---|
97 | if ( del_item ) delete (type *)d;
|
---|
98 | }
|
---|
99 |
|
---|
100 | template<class type>
|
---|
101 | class QDictIterator : public QGDictIterator
|
---|
102 | {
|
---|
103 | public:
|
---|
104 | QDictIterator(const QDict<type> &d) : QGDictIterator((QGDict &)d) { }
|
---|
105 | ~QDictIterator() {}
|
---|
106 | uint count() const { return dict->count(); }
|
---|
107 | bool isEmpty() const { return dict->count() == 0; }
|
---|
108 | type *toFirst() { return (type *)QGDictIterator::toFirst(); }
|
---|
109 | operator type *() const { return (type *)QGDictIterator::get(); }
|
---|
110 | type *operator*() { return (type *)QGDictIterator::get(); }
|
---|
111 | type *current() const { return (type *)QGDictIterator::get(); }
|
---|
112 | QString currentKey() const{ return QGDictIterator::getKeyString(); }
|
---|
113 | type *operator()() { return (type *)QGDictIterator::operator()(); }
|
---|
114 | type *operator++() { return (type *)QGDictIterator::operator++(); }
|
---|
115 | type *operator+=(uint j) { return (type *)QGDictIterator::operator+=(j); }
|
---|
116 | };
|
---|
117 |
|
---|
118 | #define Q_DEFINED_QDICT
|
---|
119 | #include "qwinexport.h"
|
---|
120 | #endif // QDICT_H
|
---|