Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qgdict.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of QGDict and QGDictIterator classes 00005 ** 00006 ** Created : 920529 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file is part of the tools module of the Qt GUI Toolkit. 00011 ** 00012 ** This file may be distributed under the terms of the Q Public License 00013 ** as defined by Trolltech ASA of Norway and appearing in the file 00014 ** LICENSE.QPL included in the packaging of this file. 00015 ** 00016 ** This file may be distributed and/or modified under the terms of the 00017 ** GNU General Public License version 2 as published by the Free Software 00018 ** Foundation and appearing in the file LICENSE.GPL included in the 00019 ** packaging of this file. 00020 ** 00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00022 ** licenses may use this file in accordance with the Qt Commercial License 00023 ** Agreement provided with the Software. 00024 ** 00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00027 ** 00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00029 ** information about Qt Commercial License Agreements. 00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00032 ** 00033 ** Contact info@trolltech.com if any conditions of this licensing are 00034 ** not clear to you. 00035 ** 00036 **********************************************************************/ 00037 00038 #ifndef QGDICT_H 00039 #define QGDICT_H 00040 00041 #ifndef QT_H 00042 #include "qptrcollection.h" 00043 #include "qstring.h" 00044 #endif // QT_H 00045 00046 class QGDictIterator; 00047 class QGDItList; 00048 00049 00050 class QBaseBucket // internal dict node 00051 { 00052 public: 00053 QPtrCollection::Item getData() { return data; } 00054 QPtrCollection::Item setData( QPtrCollection::Item d ) { return data = d; } 00055 QBaseBucket *getNext() { return next; } 00056 void setNext( QBaseBucket *n) { next = n; } 00057 protected: 00058 QBaseBucket( QPtrCollection::Item d, QBaseBucket *n ) : data(d), next(n) {} 00059 QPtrCollection::Item data; 00060 QBaseBucket *next; 00061 }; 00062 00063 class QStringBucket : public QBaseBucket 00064 { 00065 public: 00066 QStringBucket( const QString &k, QPtrCollection::Item d, QBaseBucket *n ) 00067 : QBaseBucket(d,n), key(k) {} 00068 const QString &getKey() const { return key; } 00069 private: 00070 QString key; 00071 }; 00072 00073 class QAsciiBucket : public QBaseBucket 00074 { 00075 public: 00076 QAsciiBucket( const char *k, QPtrCollection::Item d, QBaseBucket *n ) 00077 : QBaseBucket(d,n), key(k) {} 00078 const char *getKey() const { return key; } 00079 private: 00080 const char *key; 00081 }; 00082 00083 class QIntBucket : public QBaseBucket 00084 { 00085 public: 00086 QIntBucket( long k, QPtrCollection::Item d, QBaseBucket *n ) 00087 : QBaseBucket(d,n), key(k) {} 00088 long getKey() const { return key; } 00089 private: 00090 long key; 00091 }; 00092 00093 class QPtrBucket : public QBaseBucket 00094 { 00095 public: 00096 QPtrBucket( void *k, QPtrCollection::Item d, QBaseBucket *n ) 00097 : QBaseBucket(d,n), key(k) {} 00098 void *getKey() const { return key; } 00099 private: 00100 void *key; 00101 }; 00102 00103 00104 class Q_EXPORT QGDict : public QPtrCollection // generic dictionary class 00105 { 00106 public: 00107 uint count() const { return numItems; } 00108 uint size() const { return vlen; } 00109 QPtrCollection::Item look_string( const QString& key, QPtrCollection::Item, 00110 int ); 00111 QPtrCollection::Item look_ascii( const char *key, QPtrCollection::Item, int ); 00112 QPtrCollection::Item look_int( long key, QPtrCollection::Item, int ); 00113 QPtrCollection::Item look_ptr( void *key, QPtrCollection::Item, int ); 00114 #ifndef QT_NO_DATASTREAM 00115 QDataStream &read( QDataStream & ); 00116 QDataStream &write( QDataStream & ) const; 00117 #endif 00118 protected: 00119 enum KeyType { StringKey, AsciiKey, IntKey, PtrKey }; 00120 00121 QGDict( uint len, KeyType kt, bool cs, bool ck ); 00122 QGDict( const QGDict & ); 00123 ~QGDict(); 00124 00125 QGDict &operator=( const QGDict & ); 00126 00127 bool remove_string( const QString &key, QPtrCollection::Item item=0 ); 00128 bool remove_ascii( const char *key, QPtrCollection::Item item=0 ); 00129 bool remove_int( long key, QPtrCollection::Item item=0 ); 00130 bool remove_ptr( void *key, QPtrCollection::Item item=0 ); 00131 QPtrCollection::Item take_string( const QString &key ); 00132 QPtrCollection::Item take_ascii( const char *key ); 00133 QPtrCollection::Item take_int( long key ); 00134 QPtrCollection::Item take_ptr( void *key ); 00135 00136 void clear(); 00137 void resize( uint ); 00138 00139 int hashKeyString( const QString & ); 00140 int hashKeyAscii( const char * ); 00141 00142 void statistics() const; 00143 00144 #ifndef QT_NO_DATASTREAM 00145 virtual QDataStream &read( QDataStream &, QPtrCollection::Item & ); 00146 virtual QDataStream &write( QDataStream &, QPtrCollection::Item ) const; 00147 #endif 00148 private: 00149 QBaseBucket **vec; 00150 uint vlen; 00151 uint numItems; 00152 uint keytype : 2; 00153 uint cases : 1; 00154 uint copyk : 1; 00155 QGDItList *iterators; 00156 void unlink_common( int, QBaseBucket *, QBaseBucket * ); 00157 QStringBucket *unlink_string( const QString &, 00158 QPtrCollection::Item item = 0 ); 00159 QAsciiBucket *unlink_ascii( const char *, QPtrCollection::Item item = 0 ); 00160 QIntBucket *unlink_int( long, QPtrCollection::Item item = 0 ); 00161 QPtrBucket *unlink_ptr( void *, QPtrCollection::Item item = 0 ); 00162 void init( uint, KeyType, bool, bool ); 00163 friend class QGDictIterator; 00164 }; 00165 00166 00167 class Q_EXPORT QGDictIterator // generic dictionary iterator 00168 { 00169 friend class QGDict; 00170 public: 00171 QGDictIterator( const QGDict & ); 00172 QGDictIterator( const QGDictIterator & ); 00173 QGDictIterator &operator=( const QGDictIterator & ); 00174 ~QGDictIterator(); 00175 00176 QPtrCollection::Item toFirst(); 00177 00178 QPtrCollection::Item get() const; 00179 QString getKeyString() const; 00180 const char *getKeyAscii() const; 00181 long getKeyInt() const; 00182 void *getKeyPtr() const; 00183 00184 QPtrCollection::Item operator()(); 00185 QPtrCollection::Item operator++(); 00186 QPtrCollection::Item operator+=(uint); 00187 00188 protected: 00189 QGDict *dict; 00190 00191 private: 00192 QBaseBucket *curNode; 00193 uint curIndex; 00194 }; 00195 00196 inline QPtrCollection::Item QGDictIterator::get() const 00197 { 00198 return curNode ? curNode->getData() : 0; 00199 } 00200 00201 inline QString QGDictIterator::getKeyString() const 00202 { 00203 return curNode ? ((QStringBucket*)curNode)->getKey() : QString::null; 00204 } 00205 00206 inline const char *QGDictIterator::getKeyAscii() const 00207 { 00208 return curNode ? ((QAsciiBucket*)curNode)->getKey() : 0; 00209 } 00210 00211 inline long QGDictIterator::getKeyInt() const 00212 { 00213 return curNode ? ((QIntBucket*)curNode)->getKey() : 0; 00214 } 00215 00216 inline void *QGDictIterator::getKeyPtr() const 00217 { 00218 return curNode ? ((QPtrBucket*)curNode)->getKey() : 0; 00219 } 00220 00221 00222 #endif // QGDICT_H