]> git.donarmstrong.com Git - lilypond.git/blob - lily/symtable.cc
94aba34bea350b9ee019ed8d770f16583f36030e
[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--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "misc.hh"
10 #include "debug.hh"
11 #include "real.hh"
12 #include "atom.hh"
13 #include "assoc.hh"
14 #include "assoc-iter.hh"
15 #include "symtable.hh"
16
17 Symtables::Symtables()
18 {
19 }
20
21
22 Symtables::Symtables (Symtables const &s)
23   : Dictionary<Symtable*> (s)
24 {
25   font_ = s.font_;
26   font_path_ = s.font_path_;
27   for (Assoc_iter<String, Symtable*>  i (s); i.ok(); i++)
28     {
29       add (i.key(), new Symtable (*i.val ()));
30     }
31 }
32
33 Symtables::~Symtables()
34 {
35   for (Assoc_iter<String, Symtable*>  i (*this); i.ok(); i++)
36     {
37       delete i.val();
38     }
39 }
40
41 Atom
42 Symtable::lookup (String s) const
43 {
44   if (elem_b (s))
45     {
46       Atom a (elem(s));
47       return a;
48     }
49   else
50     {
51       warning (_f ("Symtable `%s\': unknown symbol: `%s\'", id_str, s));
52       Atom sy;
53       return sy;
54     }
55 }
56
57 Symtable*
58 Symtables::operator()(String s)
59 {
60   if (!elem_b (s))
61     {
62       error (_f ("Symtable `%s\' unknown", s));
63       /* 
64          We can 't return, because we'll dump core anyway.
65        */
66       return 0;
67     }
68   else
69     return Dictionary<Symtable*>::operator[](s);
70 }
71 void
72 Symtables::print() const
73 {
74   for (Assoc_iter<String, Symtable*>  i (*this); i.ok(); i++)
75     {
76       DOUT << "table \'" << i.key () << "\' {\n";
77       i.val()->print ();
78       DOUT << "}\n";
79     }
80 }
81 void
82 Symtable::print() const
83 {
84   for (Assoc_iter<String, Atom>  i (*this); i.ok(); i++)
85     {
86       DOUT << "\'" << i.key() << "\'->" << i.val ().str () << '\n';
87     }
88 }
89
90 void
91 Symtables::add (String s, Symtable*p)
92 {
93   p-> id_str = s;
94   Dictionary<Symtable*>::add (s,p);
95 }