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