]> git.ipfire.org Git - thirdparty/cups.git/blame - pdftops/Dict.cxx
Load cups into easysw/current.
[thirdparty/cups.git] / pdftops / Dict.cxx
CommitLineData
ef416fc2 1//========================================================================
2//
3// Dict.cc
4//
5// Copyright 1996-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9#include <config.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
26Dict::Dict(XRef *xrefA) {
27 xref = xrefA;
28 entries = NULL;
29 size = length = 0;
30 ref = 1;
31}
32
33Dict::~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
43void Dict::add(char *key, Object *val) {
44 if (length == size) {
45 if (length == 0) {
46 size = 8;
47 } else {
48 size *= 2;
49 }
50 entries = (DictEntry *)greallocn(entries, size, sizeof(DictEntry));
51 }
52 entries[length].key = key;
53 entries[length].val = *val;
54 ++length;
55}
56
57inline DictEntry *Dict::find(char *key) {
58 int i;
59
60 for (i = 0; i < length; ++i) {
61 if (!strcmp(key, entries[i].key))
62 return &entries[i];
63 }
64 return NULL;
65}
66
67GBool Dict::is(char *type) {
68 DictEntry *e;
69
70 return (e = find("Type")) && e->val.isName(type);
71}
72
73Object *Dict::lookup(char *key, Object *obj) {
74 DictEntry *e;
75
76 return (e = find(key)) ? e->val.fetch(xref, obj) : obj->initNull();
77}
78
79Object *Dict::lookupNF(char *key, Object *obj) {
80 DictEntry *e;
81
82 return (e = find(key)) ? e->val.copy(obj) : obj->initNull();
83}
84
85char *Dict::getKey(int i) {
86 return entries[i].key;
87}
88
89Object *Dict::getVal(int i, Object *obj) {
90 return entries[i].val.fetch(xref, obj);
91}
92
93Object *Dict::getValNF(int i, Object *obj) {
94 return entries[i].val.copy(obj);
95}