1 
2 /******************************************************************************
3 * MODULE     : tree_label.cpp
4 * DESCRIPTION: labels of trees
5 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11 
12 #include "tree_label.hpp"
13 #include "hashmap.hpp"
14 
15 hashmap<int,string> CONSTRUCTOR_NAME ("?");
16 hashmap<string,int> CONSTRUCTOR_CODE (UNKNOWN);
17 
18 /******************************************************************************
19 * Setting up the conversion tables
20 ******************************************************************************/
21 
22 static tree_label next_tree_label= START_EXTENSIONS;
23 
24 void
make_tree_label(tree_label l,string s)25 make_tree_label (tree_label l, string s) {
26   CONSTRUCTOR_NAME ((int) l) = s;
27   CONSTRUCTOR_CODE (s)       = (int) l;
28 }
29 
30 tree_label
make_tree_label(string s)31 make_tree_label (string s) {
32   if (CONSTRUCTOR_CODE->contains (s))
33     return (tree_label) CONSTRUCTOR_CODE[s];
34   tree_label l= next_tree_label;
35   next_tree_label= (tree_label) (((int) next_tree_label) + 1);
36   make_tree_label (l, s);
37   return l;
38 }
39 
40 /******************************************************************************
41 * Conversions between tree_labels and strings
42 ******************************************************************************/
43 
44 string
as_string(tree_label l)45 as_string (tree_label l) {
46   return CONSTRUCTOR_NAME[(int) l];
47 }
48 
49 tree_label
as_tree_label(string s)50 as_tree_label (string s) {
51   return (tree_label) CONSTRUCTOR_CODE[s];
52 }
53 
54 bool
existing_tree_label(string s)55 existing_tree_label (string s) {
56   return CONSTRUCTOR_CODE->contains (s);
57 }
58