]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-interface.cc
Merge branch 'master' of ssh+git://hanwen@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / lily / grob-interface.cc
1 /*
2   grob-interface.cc -- implement graphic objects interface
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2002--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "grob-interface.hh"
10
11 #include "grob.hh"
12 #include "international.hh"
13 #include "protected-scm.hh"
14 #include "std-string.hh"
15 #include "string-convert.hh"
16 #include "warn.hh"
17 #include "misc.hh"
18
19 SCM add_interface (char const *cxx_name,
20                     char const *descr,
21                     char const *vars)
22 {
23   string suffix ("-interface");
24   string lispy_name = camel_case_to_lisp_identifier (cxx_name);
25   vsize end = max (int (0), int (lispy_name.length () - suffix.length ()));
26   if (lispy_name.substr (end) != suffix)
27     lispy_name += suffix;
28
29   SCM s = ly_symbol2scm (lispy_name.c_str ());
30   SCM d = scm_makfrom0str (descr);
31   SCM l = parse_symbol_list (vars);
32
33   ly_add_interface (s, d, l);
34
35   return s;
36 }
37
38 void
39 check_interfaces_for_property (Grob const *me, SCM sym)
40 {
41   if (sym == ly_symbol2scm ("meta"))
42     {
43       /*
44         otherwise we get in a nasty recursion loop.
45       */
46       return;
47     }
48
49   SCM ifs = me->interfaces ();
50
51   SCM all_ifaces = ly_all_grob_interfaces ();
52   bool found = false;
53   for (; !found && scm_is_pair (ifs); ifs = scm_cdr (ifs))
54     {
55       SCM iface = scm_hashq_ref (all_ifaces, scm_car (ifs), SCM_BOOL_F);
56       if (iface == SCM_BOOL_F)
57         {
58           string msg = to_string (_f ("Unknown interface `%s'",
59                                       ly_symbol2string (scm_car (ifs)).c_str ()));
60           programming_error (msg);
61           continue;
62         }
63
64       found = found || (scm_c_memq (sym, scm_caddr (iface)) != SCM_BOOL_F);
65     }
66
67   if (!found)
68     {
69       string str = to_string (_f ("Grob `%s' has no interface for property `%s'",
70                                   me->name ().c_str (),
71                                   ly_symbol2string (sym).c_str ()));
72       programming_error (str);
73     }
74 }