1
//========================================================================
5
// Copyright 1996-2003 Glyph & Cog, LLC
7
//========================================================================
9
//========================================================================
11
// Modified under the Poppler project - http://poppler.freedesktop.org
13
// All changes made under the Poppler project to this file are licensed
14
// under GPL version 2 or later
16
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
17
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
18
// Copyright (C) 2007-2008 Julien Rebetez <julienr@svn.gnome.org>
19
// Copyright (C) 2008 Albert Astals Cid <aacid@kde.org>
21
// To see a description of the changes please see the Changelog file that
22
// came with your tarball or type make ChangeLog if you are building from git
24
//========================================================================
28
#ifdef USE_GCC_PRAGMAS
29
#pragma implementation
39
//------------------------------------------------------------------------
41
//------------------------------------------------------------------------
43
Dict::Dict(XRef *xrefA) {
50
Dict::Dict(Dict* dictA) {
52
size = length = dictA->length;
55
entries = (DictEntry *)gmallocn(size, sizeof(DictEntry));
56
for (int i=0; i<length; i++) {
57
entries[i].key = strdup(dictA->entries[i].key);
58
dictA->entries[i].val.copy(&entries[i].val);
65
for (i = 0; i < length; ++i) {
66
gfree(entries[i].key);
67
entries[i].val.free();
72
void Dict::add(char *key, Object *val) {
79
entries = (DictEntry *)greallocn(entries, size, sizeof(DictEntry));
81
entries[length].key = key;
82
entries[length].val = *val;
86
inline DictEntry *Dict::find(char *key) {
89
for (i = length - 1; i >=0; --i) {
90
if (!strcmp(key, entries[i].key))
96
void Dict::remove(char *key) {
100
if(length == 0) return;
102
for(i=0; i<length; i++) {
103
if (!strcmp(key, entries[i].key)) {
109
//replace the deleted entry with the last entry
111
tmp = entries[length];
112
if (i!=length) //don't copy the last entry if it is deleted
116
void Dict::set(char *key, Object *val) {
123
add (copyString(key), val);
128
GBool Dict::is(char *type) {
131
return (e = find("Type")) && e->val.isName(type);
134
Object *Dict::lookup(char *key, Object *obj) {
137
return (e = find(key)) ? e->val.fetch(xref, obj) : obj->initNull();
140
Object *Dict::lookupNF(char *key, Object *obj) {
143
return (e = find(key)) ? e->val.copy(obj) : obj->initNull();
146
GBool Dict::lookupInt(const char *key, const char *alt_key, int *value)
149
GBool success = gFalse;
151
lookup ((char *) key, &obj1);
152
if (obj1.isNull () && alt_key != NULL) {
154
lookup ((char *) alt_key, &obj1);
157
*value = obj1.getInt ();
166
char *Dict::getKey(int i) {
167
return entries[i].key;
170
Object *Dict::getVal(int i, Object *obj) {
171
return entries[i].val.fetch(xref, obj);
174
Object *Dict::getValNF(int i, Object *obj) {
175
return entries[i].val.copy(obj);