qdict.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
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 #define USE_ASCII_STRING
46 
47 #ifdef USE_ASCII_STRING
48 
49 #define QAsciiDict QDict
50 #define QAsciiDictIterator QDictIterator
51 #include "qasciidict.h"
52 
53 #else
54 
55 template<class type> class Q_EXPORT QDict : private QGDict
56 {
57 public:
58  QDict(int size=17, bool caseSensitive=TRUE)
59  : QGDict(size,StringKey,caseSensitive,FALSE) {}
60  QDict( const QDict<type> &d ) : QGDict(d) {}
61  ~QDict() { clear(); }
62  QDict<type> &operator=(const QDict<type> &d)
63  { return (QDict<type>&)QGDict::operator=(d); }
64 
65  // capacity
66  uint count() const { return QGDict::count(); }
67  uint size() const { return QGDict::size(); }
68  bool isEmpty() const { return QGDict::count() == 0; }
69 
70  // modifiers
71  void insert( const QString &k, const type *d )
72  { QGDict::look_string(k,(Item)d,1); }
73  void replace( const QString &k, const type *d )
74  { QGDict::look_string(k,(Item)d,2); }
75  bool remove( const QString &k ) { return QGDict::remove_string(k); }
76  type *take( const QString &k ) { return (type *)QGDict::take_string(k); }
77  void clear() { QGDict::clear(); }
78  void resize( uint n ) { QGDict::resize(n); }
79 
80  // search
81  type *find( const QString &k ) const
82  { return (type *)((QGDict*)this)->QGDict::look_string(k,0,0); }
83  type *operator[]( const QString &k ) const
84  { return (type *)((QGDict*)this)->QGDict::look_string(k,0,0); }
85 
86  // operations
87  void statistics() const { QGDict::statistics(); }
88 private:
89  void deleteItem( Item d );
90 
91  // new to be reimplemented methods
92  virtual int compareValues(const type *t1,const type *t2) const
93  { return const_cast<QDict<type>*>(this)->QGDict::compareItems((QCollection::Item)t1,(QCollection::Item)t2); }
94 
95  // reimplemented methods
96  virtual int compareItems(QCollection::Item i1,QCollection::Item i2)
97  { return compareValues((const type*)i1,(const type*)i2); }
98 };
99 
100 #if defined(Q_DELETING_VOID_UNDEFINED)
101 template<> inline void QDict<void>::deleteItem( Item )
102 {
103 }
104 #endif
105 
106 template<class type> inline void QDict<type>::deleteItem( QCollection::Item d )
107 {
108  if ( del_item ) delete (type *)d;
109 }
110 
111 
112 template<class type> class Q_EXPORT QDictIterator : public QGDictIterator
113 {
114 public:
115  QDictIterator(const QDict<type> &d) :QGDictIterator((QGDict &)d) {}
116  ~QDictIterator() {}
117  uint count() const { return dict->count(); }
118  bool isEmpty() const { return dict->count() == 0; }
119  type *toFirst() { return (type *)QGDictIterator::toFirst(); }
120  operator type *() const { return (type *)QGDictIterator::get(); }
121  type *current() const { return (type *)QGDictIterator::get(); }
122  QString currentKey() const{ return QGDictIterator::getKeyString(); }
123  type *operator()() { return (type *)QGDictIterator::operator()(); }
124  type *operator++() { return (type *)QGDictIterator::operator++(); }
125  type *operator+=(uint j) { return (type *)QGDictIterator::operator+=(j);}
126 };
127 
128 #endif // USE_ASCII_STRING
129 
130 #endif // QDICT_H
uint count() const
Definition: qgdict.h:107
void statistics() const
Definition: qgdict.cpp:930
void resize(uint)
Definition: qgdict.cpp:527
QCollection::Item operator+=(uint)
Definition: qgdict.cpp:1239
const bool FALSE
Definition: qglobal.h:370
QCollection::Item get() const
Definition: qgdict.h:196
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QCollection::Item operator()()
Definition: qgdict.cpp:1188
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
QGDict & operator=(const QGDict &)
Definition: qgdict.cpp:309
bool remove_string(const QString &key, QCollection::Item item=0)
Definition: qgdict.cpp:732
std::void_t< T > n
void clear()
Definition: qgdict.cpp:857
static Entry * current
QGDictIterator(const QGDict &)
Definition: qgdict.cpp:1101
An internal class for implementing QDictIterator and QIntDictIterator.
Definition: qgdict.h:167
QCollection::Item take_string(const QString &key)
Definition: qgdict.cpp:788
QCollection::Item operator++()
Definition: qgdict.cpp:1208
QCollection::Item toFirst()
Definition: qgdict.cpp:1161
The QGDict class is an internal class for implementing QDict template classes.
Definition: qgdict.h:104
QGDict(uint len, KeyType kt, bool cs, bool ck)
Definition: qgdict.cpp:222
uint size() const
Definition: qgdict.h:108
virtual void deleteItem(Item)
unsigned uint
Definition: qglobal.h:351
#define Q_EXPORT
Definition: qglobal.h:468
const bool TRUE
Definition: qglobal.h:371
QString getKeyString() const
Definition: qgdict.h:201
QCollection::Item look_string(const QString &key, QCollection::Item, int)
Definition: qgdict.cpp:382
void * Item
Definition: qcollection.h:60