summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf/xpdf/Dict.cc
Unidiff
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/Dict.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/xpdf/Dict.cc90
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
25Dict::Dict(XRef *xrefA) {
26 xref = xrefA;
27 entries = NULL;
28 size = length = 0;
29 ref = 1;
30}
31
32Dict::~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
42void 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
52inline 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
62GBool Dict::is(char *type) {
63 DictEntry *e;
64
65 return (e = find("Type")) && e->val.isName(type);
66}
67
68Object *Dict::lookup(char *key, Object *obj) {
69 DictEntry *e;
70
71 return (e = find(key)) ? e->val.fetch(xref, obj) : obj->initNull();
72}
73
74Object *Dict::lookupNF(char *key, Object *obj) {
75 DictEntry *e;
76
77 return (e = find(key)) ? e->val.copy(obj) : obj->initNull();
78}
79
80char *Dict::getKey(int i) {
81 return entries[i].key;
82}
83
84Object *Dict::getVal(int i, Object *obj) {
85 return entries[i].val.fetch(xref, obj);
86}
87
88Object *Dict::getValNF(int i, Object *obj) {
89 return entries[i].val.copy(obj);
90}