]> git.donarmstrong.com Git - lilypond.git/blob - lily/scope.cc
e58ad798cbdb6e290de724082adaa15ef1c558f3
[lilypond.git] / lily / scope.cc
1 /*   
2   scope.cc --  implement Scope
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "scope.hh"
11 #include "dictionary-iter.hh"
12 #include "debug.hh"
13 #include "identifier.hh"
14
15 void
16 Scope::print () const
17 {
18   bool init_b = false;          // ugh
19   for (Scope_iter ai (*this);  ai.ok(); ai++)
20     {
21       if (ai.val()->init_b_ == init_b)
22         {
23           DEBUG_OUT << ai.key() << "=";
24           ai.val()->print ();
25         }
26     }
27 }
28
29 Scope::~Scope ()
30 {
31   for (Scope_iter ai (*this); ai.ok(); ai++)
32     {
33       DEBUG_OUT << "deleting: " << ai.key() << '\n';
34       delete ai.val ();
35     }
36 }
37
38 Scope::Scope (Scope const&s)
39   : Hash_table<Protected_scm,Identifier*> (s)
40 {
41   for (Scope_iter ai (s); ai.ok(); ai++)
42     {
43       (*this)[ai.scm_key ()] = ai.val ()->clone ();
44     }
45 }
46
47 unsigned int scm_hash (Protected_scm s)
48 {
49   return scm_ihashv (s, ~1u);
50 }
51
52 Scope::Scope ()
53 {
54   hash_func_ = scm_hash;
55 }
56
57 bool
58 Scope::elem_b (String s) const
59 {
60   return elem_b (ly_symbol (s.ch_C()));
61 }
62
63
64 Identifier *&
65 Scope::elem (String s) 
66 {
67   return elem (ly_symbol (s.ch_C()));
68 }
69
70
71 Scope_iter::Scope_iter (Scope const &s)
72   : Hash_table_iter<Protected_scm,Identifier*>(s)
73 {
74 }
75
76 String
77 Scope_iter::key () const
78 {
79   SCM s= Hash_table_iter<Protected_scm,Identifier*>::key ();
80   return symbol_to_string (s);
81 }
82
83 bool
84 Scope::elem_b (SCM s) const
85 {
86   return Hash_table<Protected_scm,Identifier*> ::elem_b (s);
87 }
88
89 Identifier* &
90 Scope::elem (SCM s)
91 {
92   return Hash_table<Protected_scm,Identifier*> ::elem (s);
93 }
94
95 SCM
96 Scope_iter::scm_key () const
97 {
98   return Hash_table_iter<Protected_scm,Identifier*>::key ();
99 }