]> git.donarmstrong.com Git - lilypond.git/blob - lily/translator.cc
release: 0.1.61
[lilypond.git] / lily / translator.cc
1 /*
2   translator.cc -- implement Translator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #include "translator.hh"
11 #include "debug.hh"
12 #include "translator-group.hh"
13 #include "dictionary-iter.hh"
14 #include "rational.hh"
15
16 Translator::~Translator ()
17 {
18 }
19
20 Translator::Translator ()
21 {
22   status = ORPHAN;
23   daddy_trans_l_ = 0;
24   output_def_l_ = 0;
25 }
26
27 Translator::Translator (Translator const &s)
28   : Input (s)
29 {
30   status = ORPHAN;
31   daddy_trans_l_ =0;
32   output_def_l_ = s.output_def_l_;
33   properties_dict_ = s.properties_dict_;
34   type_str_ = s.type_str_;
35 }
36
37 bool
38 Translator::is_alias_b (String s) const
39 {
40   return s == type_str_;
41 }
42
43 bool
44 Translator::do_try_request (Request *)
45 {
46   return false;
47 }
48                             
49
50 Moment
51 Translator::now_moment () const
52 {
53   return daddy_trans_l_->now_moment ();
54 }
55
56
57 void
58 Translator::add_processing ()
59 {
60   if (status > ORPHAN)
61     return;
62   
63   do_add_processing ();
64   status = VIRGIN;
65 }
66
67 void
68 Translator::do_add_processing ()
69 {
70 }
71
72 void
73 Translator::print () const
74 {
75 #ifndef NPRINT
76   DOUT << name () << " {";
77   if (name () != type_str_)
78     DOUT << "type = " << type_str_;
79   for (Dictionary_iter<Scalar> i (properties_dict_); i.ok (); i++)
80     {
81       DOUT << i.key () << "=" << i.val () <<"\n";
82     }
83   do_print ();
84   DOUT << "}\n";
85 #endif
86 }
87
88 void
89 Translator::do_print () const
90 {
91 }
92
93 IMPLEMENT_IS_TYPE_B(Translator);
94
95
96 void
97 Translator::creation_processing ()
98 {
99   if (status >= CREATION_INITED)
100     return ;
101   
102   do_creation_processing ();
103   status = CREATION_INITED;
104 }
105
106 void
107 Translator::post_move_processing ()
108 {
109   if (status >= MOVE_INITED)
110     return;
111
112   creation_processing ();
113   do_post_move_processing ();
114   status = MOVE_INITED;
115 }
116
117 void
118 Translator::removal_processing ()
119 {
120   if (status == ORPHAN)
121     return;
122   creation_processing ();
123   do_removal_processing ();
124   // elegancy ...
125   // status = ORPHAN;
126 }
127
128
129 bool
130 Translator::try_request (Request * r)
131 {
132   if (status < MOVE_INITED)
133     post_move_processing ();
134
135   return do_try_request (r);
136 }
137
138 void
139 Translator::process_requests ()
140 {
141   if (status < PROCESSED_REQS)
142     post_move_processing ();
143   else if (status >= PROCESSED_REQS)
144     return; 
145   
146   status = PROCESSED_REQS;
147   do_process_requests ();
148 }
149
150 void
151 Translator::pre_move_processing ()
152 {
153   do_pre_move_processing ();
154   status = CREATION_INITED;
155 }
156
157 Scalar
158 Translator::get_property (String id)
159 {
160   if (properties_dict_.elt_b (id))
161     {
162       return properties_dict_[id];
163     }
164   
165   if (daddy_trans_l_)
166     return daddy_trans_l_->get_property (id);
167
168   return "";
169 }
170
171 void
172 Translator::set_property (String id, Scalar val)
173 {
174   properties_dict_[id] = val;
175 }
176
177
178 Music_output_def *
179 Translator::output_def_l () const
180 {
181   return output_def_l_;
182 }