fixed windows access violation which occurs if one tries to retrieve
[swftools.git] / pdf2swf / xpdf / Dict.cc
blob5eb077e0937cab2186de3417d37230bd5c010d12
1 //========================================================================
2 //
3 // Dict.cc
4 //
5 // Copyright 1996-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #ifdef __GNUC__
10 #pragma implementation
11 #endif
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"
21 //------------------------------------------------------------------------
22 // Dict
23 //------------------------------------------------------------------------
25 Dict::Dict(XRef *xrefA) {
26 xref = xrefA;
27 entries = NULL;
28 size = length = 0;
29 ref = 1;
32 Dict::~Dict() {
33 int i;
35 for (i = 0; i < length; ++i) {
36 gfree(entries[i].key);
37 entries[i].val.free();
39 gfree(entries);
42 void Dict::add(char *key, Object *val) {
43 if (length + 1 > size) {
44 size += 8;
45 entries = (DictEntry *)grealloc(entries, size * sizeof(DictEntry));
47 entries[length].key = key;
48 entries[length].val = *val;
49 ++length;
52 inline DictEntry *Dict::find(char *key) {
53 int i;
55 for (i = 0; i < length; ++i) {
56 if (!strcmp(key, entries[i].key))
57 return &entries[i];
59 return NULL;
62 GBool Dict::is(char *type) {
63 DictEntry *e;
65 return (e = find("Type")) && e->val.isName(type);
68 Object *Dict::lookup(char *key, Object *obj) {
69 DictEntry *e;
71 return (e = find(key)) ? e->val.fetch(xref, obj) : obj->initNull();
74 Object *Dict::lookupNF(char *key, Object *obj) {
75 DictEntry *e;
77 return (e = find(key)) ? e->val.copy(obj) : obj->initNull();
80 char *Dict::getKey(int i) {
81 return entries[i].key;
84 Object *Dict::getVal(int i, Object *obj) {
85 return entries[i].val.fetch(xref, obj);
88 Object *Dict::getValNF(int i, Object *obj) {
89 return entries[i].val.copy(obj);