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