]> git.donarmstrong.com Git - lilypond.git/blob - lily/symtable.cc
release: 0.1.24
[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 "atom.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     {
26       add (i.key(), new Symtable (*i.val ()));
27     }
28 }
29
30 Symtables::~Symtables()
31 {
32   for (Assoc_iter<String, Symtable*>  i (*this); i.ok(); i++)
33     {
34       delete i.val();
35     }
36 }
37
38 Atom
39 Symtable::lookup (String s) const
40 {
41   if (elt_b (s))
42     return (*this)[s];
43   else
44     {
45       warning ("Symtable `" + id_str+ _("\': unknown symbol `") +s+"'\n");
46       Atom sy;
47       return sy;
48     }
49 }
50
51 Symtable*
52 Symtables::operator()(String s)
53 {
54   if (!elt_b (s))
55     {
56       warning ("Symtables `" + s + _("\' unknown"));
57       return 0;
58     }
59   else
60     return Dictionary<Symtable*>::operator[](s);
61 }
62 void
63 Symtables::print() const
64 {
65   for (Assoc_iter<String, Symtable*>  i (*this); i.ok(); i++)
66     {
67       DOUT << "table \'" << i.key() << "\' {\n";
68       i.val()->print ();
69       DOUT << "}\n";
70     }
71 }
72 void
73 Symtable::print() const
74 {
75   for (Assoc_iter<String, Atom>  i (*this); i.ok(); i++)
76     {
77       DOUT << "\'" << i.key() << "\'->" << i.val ().str () << "\n";
78     }
79 }
80
81 void
82 Symtables::add (String s, Symtable*p)
83 {
84   p-> id_str = s;
85   Dictionary<Symtable*>::add (s,p);
86 }