home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 110 / EnigmaAmiga110CD.iso / indispensabili / utility / apdf / xpdf-0.80 / xpdf / dict.cc < prev    next >
C/C++ Source or Header  |  1998-11-27  |  2KB  |  89 lines

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