fixed dates
[swftools.git] / pdf2swf / xpdf / GHash.h
1 //========================================================================
2 //
3 // GHash.h
4 //
5 // Copyright 2001-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef GHASH_H
10 #define GHASH_H
11
12 #ifdef __GNUC__
13 #pragma interface
14 #endif
15
16 #include "gtypes.h"
17
18 class GString;
19 struct GHashBucket;
20 struct GHashIter;
21
22 //------------------------------------------------------------------------
23
24 class GHash {
25 public:
26
27   GHash(GBool deleteKeysA = gFalse);
28   ~GHash();
29   void add(GString *key, void *val);
30   void *lookup(GString *key);
31   void *lookup(char *key);
32   void *remove(GString *key);
33   void *remove(char *key);
34   int getLength() { return len; }
35   void startIter(GHashIter **iter);
36   GBool getNext(GHashIter **iter, GString **key, void **val);
37   void killIter(GHashIter **iter);
38
39 private:
40
41   GHashBucket *find(GString *key, int *h);
42   GHashBucket *find(char *key, int *h);
43   int hash(GString *key);
44   int hash(char *key);
45
46   GBool deleteKeys;             // set if key strings should be deleted
47   int size;                     // number of buckets
48   int len;                      // number of entries
49   GHashBucket **tab;
50 };
51
52 #define deleteGHash(hash, T)                       \
53   do {                                             \
54     GHash *_hash = (hash);                         \
55     {                                              \
56       GHashIter *_iter;                            \
57       GString *_key;                               \
58       void *_p;                                    \
59       _hash->startIter(&_iter);                    \
60       while (_hash->getNext(&_iter, &_key, &_p)) { \
61         delete (T*)_p;                             \
62       }                                            \
63       delete _hash;                                \
64     }                                              \
65   } while(0)
66
67 #endif