filters
GHash.h00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef GHASH_H
00010 #define GHASH_H
00011
00012 #include <aconf.h>
00013
00014
00015 #include "gtypes.h"
00016
00017 class GString;
00018 struct GHashBucket;
00019 struct GHashIter;
00020
00021
00022
00023 class GHash {
00024 public:
00025
00026 GHash(GBool deleteKeysA = gFalse);
00027 ~GHash();
00028 void add(GString *key, void *val);
00029 void *lookup(const GString *key);
00030 void *lookup(const char *key);
00031 void *remove(const GString *key);
00032 void *remove(const char *key);
00033 int getLength() { return len; }
00034 void startIter(GHashIter **iter);
00035 GBool getNext(GHashIter **iter, GString **key, void **val);
00036 void killIter(GHashIter **iter);
00037
00038 private:
00039
00040 GHashBucket *find(const GString *key, int *h);
00041 GHashBucket *find(const char *key, int *h);
00042 int hash(const GString *key);
00043 int hash(const char *key);
00044
00045 GBool deleteKeys;
00046 int size;
00047 int len;
00048 GHashBucket **tab;
00049 };
00050
00051 #define deleteGHash(hash, T) \
00052 do { \
00053 GHash *_hash = (hash); \
00054 { \
00055 GHashIter *_iter; \
00056 GString *_key; \
00057 void *_p; \
00058 _hash->startIter(&_iter); \
00059 while (_hash->getNext(&_iter, &_key, &_p)) { \
00060 delete (T*)_p; \
00061 } \
00062 delete _hash; \
00063 } \
00064 } while(0)
00065
00066 #endif
|