lilypond-1.3.12
[lilypond.git] / lily / register-group.cc
blob5812b2fb04252092b76997d6f5c0db2c6d242747
1 /*
2 registergroup.cc -- implement Register_group_register
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "proto.hh"
10 #include "plist.hh"
11 #include "register-group.hh"
12 #include "register.hh"
13 #include "debug.hh"
14 #include "p-score.hh"
15 #include "score-elem.hh"
16 #include "input-register.hh"
18 Register_group_register::~Register_group_register()
20 assert(removable_b());
23 void
24 Register_group_register::check_removal()
26 for (int i =0; i < group_l_arr_.size(); ) {
27 group_l_arr_[i]->check_removal();
28 if (group_l_arr_[i]->removable_b())
29 terminate_register(group_l_arr_[i]);
30 else
31 i++;
36 bool
37 Register_group_register::removable_b()const
39 return !iterator_count_&& !group_l_arr_.size() ;
42 Register_group_register::Register_group_register()
44 ireg_l_ =0;
47 void
48 Register_group_register::set_feature(Feature d)
50 iter_top(reg_list_, i);
51 while (i.ok()) {
52 // this construction to ensure clean deletion
53 Request_register *reg_l = i++;
54 reg_l->set_feature(d);
58 void
59 Register_group_register::sync_features()
61 iter_top(reg_list_, i);
62 while (i.ok()) {
64 Request_register *reg_l = i++;
65 reg_l->sync_features();
69 void
70 Register_group_register::do_pre_move_processing()
72 iter_top(reg_list_, i);
73 while (i.ok()) {
75 Request_register *reg_l = i++;
76 reg_l->pre_move_processing();
80 void
81 Register_group_register::do_process_requests()
83 iter_top(reg_list_, i);
84 while (i.ok()) {
86 Request_register *reg_l = i++;
87 reg_l->process_requests();
92 void
93 Register_group_register::do_post_move_processing()
95 iter_top(reg_list_, i);
96 while (i.ok()) {
97 // this construction to ensure clean deletion
98 Request_register *reg_l = i++;
99 reg_l->post_move_processing();
104 bool
105 Register_group_register::contains_b(Request_register* reg_l)const
107 bool parent_b = Request_register::contains_b(reg_l);
109 if (parent_b)
110 return true;
111 for (iter_top(reg_list_, j); j.ok(); j++)
112 if (j->contains_b(reg_l))
113 return true;
114 return false;
119 bool
120 Register_group_register::do_try_request(Request*req_l)
122 bool hebbes_b =false;
123 for (int i =0; !hebbes_b && i < nongroup_l_arr_.size() ; i++)
124 hebbes_b =nongroup_l_arr_[i]->try_request(req_l);
125 if (!hebbes_b)
126 hebbes_b = daddy_reg_l_->try_request(req_l);
127 return hebbes_b ;
130 void
131 Register_group_register::add(Request_register *reg_p)
133 reg_list_.bottom().add(reg_p);
134 reg_p->daddy_reg_l_ = this;
136 if (reg_p->is_type_b(Register_group_register::static_name())) {
137 group_l_arr_.push((Register_group_register*)reg_p);
138 } else {
139 nongroup_l_arr_ .push(reg_p);
144 Request_register *
145 Register_group_register::remove_register_p(Request_register*reg_l)
147 group_l_arr_.substitute((Register_group_register*)reg_l,0);
148 nongroup_l_arr_.substitute(reg_l,0);
149 iterator(reg_list_) reg_cur= reg_list_.find(reg_l);
151 return reg_cur.remove_p();
154 void
155 Register_group_register::terminate_register(Request_register*r_l)
157 mtor << "Removing " << r_l->name() << " at " << get_staff_info().when() << "\n";
158 r_l->do_removal_processing();
159 Request_register * reg_p =remove_register_p(r_l);
161 delete reg_p;
164 IMPLEMENT_IS_TYPE_B2(Register_group_register,Request_register, Acceptor);
165 IMPLEMENT_STATIC_NAME(Register_group_register);
166 ADD_THIS_REGISTER(Register_group_register);
168 void
169 Register_group_register::do_print()const
171 #ifndef NPRINT
172 mtor << "ID: " << id_str_ << "\n";
173 for (iter_top(reg_list_, i); i.ok(); i++)
174 i->print();
175 #endif
179 Register_group_register*
180 Register_group_register::find_register_l(String n, String id)
182 if (name() == n && id_str_ == id)
183 return this;
184 Register_group_register * r = 0;
185 for (int i =0; !r && i< group_l_arr_.size(); i++) {
186 r = group_l_arr_[i]->find_register_l(n,id);
189 return r;
192 Acceptor*
193 Register_group_register::find_get_acceptor_l(String n,String id)
195 Acceptor * ret=0;
196 Input_register * ireg_l= ireg_l_-> recursive_find ( n );
197 if (ireg_l ) {
198 ret = find_register_l(n,id);
199 if (!ret) {
200 Register_group_register * group =
201 ireg_l-> get_group_register_p();
203 add(group);
204 ret = group;
206 if (group->ireg_l_->is_name_b( n ) )
207 ret ->id_str_ = id;
208 else
209 return ret->find_get_acceptor_l(n,id);
212 } else if (daddy_reg_l_)
213 ret =daddy_reg_l_->find_get_acceptor_l(n,id);
214 else {
215 warning("Can't find or create `" + n + "' called `" + id + "'\n");
216 ret =0;
218 return ret;
222 Register_group_register::depth_i()const
224 return daddy_reg_l_->depth_i() + 1;
227 Acceptor*
228 Register_group_register::ancestor_l(int l)
230 if (!l || !daddy_reg_l_)
231 return this;
233 return daddy_reg_l_->ancestor_l(l-1);
236 void
237 Register_group_register::announce_element(Score_elem_info info)
239 announce_info_arr_.push(info);
240 Request_register::announce_element(info);
243 void
244 Register_group_register::do_announces()
246 for (int i=0; i < group_l_arr_.size(); i++) {
247 group_l_arr_[i]->do_announces();
250 Request dummy_req;
252 for (int j =0; j < announce_info_arr_.size(); j++){
253 Score_elem_info info = announce_info_arr_[j];
255 if (!info.req_l_)
256 info.req_l_ = &dummy_req;
257 for (int i=0; i < nongroup_l_arr_.size(); i++) {
258 if (nongroup_l_arr_[i] != info.origin_reg_l_arr_[0])
259 nongroup_l_arr_[i]->acknowledge_element(info);
262 announce_info_arr_.set_size(0);
266 void
267 Register_group_register::do_removal_processing()
269 for (iter( reg_list_.top(), i); i.ok(); i++)
270 i->do_removal_processing();
273 Staff_info
274 Register_group_register::get_staff_info()const
276 Staff_info inf = Request_register::get_staff_info();
278 for (int i=0; i < nongroup_l_arr_.size(); i++)
279 nongroup_l_arr_[i]->fill_staff_info(inf);
281 return inf;
284 Acceptor*
285 Register_group_register::get_default_interpreter()
287 if ( interpreter_l() )
288 return daddy_reg_l_->get_default_interpreter();
290 Register_group_register *reg_p= ireg_l_->
291 get_default_ireg_l()->get_group_register_p();
292 add(reg_p );
293 if (reg_p->interpreter_l())
294 return reg_p;
295 else
296 return reg_p->get_default_interpreter();