lilypond-0.0.50
[lilypond.git] / lily / symtable.cc
blob9dc82c0631c32160a43d9c73ccb0e0b5257db186
1 /*
2 symtable.cc -- implement Symbol_table
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
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"
18 Symtables::Symtables()
22 Symtables::Symtables(Symtables const &s)
24 for (Assoc_iter<String, Symtable*> i(s); i.ok(); i++) {
25 add(i.key(), new Symtable(*i.val()));
29 Symtables::~Symtables()
31 for (Assoc_iter<String, Symtable*> i(*this); i.ok(); i++) {
32 delete i.val();
36 Symbol
37 Symtable::lookup(String s) const
39 if (elt_b(s))
40 return (*this)[s];
41 else {
42 error( "Symtable `" + id_str+ "\': unknown symbol `" +s+"'\n");
44 Symbol sy; // unreachable
45 return sy;
48 Symtable*
49 Symtables::operator()(String s)
51 return Assoc<String, Symtable*>::operator[](s);
53 void
54 Symtables::print() const
56 for (Assoc_iter<String, Symtable*> i(*this); i.ok(); i++) {
57 mtor << "table \'" << i.key() << "\' {\n";
58 i.val()->print();
59 mtor << "}\n";
62 void
63 Symtable::print() const
65 for (Assoc_iter<String, Symbol> i(*this); i.ok(); i++) {
66 mtor << "\'" << i.key() << "\'->" << i.val().str() << "\n";
70 void
71 Symtables::add(String s, Symtable*p)
73 p-> id_str = s;
74 Assoc<String, Symtable*>::add(s,p);