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