Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

GHash.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // GHash.h
00004 //
00005 // Copyright 2001-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef GHASH_H
00010 #define GHASH_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #include "gtypes.h"
00019 
00020 class GString;
00021 struct GHashBucket;
00022 struct GHashIter;
00023 
00024 //------------------------------------------------------------------------
00025 
00026 class GHash {
00027 public:
00028 
00029   GHash(GBool deleteKeysA = gFalse);
00030   ~GHash();
00031   void add(GString *key, void *val);
00032   void add(GString *key, int val);
00033   void *lookup(GString *key);
00034   int lookupInt(GString *key);
00035   void *lookup(char *key);
00036   int lookupInt(char *key);
00037   void *remove(GString *key);
00038   int removeInt(GString *key);
00039   void *remove(char *key);
00040   int removeInt(char *key);
00041   int getLength() { return len; }
00042   void startIter(GHashIter **iter);
00043   GBool getNext(GHashIter **iter, GString **key, void **val);
00044   GBool getNext(GHashIter **iter, GString **key, int *val);
00045   void killIter(GHashIter **iter);
00046 
00047 private:
00048 
00049   void expand();
00050   GHashBucket *find(GString *key, int *h);
00051   GHashBucket *find(char *key, int *h);
00052   int hash(GString *key);
00053   int hash(char *key);
00054 
00055   GBool deleteKeys;             // set if key strings should be deleted
00056   int size;                     // number of buckets
00057   int len;                      // number of entries
00058   GHashBucket **tab;
00059 };
00060 
00061 #define deleteGHash(hash, T)                       \
00062   do {                                             \
00063     GHash *_hash = (hash);                         \
00064     {                                              \
00065       GHashIter *_iter;                            \
00066       GString *_key;                               \
00067       void *_p;                                    \
00068       _hash->startIter(&_iter);                    \
00069       while (_hash->getNext(&_iter, &_key, &_p)) { \
00070         delete (T*)_p;                             \
00071       }                                            \
00072       delete _hash;                                \
00073     }                                              \
00074   } while(0)
00075 
00076 #endif

Generated on Wed Nov 3 12:58:56 2004 for Lemur Toolkit by doxygen1.2.18