home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / pdf / Dict.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  2.2 KB  |  108 lines

  1. //========================================================================
  2. //
  3. // Dict.cc
  4. //
  5. // Copyright 1996 Derek B. Noonburg
  6. //
  7. //========================================================================
  8. //
  9. // Ported to EPOC by Sander van der Wal
  10. //
  11. // $Log: Dict.cpp $
  12. // Revision 1.3  2000-09-25 20:58:48+02  svdwal
  13. // Profile macros removed
  14. //
  15. // Revision 1.2  2000-09-17 13:38:25+02  svdwal
  16. // Ported
  17. //
  18.  
  19. #ifdef __GNUC__
  20. #pragma implementation
  21. #endif
  22.  
  23. #ifndef __E32DEF_H__
  24. #include <e32def.h>
  25. #endif
  26.  
  27. #include "gmem.h"
  28.  
  29. #include "Object.h"
  30. #include "XRef.h"
  31. #include "Dict.h"
  32.  
  33. #include "PROFILE.h"
  34.  
  35. #ifndef OOM 
  36. static const TInt KDictSizeIncrement = 8;
  37. #else
  38. static const TInt KDictSizeIncrement = 1;
  39. #endif
  40.  
  41. //------------------------------------------------------------------------
  42. // Dict
  43. //------------------------------------------------------------------------
  44.  
  45. Dict::Dict() {
  46.   ref = 1;
  47. }
  48.  
  49. Dict::~Dict() {
  50.   int i;
  51.  
  52.   if (entries)
  53.     for (i = 0; i < length; ++i) {
  54.       User::Free(entries[i].key);
  55.       entries[i].val.free();
  56.     }
  57.   User::Free(entries);
  58. }
  59.  
  60. void Dict::addL(char *key, Object *val) {
  61.   if (length + 1 > size) {
  62.     size += KDictSizeIncrement;
  63.     entries = (DictEntry *)User::ReAllocL(entries, size * sizeof(DictEntry));
  64.   }
  65.   entries[length].key = key;
  66.   entries[length].val = *val;
  67.   ++length;
  68. }
  69.  
  70. inline DictEntry *Dict::find(char *key) {
  71.   int i;
  72.  
  73.   for (i = 0; i < length; ++i) {
  74.     if (!strcmp(key, entries[i].key)) {
  75.       return &entries[i];
  76.     }
  77.   }
  78.   return NULL;  
  79. }
  80.  
  81. GBool Dict::is(char *type) {
  82.   DictEntry *e=find("Type");
  83.   return (e) && e->val.isName(type);
  84. }
  85.  
  86. Object *Dict::lookupL(char *key, Object *obj) {
  87.   DictEntry *e= find(key);
  88.   return (e) ? e->val.fetchL(obj) : obj->initNull();
  89. }
  90.  
  91. Object *Dict::lookupNFL(char *key, Object *obj) {
  92.   DictEntry *e= find(key);
  93.  
  94.   return (e) ? e->val.copyL(obj) : obj->initNull();
  95. }
  96.  
  97. char *Dict::getKey(int i) {
  98.   return entries[i].key;
  99. }
  100.  
  101. Object *Dict::getValL(int i, Object *obj) {
  102.   return entries[i].val.fetchL(obj);
  103. }
  104.  
  105. Object *Dict::getValNFL(int i, Object *obj) {
  106.   return entries[i].val.copyL(obj);
  107. }
  108.