/src/xpdf-4.05/xpdf/Dict.h
Line | Count | Source |
1 | | //======================================================================== |
2 | | // |
3 | | // Dict.h |
4 | | // |
5 | | // Copyright 1996-2003 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #ifndef DICT_H |
10 | | #define DICT_H |
11 | | |
12 | | #include <aconf.h> |
13 | | |
14 | | #if MULTITHREADED |
15 | | #include "GMutex.h" |
16 | | #endif |
17 | | #include "Object.h" |
18 | | |
19 | | struct DictEntry; |
20 | | |
21 | | //------------------------------------------------------------------------ |
22 | | // Dict |
23 | | //------------------------------------------------------------------------ |
24 | | |
25 | | class Dict { |
26 | | public: |
27 | | |
28 | | // Constructor. |
29 | | Dict(XRef *xrefA); |
30 | | |
31 | | // Destructor. |
32 | | ~Dict(); |
33 | | |
34 | | // Reference counting. |
35 | | #if MULTITHREADED |
36 | 979k | long incRef() { return gAtomicIncrement(&ref); } |
37 | 1.63M | long decRef() { return gAtomicDecrement(&ref); } |
38 | | #else |
39 | | long incRef() { return ++ref; } |
40 | | long decRef() { return --ref; } |
41 | | #endif |
42 | | |
43 | | // Get number of entries. |
44 | 10.8k | int getLength() { return length; } |
45 | | |
46 | | // Add an entry. NB: does not copy key. |
47 | | void add(char *key, Object *val); |
48 | | |
49 | | // Check if dictionary is of specified type. |
50 | | GBool is(const char *type); |
51 | | |
52 | | // Look up an entry and return the value. Returns a null object |
53 | | // if <key> is not in the dictionary. |
54 | | Object *lookup(const char *key, Object *obj, int recursion = 0); |
55 | | Object *lookupNF(const char *key, Object *obj); |
56 | | |
57 | | // Iterative accessors. |
58 | | char *getKey(int i); |
59 | | Object *getVal(int i, Object *obj); |
60 | | Object *getValNF(int i, Object *obj); |
61 | | |
62 | | // Set the xref pointer. This is only used in one special case: the |
63 | | // trailer dictionary, which is read before the xref table is |
64 | | // parsed. |
65 | 1.45k | void setXRef(XRef *xrefA) { xref = xrefA; } |
66 | | |
67 | | private: |
68 | | |
69 | | XRef *xref; // the xref table for this PDF file |
70 | | DictEntry *entries; // array of entries |
71 | | DictEntry **hashTab; // hash table pointers |
72 | | int size; // size of <entries> array |
73 | | int length; // number of entries in dictionary |
74 | | #if MULTITHREADED |
75 | | GAtomicCounter ref; // reference count |
76 | | #else |
77 | | long ref; // reference count |
78 | | #endif |
79 | | |
80 | | DictEntry *find(const char *key); |
81 | | void expand(); |
82 | | int hash(const char *key); |
83 | | }; |
84 | | |
85 | | #endif |