filters
Dict.cc00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <aconf.h>
00010
00011 #ifdef USE_GCC_PRAGMAS
00012 #pragma implementation
00013 #endif
00014
00015 #include <stddef.h>
00016 #include <string.h>
00017 #include "gmem.h"
00018 #include "Object.h"
00019 #include "XRef.h"
00020 #include "Dict.h"
00021
00022
00023
00024
00025
00026 Dict::Dict(XRef *xrefA) {
00027 xref = xrefA;
00028 entries = NULL;
00029 size = length = 0;
00030 ref = 1;
00031 }
00032
00033 Dict::~Dict() {
00034 int i;
00035
00036 for (i = 0; i < length; ++i) {
00037 gfree(entries[i].key);
00038 entries[i].val.free();
00039 }
00040 gfree(entries);
00041 }
00042
00043 void Dict::add(char *key, Object *val) {
00044 if (length + 1 > size) {
00045 size += 8;
00046 entries = (DictEntry *)grealloc(entries, size * sizeof(DictEntry));
00047 }
00048 entries[length].key = key;
00049 entries[length].val = *val;
00050 ++length;
00051 }
00052
00053 inline DictEntry *Dict::find(const char *key) {
00054 int i;
00055
00056 for (i = 0; i < length; ++i) {
00057 if (!strcmp(key, entries[i].key))
00058 return &entries[i];
00059 }
00060 return NULL;
00061 }
00062
00063 GBool Dict::is(const char *type) {
00064 DictEntry *e;
00065
00066 return (e = find("Type")) && e->val.isName(type);
00067 }
00068
00069 Object *Dict::lookup(const char *key, Object *obj) {
00070 DictEntry *e;
00071
00072 return (e = find(key)) ? e->val.fetch(xref, obj) : obj->initNull();
00073 }
00074
00075 Object *Dict::lookupNF(const char *key, Object *obj) {
00076 DictEntry *e;
00077
00078 return (e = find(key)) ? e->val.copy(obj) : obj->initNull();
00079 }
00080
00081 char *Dict::getKey(int i) {
00082 return entries[i].key;
00083 }
00084
00085 Object *Dict::getVal(int i, Object *obj) {
00086 return entries[i].val.fetch(xref, obj);
00087 }
00088
00089 Object *Dict::getValNF(int i, Object *obj) {
00090 return entries[i].val.copy(obj);
00091 }
|