]> git.donarmstrong.com Git - lilypond.git/blob - lily/change-iterator.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / change-iterator.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 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 "change-iterator.hh"
21
22 #include "context.hh"
23 #include "input.hh"
24 #include "international.hh"
25 #include "music.hh"
26 #include "warn.hh"
27
28 using std::string;
29
30 void
31 Change_iterator::error (const string &reason)
32 {
33   string to_type = ly_symbol2string (get_music ()->get_property ("change-to-type"));
34   string to_id = ly_scm2string (get_music ()->get_property ("change-to-id"));
35
36   string warn1 = _f ("cannot change `%s' to `%s'", to_type, to_id)
37                  + ": " + reason;
38
39   /*
40     GUHG!
41   */
42   string warn2 = "Change_iterator::process (): "
43                  + get_outlet ()->context_name () + " = `"
44                  + get_outlet ()->id_string () + "': ";
45   warning (warn2);
46   get_music ()->origin ()->warning (warn1);
47 }
48
49 string
50 Change_iterator::change_to (Music_iterator &it,
51                             SCM to_type,
52                             const string &to_id)
53 {
54   string result; // error message
55
56   // Find the context that should have its parent changed.
57   Context *last = find_context_above_by_parent_type (it.get_outlet (), to_type);
58   if (last)
59     {
60       // Find the new parent.
61       Context *dest = find_context_near (it.get_outlet (), to_type, to_id);
62       if (dest)
63         {
64           send_stream_event (last, "ChangeParent", it.get_music ()->origin (),
65                              ly_symbol2scm ("context"), dest->self_scm ());
66         }
67       else
68         /* FIXME: constant error message.  */
69         it.get_music ()->origin ()->warning (_ ("cannot find context to switch to"));
70     }
71   else if (it.get_outlet ()->is_alias (to_type))
72     {
73       // No enclosing context was found because the iterator's immediate
74       // context is the kind that was sought.
75       /* We could change the current translator's id, but that would make
76          errors hard to catch.
77
78          last->translator_id_string () = get_change
79          ()->change_to_id_string (); */
80       result = _f ("not changing to same context type: %s", ly_symbol2string (to_type).c_str ());
81     }
82   else
83     /* FIXME: incomprehensible message */
84     result = _ ("none of these in my family");
85
86   return result;
87 }
88
89 /*
90   move to construct_children ?
91 */
92 void
93 Change_iterator::process (Moment m)
94 {
95   SCM to_type = get_music ()->get_property ("change-to-type");
96   string to_id = ly_scm2string (get_music ()->get_property ("change-to-id"));
97
98   string msg = change_to (*this, to_type, to_id);
99   if (!msg.empty ())
100     error (msg);
101
102   Simple_music_iterator::process (m);
103 }
104
105 IMPLEMENT_CTOR_CALLBACK (Change_iterator);