Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

skSHashTable.h

00001 /*
00002   Copyright 1996-2003
00003   Simon Whiteside
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019   $Id: skSHashTable_8h-source.html,v 1.7 2004/12/17 21:31:15 sdw Exp $
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

Generated on Fri Dec 17 20:28:26 2004 for Simkin C++ for Symbian by doxygen1.3