]> git.donarmstrong.com Git - lilypond.git/blob - lily/scope.cc
e2923fcb80bfa68ca954be7c6a01235d483ffb5f
[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--2000 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 #include "dictionary.hh"
15 #include "protected-scm.hh"
16
17 void
18 Scope::print () const
19 {
20 #ifndef NPRINT
21   bool init_b = false;          // ugh
22   for (Scope_iter ai (*this);  ai.ok(); ai++)
23     {
24       if (ai.val()->init_b_ == init_b)
25         {
26           DEBUG_OUT << ai.key() << "=";
27           ai.val()->print ();
28         }
29     }
30 #endif
31 }
32
33 Scope::~Scope ()
34 {
35   for (Scope_iter ai (*this); ai.ok(); ai++)
36     {
37       DEBUG_OUT << "deleting: " << ai.key() << '\n';
38       delete ai.val ();
39     }
40   delete id_dict_;
41 }
42
43 Scope::Scope (Scope const&s)
44 {
45   id_dict_ = new Hash_table<Protected_scm,Identifier*> (*s.id_dict_);
46   for (Scope_iter ai (s); ai.ok(); ai++)
47     {
48       id_dict_->elem (ai.scm_key ()) = ai.val ()->clone ();
49     }
50 }
51
52 unsigned int ly_pscm_hash (Protected_scm s)
53 {
54   return ly_scm_hash (s);
55 }
56
57
58 Scope::Scope ()
59 {
60   id_dict_ = new Hash_table<Protected_scm,Identifier*>;
61   id_dict_->hash_func_ = ly_pscm_hash;
62 }
63
64 bool
65 Scope::elem_b (String s) const
66 {
67   return id_dict_->elem_b (ly_symbol2scm (s.ch_C()));
68 }
69
70
71 Identifier *&
72 Scope::elem (String s) 
73 {
74   return id_dict_->elem (ly_symbol2scm (s.ch_C()));
75 }
76
77
78 Scope_iter::Scope_iter (Scope const &s)
79 {
80   iter_ = new Hash_table_iter<Protected_scm,Identifier*>(*s.id_dict_);
81 }
82
83 String
84 Scope_iter::key () const
85 {
86   SCM s= iter_->key ();
87   return ly_symbol2string (s);
88 }
89
90 bool
91 Scope::elem_b (SCM s) const
92 {
93   return id_dict_->elem_b (s);
94 }
95
96 Identifier* &
97 Scope::elem (SCM s)
98 {
99   return id_dict_->elem (s);
100 }
101
102 SCM
103 Scope_iter::scm_key () const
104 {
105   return iter_->key ();
106 }
107
108 bool
109 Scope_iter::ok () const
110 {
111   return iter_->ok();
112 }
113
114 void
115 Scope_iter::operator ++(int)
116 {
117   (*iter_) ++;
118 }
119
120 Identifier*
121 Scope_iter::val ()const
122 {
123   return iter_->val ();
124 }