]> git.donarmstrong.com Git - lilypond.git/blob - lily/translator-dispatch-list.cc
4faac7116781bd08bf7abe3e83ca7042c62fc474
[lilypond.git] / lily / translator-dispatch-list.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "translator-dispatch-list.hh"
21 #include "engraver.hh"
22
23
24 void
25 Engraver_dispatch_list::apply (Grob_info gi)
26 {
27   Translator *origin = gi.origin_translator ();
28   for (vsize i = 0; i < dispatch_entries_.size (); i++)
29     {
30       Engraver_dispatch_entry const &e (dispatch_entries_[i]);
31       if (e.engraver_ == origin)
32         continue;
33
34       (e.engraver_->*e.function_) (gi);
35     }
36 }
37
38 SCM
39 Engraver_dispatch_list::create (SCM trans_list,
40                                 SCM iface_list, Direction start_end)
41 {
42   SCM retval = Engraver_dispatch_list ().smobbed_copy ();
43   Engraver_dispatch_list *list = Engraver_dispatch_list::unsmob (retval);
44
45   Engraver_dispatch_entry entry;
46   bool found = false;
47   for (SCM s = trans_list; scm_is_pair (s); s = scm_cdr (s))
48     {
49       Engraver *eng
50         = dynamic_cast<Engraver *> (Translator::unsmob (scm_car (s)));
51
52       if (!eng)
53         continue;
54
55       entry.engraver_ = eng;
56       for (SCM i = iface_list; scm_is_pair (i); i = scm_cdr (i))
57         {
58           Engraver_void_function_engraver_grob_info ptr
59             = (start_end == START)
60               ? eng->get_acknowledger (scm_car (i))
61               : eng->get_end_acknowledger (scm_car (i));
62
63           if (ptr)
64             {
65               entry.function_ = ptr;
66               list->dispatch_entries_.push_back (entry);
67               found = true;
68             }
69         }
70     }
71
72   return found ? retval : SCM_EOL;
73 }