xref: /netbsd-src/external/gpl2/groff/dist/src/roff/troff/dictionary.h (revision 89a07cf815a29524268025a1139fac4c5190f765)
1 /*	$NetBSD: dictionary.h,v 1.1.1.1 2016/01/13 18:41:48 christos Exp $	*/
2 
3 // -*- C++ -*-
4 /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
5      Written by James Clark (jjc@jclark.com)
6 
7 This file is part of groff.
8 
9 groff is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
12 version.
13 
14 groff is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License along
20 with groff; see the file COPYING.  If not, write to the Free Software
21 Foundation, 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 
28 struct association {
29   symbol s;
30   void *v;
associationassociation31   association() :  v(0) {}
32 };
33 
34 class dictionary;
35 
36 class dictionary_iterator {
37   dictionary *dict;
38   int i;
39 public:
40   dictionary_iterator(dictionary &);
41   int get(symbol *, void **);
42 };
43 
44 class dictionary {
45   int size;
46   int used;
47   double threshold;
48   double factor;
49   association *table;
50   void rehash(int);
51 public:
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 
60 class object {
61   int rcount;
62  public:
63   object();
64   virtual ~object();
65   void add_reference();
66   void remove_reference();
67 };
68 
69 class object_dictionary;
70 
71 class object_dictionary_iterator {
72   dictionary_iterator di;
73 public:
74   object_dictionary_iterator(object_dictionary &);
75   int get(symbol *, object **);
76 };
77 
78 class object_dictionary {
79   dictionary d;
80 public:
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 
get(symbol * sp,object ** op)91 inline int object_dictionary_iterator::get(symbol *sp, object **op)
92 {
93   return di.get(sp, (void **)op);
94 }
95