home *** CD-ROM | disk | FTP | other *** search
- //========================================================================
- //
- // Dict.cc
- //
- // Copyright 1996 Derek B. Noonburg
- //
- //========================================================================
- //
- // Ported to EPOC by Sander van der Wal
- //
- // $Log: Dict.cpp $
- // Revision 1.3 2000-09-25 20:58:48+02 svdwal
- // Profile macros removed
- //
- // Revision 1.2 2000-09-17 13:38:25+02 svdwal
- // Ported
- //
-
- #ifdef __GNUC__
- #pragma implementation
- #endif
-
- #ifndef __E32DEF_H__
- #include <e32def.h>
- #endif
-
- #include "gmem.h"
-
- #include "Object.h"
- #include "XRef.h"
- #include "Dict.h"
-
- #include "PROFILE.h"
-
- #ifndef OOM
- static const TInt KDictSizeIncrement = 8;
- #else
- static const TInt KDictSizeIncrement = 1;
- #endif
-
- //------------------------------------------------------------------------
- // Dict
- //------------------------------------------------------------------------
-
- Dict::Dict() {
- ref = 1;
- }
-
- Dict::~Dict() {
- int i;
-
- if (entries)
- for (i = 0; i < length; ++i) {
- User::Free(entries[i].key);
- entries[i].val.free();
- }
- User::Free(entries);
- }
-
- void Dict::addL(char *key, Object *val) {
- if (length + 1 > size) {
- size += KDictSizeIncrement;
- entries = (DictEntry *)User::ReAllocL(entries, size * sizeof(DictEntry));
- }
- entries[length].key = key;
- entries[length].val = *val;
- ++length;
- }
-
- inline DictEntry *Dict::find(char *key) {
- int i;
-
- for (i = 0; i < length; ++i) {
- if (!strcmp(key, entries[i].key)) {
- return &entries[i];
- }
- }
- return NULL;
- }
-
- GBool Dict::is(char *type) {
- DictEntry *e=find("Type");
- return (e) && e->val.isName(type);
- }
-
- Object *Dict::lookupL(char *key, Object *obj) {
- DictEntry *e= find(key);
- return (e) ? e->val.fetchL(obj) : obj->initNull();
- }
-
- Object *Dict::lookupNFL(char *key, Object *obj) {
- DictEntry *e= find(key);
-
- return (e) ? e->val.copyL(obj) : obj->initNull();
- }
-
- char *Dict::getKey(int i) {
- return entries[i].key;
- }
-
- Object *Dict::getValL(int i, Object *obj) {
- return entries[i].val.fetchL(obj);
- }
-
- Object *Dict::getValNFL(int i, Object *obj) {
- return entries[i].val.copyL(obj);
- }
-