lilypond-1.3.28
[lilypond.git] / lily / scope.cc
blobe2923fcb80bfa68ca954be7c6a01235d483ffb5f
1 /*
2 scope.cc -- implement Scope
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
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"
17 void
18 Scope::print () const
20 #ifndef NPRINT
21 bool init_b = false; // ugh
22 for (Scope_iter ai (*this); ai.ok(); ai++)
24 if (ai.val()->init_b_ == init_b)
26 DEBUG_OUT << ai.key() << "=";
27 ai.val()->print ();
30 #endif
33 Scope::~Scope ()
35 for (Scope_iter ai (*this); ai.ok(); ai++)
37 DEBUG_OUT << "deleting: " << ai.key() << '\n';
38 delete ai.val ();
40 delete id_dict_;
43 Scope::Scope (Scope const&s)
45 id_dict_ = new Hash_table<Protected_scm,Identifier*> (*s.id_dict_);
46 for (Scope_iter ai (s); ai.ok(); ai++)
48 id_dict_->elem (ai.scm_key ()) = ai.val ()->clone ();
52 unsigned int ly_pscm_hash (Protected_scm s)
54 return ly_scm_hash (s);
58 Scope::Scope ()
60 id_dict_ = new Hash_table<Protected_scm,Identifier*>;
61 id_dict_->hash_func_ = ly_pscm_hash;
64 bool
65 Scope::elem_b (String s) const
67 return id_dict_->elem_b (ly_symbol2scm (s.ch_C()));
71 Identifier *&
72 Scope::elem (String s)
74 return id_dict_->elem (ly_symbol2scm (s.ch_C()));
78 Scope_iter::Scope_iter (Scope const &s)
80 iter_ = new Hash_table_iter<Protected_scm,Identifier*>(*s.id_dict_);
83 String
84 Scope_iter::key () const
86 SCM s= iter_->key ();
87 return ly_symbol2string (s);
90 bool
91 Scope::elem_b (SCM s) const
93 return id_dict_->elem_b (s);
96 Identifier* &
97 Scope::elem (SCM s)
99 return id_dict_->elem (s);
103 Scope_iter::scm_key () const
105 return iter_->key ();
108 bool
109 Scope_iter::ok () const
111 return iter_->ok();
114 void
115 Scope_iter::operator ++(int)
117 (*iter_) ++;
120 Identifier*
121 Scope_iter::val ()const
123 return iter_->val ();