Line data Source code
1 : /* Copyright 1989-2020 Free Software Foundation, Inc. 2 : Written by James Clark (jjc@jclark.com) 3 : 4 : This file is part of groff, the GNU roff typesetting system. 5 : 6 : groff is free software; you can redistribute it and/or modify it under 7 : the terms of the GNU General Public License as published by the Free 8 : Software Foundation, either version 3 of the License, or 9 : (at your option) any later version. 10 : 11 : groff is distributed in the hope that it will be useful, but WITHOUT ANY 12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 : for more details. 15 : 16 : You should have received a copy of the GNU General Public License 17 : along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 : 19 : 20 : // There is no distinction between a name with no value and a name with 21 : // a 0 (nullptr) value. Null names are not permitted; they are ignored. 22 : 23 : struct association { 24 : symbol s; 25 : void *v; 26 15772516 : association() : v(0 /* nullptr */) {} 27 : }; 28 : 29 : class dictionary; 30 : 31 : class dictionary_iterator { 32 : dictionary *dict; 33 : int i; 34 : public: 35 : dictionary_iterator(dictionary &); 36 : bool get(symbol *, void **); 37 : }; 38 : 39 : class dictionary { 40 : int size; 41 : int used; 42 : double threshold; 43 : double factor; 44 : association *table; 45 : void rehash(int); 46 : public: 47 : dictionary(int); 48 : void *lookup(symbol s, void *v = 0 /* nullptr */); 49 : void *lookup(const char *); 50 : void *remove(symbol); 51 : friend class dictionary_iterator; 52 : }; 53 : 54 : class object { 55 : int refcount; 56 : public: 57 : object(); 58 : virtual ~object(); 59 : void add_reference(); 60 : void remove_reference(); 61 : }; 62 : 63 : class object_dictionary; 64 : 65 : class object_dictionary_iterator { 66 : dictionary_iterator di; 67 : public: 68 : object_dictionary_iterator(object_dictionary &); 69 : bool get(symbol *, object **); 70 : }; 71 : 72 : class object_dictionary { 73 : dictionary d; 74 : public: 75 : object_dictionary(int); 76 : object *lookup(symbol); 77 : void define(symbol, object *); 78 : void rename(symbol, symbol); 79 : void remove(symbol); 80 : bool alias(symbol, symbol); 81 : friend class object_dictionary_iterator; 82 : }; 83 : 84 : 85 1403 : inline bool object_dictionary_iterator::get(symbol *sp, object **op) 86 : { 87 1403 : return di.get(sp, (void **)op); 88 : } 89 : 90 : // Local Variables: 91 : // fill-column: 72 92 : // mode: C++ 93 : // End: 94 : // vim: set cindent noexpandtab shiftwidth=2 textwidth=72: