]> git.donarmstrong.com Git - lilypond.git/blob - lily/scope.cc
release: 1.3.56
[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
18 Scope::~Scope ()
19 {
20   for (Scope_iter ai (*this); ai.ok(); ai++)
21     delete ai.val ();
22   delete id_dict_;
23 }
24
25 Scope::Scope (Scope const&s)
26 {
27   id_dict_ = new Hash_table<Protected_scm,Identifier*> (*s.id_dict_);
28   for (Scope_iter ai (s); ai.ok(); ai++)
29     {
30       id_dict_->elem (ai.scm_key ()) = ai.val ()->clone ();
31     }
32 }
33
34 unsigned int ly_pscm_hash (Protected_scm s)
35 {
36   return ly_scm_hash (s);
37 }
38
39
40 Scope::Scope ()
41 {
42   id_dict_ = new Hash_table<Protected_scm,Identifier*>;
43   id_dict_->hash_func_ = ly_pscm_hash;
44 }
45
46 bool
47 Scope::elem_b (String s) const
48 {
49   return id_dict_->elem_b (ly_symbol2scm (s.ch_C()));
50 }
51
52
53 Identifier *&
54 Scope::elem (String s) 
55 {
56   return id_dict_->elem (ly_symbol2scm (s.ch_C()));
57 }
58
59
60 Scope_iter::Scope_iter (Scope const &s)
61 {
62   iter_ = new Hash_table_iter<Protected_scm,Identifier*>(*s.id_dict_);
63 }
64
65 String
66 Scope_iter::key () const
67 {
68   SCM s= iter_->key ();
69   return ly_symbol2string (s);
70 }
71
72 bool
73 Scope::elem_b (SCM s) const
74 {
75   return id_dict_->elem_b (s);
76 }
77
78 Identifier* &
79 Scope::elem (SCM s)
80 {
81   return id_dict_->elem (s);
82 }
83
84 SCM
85 Scope_iter::scm_key () const
86 {
87   return iter_->key ();
88 }
89
90 bool
91 Scope_iter::ok () const
92 {
93   return iter_->ok();
94 }
95
96 void
97 Scope_iter::operator ++(int)
98 {
99   (*iter_) ++;
100 }
101
102 Identifier*
103 Scope_iter::val ()const
104 {
105   return iter_->val ();
106 }