author | sandman <sandman> | 2002-04-13 00:47:20 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-04-13 00:47:20 (UTC) |
commit | 98a1e3f36567639344f12932b629e526a8783aa8 (patch) (unidiff) | |
tree | 0433d296857faceeafc54f7deabddb621f45a933 /noncore/unsupported/qpdf/xpdf/Dict.cc | |
parent | 7e31b1fba119f69929d6744d7295555ff1727f4f (diff) | |
download | opie-98a1e3f36567639344f12932b629e526a8783aa8.zip opie-98a1e3f36567639344f12932b629e526a8783aa8.tar.gz opie-98a1e3f36567639344f12932b629e526a8783aa8.tar.bz2 |
CVS import of QPdf
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/Dict.cc') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/Dict.cc | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/Dict.cc b/noncore/unsupported/qpdf/xpdf/Dict.cc new file mode 100644 index 0000000..1a49ca5 --- a/dev/null +++ b/noncore/unsupported/qpdf/xpdf/Dict.cc | |||
@@ -0,0 +1,90 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // Dict.cc | ||
4 | // | ||
5 | // Copyright 1996 Derek B. Noonburg | ||
6 | // | ||
7 | //======================================================================== | ||
8 | |||
9 | #ifdef __GNUC__ | ||
10 | #pragma implementation | ||
11 | #endif | ||
12 | |||
13 | #include <aconf.h> | ||
14 | #include <stddef.h> | ||
15 | #include <string.h> | ||
16 | #include "gmem.h" | ||
17 | #include "Object.h" | ||
18 | #include "XRef.h" | ||
19 | #include "Dict.h" | ||
20 | |||
21 | //------------------------------------------------------------------------ | ||
22 | // Dict | ||
23 | //------------------------------------------------------------------------ | ||
24 | |||
25 | Dict::Dict(XRef *xrefA) { | ||
26 | xref = xrefA; | ||
27 | entries = NULL; | ||
28 | size = length = 0; | ||
29 | ref = 1; | ||
30 | } | ||
31 | |||
32 | Dict::~Dict() { | ||
33 | int i; | ||
34 | |||
35 | for (i = 0; i < length; ++i) { | ||
36 | gfree(entries[i].key); | ||
37 | entries[i].val.free(); | ||
38 | } | ||
39 | gfree(entries); | ||
40 | } | ||
41 | |||
42 | void Dict::add(char *key, Object *val) { | ||
43 | if (length + 1 > size) { | ||
44 | size += 8; | ||
45 | entries = (DictEntry *)grealloc(entries, size * sizeof(DictEntry)); | ||
46 | } | ||
47 | entries[length].key = key; | ||
48 | entries[length].val = *val; | ||
49 | ++length; | ||
50 | } | ||
51 | |||
52 | inline DictEntry *Dict::find(char *key) { | ||
53 | int i; | ||
54 | |||
55 | for (i = 0; i < length; ++i) { | ||
56 | if (!strcmp(key, entries[i].key)) | ||
57 | return &entries[i]; | ||
58 | } | ||
59 | return NULL; | ||
60 | } | ||
61 | |||
62 | GBool Dict::is(char *type) { | ||
63 | DictEntry *e; | ||
64 | |||
65 | return (e = find("Type")) && e->val.isName(type); | ||
66 | } | ||
67 | |||
68 | Object *Dict::lookup(char *key, Object *obj) { | ||
69 | DictEntry *e; | ||
70 | |||
71 | return (e = find(key)) ? e->val.fetch(xref, obj) : obj->initNull(); | ||
72 | } | ||
73 | |||
74 | Object *Dict::lookupNF(char *key, Object *obj) { | ||
75 | DictEntry *e; | ||
76 | |||
77 | return (e = find(key)) ? e->val.copy(obj) : obj->initNull(); | ||
78 | } | ||
79 | |||
80 | char *Dict::getKey(int i) { | ||
81 | return entries[i].key; | ||
82 | } | ||
83 | |||
84 | Object *Dict::getVal(int i, Object *obj) { | ||
85 | return entries[i].val.fetch(xref, obj); | ||
86 | } | ||
87 | |||
88 | Object *Dict::getValNF(int i, Object *obj) { | ||
89 | return entries[i].val.copy(obj); | ||
90 | } | ||