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