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