]> git.donarmstrong.com Git - lilypond.git/blob - lily/symtable.cc
release: 0.0.65
[lilypond.git] / lily / symtable.cc
1 /*
2   symtable.cc -- implement Symbol_table
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "misc.hh"
10 #include "dimen.hh"
11 #include "debug.hh"
12 #include "real.hh"
13 #include "symbol.hh"
14 #include "assoc.hh"
15 #include "assoc-iter.hh"
16 #include "symtable.hh"
17
18 Symtables::Symtables()
19 {
20 }
21
22 Symtables::Symtables(Symtables const &s)
23 {
24     for (Assoc_iter<String, Symtable*>  i(s); i.ok(); i++) {
25         add(i.key(), new Symtable(*i.val()));
26     }
27 }
28
29 Symtables::~Symtables()
30 {
31     for (Assoc_iter<String, Symtable*>  i(*this); i.ok(); i++) {
32         delete i.val();
33     }
34 }
35
36 Symbol 
37 Symtable::lookup(String s) const
38 {
39     if (elt_b(s))
40         return (*this)[s];
41     else {
42         warning( "Symtable `" + id_str+ "\': unknown symbol `" +s+"'\n");
43         Symbol sy;                      // unreachable
44         sy.tex = "";
45         return sy;
46     }
47 }
48
49 Symtable* 
50 Symtables::operator()(String s) 
51 {
52     return Assoc<String, Symtable*>::operator[](s);
53
54 void
55 Symtables::print() const
56 {
57     for (Assoc_iter<String, Symtable*>  i(*this); i.ok(); i++) {
58         mtor << "table \'" << i.key() << "\' {\n";
59         i.val()->print();
60         mtor << "}\n";
61     }
62 }
63 void
64 Symtable::print() const
65 {
66     for (Assoc_iter<String, Symbol>  i(*this); i.ok(); i++) {
67         mtor << "\'" << i.key() << "\'->" << i.val().str() << "\n";
68     }
69 }
70         
71 void
72 Symtables::add(String s, Symtable*p)
73 {
74     p-> id_str = s;
75     Assoc<String, Symtable*>::add(s,p);
76 }