00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef skSHASHTBL_H
00022 #define skSHASHTBL_H
00023
00024
00025 #include "skGeneral.h"
00026 #include "skString.h"
00027 #include "skAlist.h"
00028
00032 class CLASSEXPORT skSHashEntry
00033 {
00034 public:
00038 skSHashEntry(const skString& k,void * v)
00039 : m_Key(k), m_Value(v) {
00040 }
00044 int operator==(const skSHashEntry& h) {
00045 return this==&h;
00046 }
00047 skString m_Key;
00048 void * m_Value;
00049 };
00050
00051 typedef skTAList<skSHashEntry> skSHashEntryList;
00052 typedef skTAListIterator<skSHashEntry> skSHashEntryListIterator;
00053
00059 class CLASSEXPORT skSHashTable
00060 #ifdef __SYMBIAN32__
00061 : public CBase
00062 #endif
00063 {
00064 public:
00068 IMPORT_C void clear();
00072 IMPORT_C void clearAndDestroyValues();
00076 IMPORT_C void clearAndDestroy();
00080 inline USize entries() const;
00084 virtual ~skSHashTable();
00088 IMPORT_C void del(const skString& key);
00092 IMPORT_C void remove(const skString& key);
00093 #ifdef __SYMBIAN32__
00094
00099 inline operator TCleanupItem();
00104 inline static void Cleanup(TAny * s);
00105 #endif
00106 protected:
00110 skSHashTable(USize size);
00115 IMPORT_C void insertKeyAndValue(const skString& key, void * value);
00119 void * value(const skString& key) const;
00123 virtual void deleteValue(void * value)=0;
00124 private:
00128 skSHashTable();
00132 skSHashTable(const skSHashTable&);
00136 skSHashTable& operator=(const skSHashTable&);
00140 skSHashEntry * findEntry(const skString& key,USize & slot) const;
00144 skSHashEntry * findEntry(const skString& key) const;
00149 void createSlots();
00153 skSHashEntryList * m_Slots;
00157 USize m_Size;
00161 USize m_NumEntries;
00162 friend class skSHashTableIterator;
00163 };
00167 class CLASSEXPORT skSHashTableIterator
00168 #ifdef __SYMBIAN32__
00169 : public CBase
00170 #endif
00171 {
00172 public:
00176 virtual ~skSHashTableIterator();
00181 IMPORT_C int operator()();
00185 inline skString key() const;
00186 protected:
00190 skSHashTableIterator(const skSHashTable&);
00194 void * value() const;
00195 private:
00199 skSHashTableIterator& operator=(const skSHashTableIterator&);
00203 const skSHashTable& m_Table;
00207 USize m_Slot;
00211 void * m_Value;
00215 skString m_Key;
00219 skSHashEntryListIterator * m_ListIterator;
00220 };
00221 #define TTS_PREFIX template <class TValue>
00222
00223 const int DEFAULT_skSHashTable_SIZE=3;
00227 template <class TValue> class CLASSEXPORT skTSHashTable: public skSHashTable
00228 {
00229 public:
00233 skTSHashTable(USize size);
00237 skTSHashTable();
00241 ~skTSHashTable();
00246 void insertKeyAndValue(const skString& key, TValue * value);
00250 TValue * value(const skString& key);
00251
00252 protected:
00256 void deleteValue(void * value);
00257 };
00261 template <class TValue> class CLASSEXPORT skTSHashTableIterator: public skSHashTableIterator
00262 {
00263 public:
00267 skTSHashTableIterator(const skTSHashTable<TValue>&);
00271 TValue * value() const;
00272 };
00273
00274 #include "skSHashTable.inl"
00275
00276 #endif