175584Sru// -*- C++ -*- 275584Sru/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. 375584Sru Written by James Clark (jjc@jclark.com) 475584Sru 575584SruThis file is part of groff. 675584Sru 775584Srugroff is free software; you can redistribute it and/or modify it under 875584Sruthe terms of the GNU General Public License as published by the Free 975584SruSoftware Foundation; either version 2, or (at your option) any later 1075584Sruversion. 1175584Sru 1275584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY 1375584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or 1475584SruFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1575584Srufor more details. 1675584Sru 1775584SruYou should have received a copy of the GNU General Public License along 1875584Sruwith groff; see the file COPYING. If not, write to the Free Software 19151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 2075584Sru 2175584Sru 2275584Sru 2375584Sru// there is no distinction between name with no value and name with NULL value 2475584Sru// null names are not permitted (they will be ignored). 2575584Sru 2675584Srustruct association { 2775584Sru symbol s; 2875584Sru void *v; 2975584Sru association() : v(0) {} 3075584Sru}; 3175584Sru 3275584Sruclass dictionary; 3375584Sru 3475584Sruclass dictionary_iterator { 3575584Sru dictionary *dict; 3675584Sru int i; 3775584Srupublic: 3875584Sru dictionary_iterator(dictionary &); 3975584Sru int get(symbol *, void **); 4075584Sru}; 4175584Sru 4275584Sruclass dictionary { 4375584Sru int size; 4475584Sru int used; 4575584Sru double threshold; 4675584Sru double factor; 4775584Sru association *table; 4875584Sru void rehash(int); 4975584Srupublic: 5075584Sru dictionary(int); 5175584Sru void *lookup(symbol s, void *v=0); // returns value associated with key 5275584Sru void *lookup(const char *); 5375584Sru // if second parameter not NULL, value will be replaced 5475584Sru void *remove(symbol); 5575584Sru friend class dictionary_iterator; 5675584Sru}; 5775584Sru 5875584Sruclass object { 5975584Sru int rcount; 6075584Sru public: 6175584Sru object(); 6275584Sru virtual ~object(); 6375584Sru void add_reference(); 6475584Sru void remove_reference(); 6575584Sru}; 6675584Sru 6775584Sruclass object_dictionary; 6875584Sru 6975584Sruclass object_dictionary_iterator { 7075584Sru dictionary_iterator di; 7175584Srupublic: 7275584Sru object_dictionary_iterator(object_dictionary &); 7375584Sru int get(symbol *, object **); 7475584Sru}; 7575584Sru 7675584Sruclass object_dictionary { 7775584Sru dictionary d; 7875584Srupublic: 7975584Sru object_dictionary(int); 8075584Sru object *lookup(symbol nm); 8175584Sru void define(symbol nm, object *obj); 8275584Sru void rename(symbol oldnm, symbol newnm); 8375584Sru void remove(symbol nm); 8475584Sru int alias(symbol newnm, symbol oldnm); 8575584Sru friend class object_dictionary_iterator; 8675584Sru}; 8775584Sru 8875584Sru 8975584Sruinline int object_dictionary_iterator::get(symbol *sp, object **op) 9075584Sru{ 9175584Sru return di.get(sp, (void **)op); 9275584Sru} 93