]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-interface.cc
Issue 4550 (2/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / grob-interface.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2002--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 "grob-interface.hh"
21
22 #include "grob.hh"
23 #include "international.hh"
24 #include "protected-scm.hh"
25 #include "string-convert.hh"
26 #include "warn.hh"
27 #include "misc.hh"
28
29 using std::string;
30
31 SCM add_interface (char const *cxx_name,
32                    char const *descr,
33                    char const *vars)
34 {
35   string suffix ("-interface");
36   string lispy_name = camel_case_to_lisp_identifier (cxx_name);
37   vsize end = std::max (int (0), int (lispy_name.length () - suffix.length ()));
38   if (lispy_name.substr (end) != suffix)
39     lispy_name += suffix;
40
41   SCM s = ly_symbol2scm (lispy_name.c_str ());
42   SCM d = scm_from_utf8_string (descr);
43   SCM l = parse_symbol_list (vars);
44
45   internal_add_interface (s, d, l);
46
47   return s;
48 }
49
50 void
51 check_interfaces_for_property (Grob const *me, SCM sym)
52 {
53   if (scm_is_eq (sym, ly_symbol2scm ("meta")))
54     {
55       /*
56         otherwise we get in a nasty recursion loop.
57       */
58       return;
59     }
60
61   SCM ifs = me->interfaces ();
62
63   SCM all_ifaces = ly_all_grob_interfaces ();
64   bool found = false;
65   for (; !found && scm_is_pair (ifs); ifs = scm_cdr (ifs))
66     {
67       SCM iface = scm_hashq_ref (all_ifaces, scm_car (ifs), SCM_BOOL_F);
68       if (scm_is_false (iface))
69         {
70           string msg = to_string (_f ("Unknown interface `%s'",
71                                       ly_symbol2string (scm_car (ifs)).c_str ()));
72           programming_error (msg);
73           continue;
74         }
75
76       found = found || scm_is_true (scm_c_memq (sym, scm_caddr (iface)));
77     }
78
79   if (!found)
80     {
81       string str = to_string (_f ("Grob `%s' has no interface for property `%s'",
82                                   me->name ().c_str (),
83                                   ly_symbol2string (sym).c_str ()));
84       programming_error (str);
85     }
86 }