lilypond-1.1.55
[lilypond.git] / lily / symtable.cc
blobccf1eb16102584041048253f83486af0a9154f39
1 /*
2 symtable.cc -- implement Symbol_table
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
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"
16 Symtables::Symtables()
21 Symtables::Symtables (Symtables const &s)
22 : Dictionary<Symtable*> (s)
24 font_name_ = s.font_name_;
26 for (Dictionary_iter< Symtable*> i (s); i.ok(); i++)
28 add (i.key(), new Symtable (*i.val ()));
32 Symtables::~Symtables()
34 for (Dictionary_iter<Symtable*> i (*this); i.ok(); i++)
36 delete i.val();
40 Atom
41 Symtable::lookup (String s) const
43 if (elem_b (s))
45 Atom a (elem(s));
46 return a;
48 else
50 warning (_f ("Symtable `%s\': unknown symbol: `%s\'", id_str, s));
51 Atom sy;
52 return sy;
56 Symtable*
57 Symtables::operator()(String s)
59 if (!elem_b (s))
61 error (_f ("Symtable `%s\' unknown", s));
62 /*
63 We can 't return, because we would dump core anyway.
65 return 0;
67 else
68 return elem(s);
70 void
71 Symtables::print() const
73 for (Dictionary_iter<Symtable*> i (*this); i.ok(); i++)
75 DOUT << "table \'" << i.key () << "\' {\n";
76 i.val()->print ();
77 DOUT << "}\n";
80 void
81 Symtable::print() const
83 for (Dictionary_iter<Atom> i (*this); i.ok(); i++)
85 DOUT << "\'" << i.key() << "\'->" << i.val ().str () << '\n';
89 void
90 Symtables::add (String s, Symtable*p)
92 p-> id_str = s;
93 Dictionary<Symtable*>::elem (s) = p;