lilypond-0.1.35
[lilypond.git] / lily / input-translator.cc
blobff277cc672cf4fe94d2821ac08b490c9492e5e5e
1 /*
2 input-translator.cc -- implement Input_translator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "debug.hh"
10 #include "engraver.hh"
11 #include "input-translator.hh"
12 #include "parray.hh"
13 #include "input-translator.hh"
14 #include "engraver-group.hh"
15 #include "performer-group-performer.hh"
17 bool
18 Input_translator::is_name_b (String n)
20 for (int i=0; i < alias_str_arr_.size(); i++)
21 if (alias_str_arr_[i] == n)
22 return true;
23 return false;
26 void
27 Input_translator::print() const
29 #ifndef NPRINT
30 if (! check_debug)
31 return ;
32 DOUT << base_str_ <<" " << type_str_<<" {\n";
33 DOUT << "Consists of ";
34 for (int i=0; i< consists_str_arr_.size(); i++)
35 DOUT << consists_str_arr_[i] << ',';
36 if (contains_itrans_p_list_.size())
37 DOUT << "\nContains " ;
38 for (PCursor<Input_translator*> i (contains_itrans_p_list_.top()); i.ok (); i++)
39 i->print();
40 DOUT << "}\n";
41 #endif
46 Input_translator *
47 Input_translator::recursive_find (String nm)
49 if (is_name_b (nm))
50 return this;
52 Input_translator * r =0;
53 // what bout for() ?
54 PCursor<Input_translator*> i (contains_itrans_p_list_.top());
55 for (; !r &&i.ok(); i++)
57 if (i->recursive_find (nm))
58 r = i.ptr();
61 return r;
64 Input_translator *
65 Input_translator::find_itrans_l (String nm)
67 for (PCursor<Input_translator*> i (contains_itrans_p_list_.top()); i.ok (); i++)
68 if (i->is_name_b (nm))
69 return i;
71 return 0;
75 Engraver_group_engraver *
76 Input_translator::get_group_engraver_p()
78 assert (base_str_ == "Engraver");
79 Engraver_group_engraver * grav_p = (Engraver_group_engraver*)
80 get_engraver_p (type_str_);
82 for (int i=0; i < consists_str_arr_.size(); i++)
84 grav_p->add (get_engraver_p (consists_str_arr_[i]));
86 grav_p->itrans_l_ = this;
87 grav_p->id_str_ = default_id_str_;
88 return grav_p;
91 Performer_group_performer*
92 Input_translator::get_group_performer_p()
94 assert (base_str_ == "Performer");
95 Performer_group_performer * perf_p = (Performer_group_performer*)
96 get_performer_p (type_str_);
98 for (int i=0; i < consists_str_arr_.size(); i++)
100 perf_p->add (get_performer_p (consists_str_arr_[i]));
102 perf_p->itrans_l_ = this;
103 perf_p->id_str_ = default_id_str_;
104 return perf_p;
107 bool
108 Input_translator::accept_req_b()
110 return ! contains_itrans_p_list_.size();
113 void
114 Input_translator::add (Input_translator *ip)
116 contains_itrans_p_list_.bottom().add (ip);
119 Input_translator*
120 Input_translator::get_default_itrans_l()
122 if (contains_itrans_p_list_.size())
123 return contains_itrans_p_list_.top();
124 else
125 return 0;
129 Input_translator_list::Input_translator_list (Input_translator_list const &s)
131 for (PCursor<Input_translator*> pc (s); pc.ok(); pc++)
133 Input_translator *q = pc;
134 Input_translator *p=new Input_translator (*q) ;
135 bottom().add (p);