beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / goo / GooHash.h
blobeda19e314097e71de2d11994b635d9128558a6a6
1 //========================================================================
2 //
3 // GooHash.h
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2012 Albert Astals Cid <aacid@kde.org>
18 // To see a description of the changes please see the Changelog file that
19 // came with your tarball or type make ChangeLog if you are building from git
21 //========================================================================
23 #ifndef GHASH_H
24 #define GHASH_H
26 #ifdef USE_GCC_PRAGMAS
27 #pragma interface
28 #endif
30 #include "gtypes.h"
32 class GooString;
33 struct GooHashBucket;
34 struct GooHashIter;
36 //------------------------------------------------------------------------
38 class GooHash {
39 public:
41 GooHash(GBool deleteKeysA = gFalse);
42 ~GooHash();
43 void add(GooString *key, void *val);
44 void add(GooString *key, int val);
45 void replace(GooString *key, void *val);
46 void replace(GooString *key, int val);
47 void *lookup(GooString *key);
48 int lookupInt(GooString *key);
49 void *lookup(const char *key);
50 int lookupInt(const char *key);
51 void *remove(GooString *key);
52 int removeInt(GooString *key);
53 void *remove(const char *key);
54 int removeInt(const char *key);
55 int getLength() { return len; }
56 void startIter(GooHashIter **iter);
57 GBool getNext(GooHashIter **iter, GooString **key, void **val);
58 GBool getNext(GooHashIter **iter, GooString **key, int *val);
59 void killIter(GooHashIter **iter);
61 private:
62 GooHash(const GooHash &other);
63 GooHash& operator=(const GooHash &other);
65 void expand();
66 GooHashBucket *find(GooString *key, int *h);
67 GooHashBucket *find(const char *key, int *h);
68 int hash(GooString *key);
69 int hash(const char *key);
71 GBool deleteKeys; // set if key strings should be deleted
72 int size; // number of buckets
73 int len; // number of entries
74 GooHashBucket **tab;
77 #define deleteGooHash(hash, T) \
78 do { \
79 GooHash *_hash = (hash); \
80 { \
81 GooHashIter *_iter; \
82 GooString *_key; \
83 void *_p; \
84 _hash->startIter(&_iter); \
85 while (_hash->getNext(&_iter, &_key, &_p)) { \
86 delete (T*)_p; \
87 } \
88 delete _hash; \
89 } \
90 } while(0)
92 #endif