Back to index

texmacs  1.0.7.15
tree_label.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : tree_label.cpp
00004 * DESCRIPTION: labels of trees
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "tree_label.hpp"
00013 #include "hashmap.hpp"
00014 
00015 hashmap<int,string> CONSTRUCTOR_NAME ("?");
00016 hashmap<string,int> CONSTRUCTOR_CODE (UNKNOWN);
00017 
00018 /******************************************************************************
00019 * Setting up the conversion tables
00020 ******************************************************************************/
00021 
00022 static tree_label next_tree_label= START_EXTENSIONS;
00023 
00024 void
00025 make_tree_label (tree_label l, string s) {
00026   CONSTRUCTOR_NAME ((int) l) = s;
00027   CONSTRUCTOR_CODE (s)       = (int) l;
00028 }
00029 
00030 tree_label
00031 make_tree_label (string s) {
00032   if (CONSTRUCTOR_CODE->contains (s))
00033     return (tree_label) CONSTRUCTOR_CODE[s];
00034   tree_label l= next_tree_label;
00035   next_tree_label= (tree_label) (((int) next_tree_label) + 1);
00036   make_tree_label (l, s);
00037   return l;
00038 }
00039 
00040 /******************************************************************************
00041 * Conversions between tree_labels and strings
00042 ******************************************************************************/
00043 
00044 string
00045 as_string (tree_label l) {
00046   return CONSTRUCTOR_NAME[(int) l];
00047 }
00048 
00049 tree_label
00050 as_tree_label (string s) {
00051   return (tree_label) CONSTRUCTOR_CODE[s];
00052 }
00053 
00054 bool
00055 existing_tree_label (string s) {
00056   return CONSTRUCTOR_CODE->contains (s);
00057 }