]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/Dict.cc
9575e4cbf108f523870fca77fba975ddb45e7a1a
[evince.git] / pdf / xpdf / Dict.cc
1 //========================================================================
2 //
3 // Dict.cc
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #include <aconf.h>
10
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14
15 #include <stddef.h>
16 #include <string.h>
17 #include "gmem.h"
18 #include "Object.h"
19 #include "XRef.h"
20 #include "Dict.h"
21
22 //------------------------------------------------------------------------
23 // Dict
24 //------------------------------------------------------------------------
25
26 Dict::Dict(XRef *xrefA) {
27   xref = xrefA;
28   entries = NULL;
29   size = length = 0;
30   ref = 1;
31 }
32
33 Dict::~Dict() {
34   int i;
35
36   for (i = 0; i < length; ++i) {
37     gfree(entries[i].key);
38     entries[i].val.free();
39   }
40   gfree(entries);
41 }
42
43 void Dict::add(char *key, Object *val) {
44   if (length + 1 > size) {
45     size += 8;
46     entries = (DictEntry *)grealloc(entries, size * sizeof(DictEntry));
47   }
48   entries[length].key = key;
49   entries[length].val = *val;
50   ++length;
51 }
52
53 inline DictEntry *Dict::find(char *key) {
54   int i;
55
56   for (i = 0; i < length; ++i) {
57     if (!strcmp(key, entries[i].key))
58       return &entries[i];
59   }
60   return NULL;
61 }
62
63 GBool Dict::is(char *type) {
64   DictEntry *e;
65
66   return (e = find("Type")) && e->val.isName(type);
67 }
68
69 Object *Dict::lookup(char *key, Object *obj) {
70   DictEntry *e;
71
72   return (e = find(key)) ? e->val.fetch(xref, obj) : obj->initNull();
73 }
74
75 Object *Dict::lookupNF(char *key, Object *obj) {
76   DictEntry *e;
77
78   return (e = find(key)) ? e->val.copy(obj) : obj->initNull();
79 }
80
81 char *Dict::getKey(int i) {
82   return entries[i].key;
83 }
84
85 Object *Dict::getVal(int i, Object *obj) {
86   return entries[i].val.fetch(xref, obj);
87 }
88
89 Object *Dict::getValNF(int i, Object *obj) {
90   return entries[i].val.copy(obj);
91 }