1/* $NetBSD$ */ 2 3// -*- C++ -*- 4/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. 5 Written by James Clark (jjc@jclark.com) 6 7This file is part of groff. 8 9groff is free software; you can redistribute it and/or modify it under 10the terms of the GNU General Public License as published by the Free 11Software Foundation; either version 2, or (at your option) any later 12version. 13 14groff is distributed in the hope that it will be useful, but WITHOUT ANY 15WARRANTY; without even the implied warranty of MERCHANTABILITY or 16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17for more details. 18 19You should have received a copy of the GNU General Public License along 20with groff; see the file COPYING. If not, write to the Free Software 21Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23 24 25// there is no distinction between name with no value and name with NULL value 26// null names are not permitted (they will be ignored). 27 28struct association { 29 symbol s; 30 void *v; 31 association() : v(0) {} 32}; 33 34class dictionary; 35 36class dictionary_iterator { 37 dictionary *dict; 38 int i; 39public: 40 dictionary_iterator(dictionary &); 41 int get(symbol *, void **); 42}; 43 44class dictionary { 45 int size; 46 int used; 47 double threshold; 48 double factor; 49 association *table; 50 void rehash(int); 51public: 52 dictionary(int); 53 void *lookup(symbol s, void *v=0); // returns value associated with key 54 void *lookup(const char *); 55 // if second parameter not NULL, value will be replaced 56 void *remove(symbol); 57 friend class dictionary_iterator; 58}; 59 60class object { 61 int rcount; 62 public: 63 object(); 64 virtual ~object(); 65 void add_reference(); 66 void remove_reference(); 67}; 68 69class object_dictionary; 70 71class object_dictionary_iterator { 72 dictionary_iterator di; 73public: 74 object_dictionary_iterator(object_dictionary &); 75 int get(symbol *, object **); 76}; 77 78class object_dictionary { 79 dictionary d; 80public: 81 object_dictionary(int); 82 object *lookup(symbol nm); 83 void define(symbol nm, object *obj); 84 void rename(symbol oldnm, symbol newnm); 85 void remove(symbol nm); 86 int alias(symbol newnm, symbol oldnm); 87 friend class object_dictionary_iterator; 88}; 89 90 91inline int object_dictionary_iterator::get(symbol *sp, object **op) 92{ 93 return di.get(sp, (void **)op); 94} 95