]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-interface.cc
b0a255d58f9f09f97d436afb4b26a3a8b4ad1fff
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "grob-interface.hh"
10
11 #include "protected-scm.hh"
12 #include "grob.hh"
13 #include "warn.hh"
14
15 void add_interface (const char *symbol,
16                     const char *descr,
17                     const char *vars)
18 {
19   SCM s = ly_symbol2scm (symbol);
20   SCM d = scm_makfrom0str (descr);
21   SCM l = parse_symbol_list (vars);
22
23   ly_add_interface (s, d, l);
24 }
25
26 void
27 check_interfaces_for_property (Grob const *me, SCM sym)
28 {
29   if (sym == ly_symbol2scm ("meta"))
30     {
31       /*
32         otherwise we get in a nasty recursion loop.
33       */
34       return;
35     }
36   SCM ifs = me->get_property ("interfaces");
37
38   SCM all_ifaces = ly_all_grob_interfaces ();
39   bool found = false;
40   for (; !found && scm_is_pair (ifs); ifs = scm_cdr (ifs))
41     {
42       SCM iface = scm_hashq_ref (all_ifaces, scm_car (ifs), SCM_BOOL_F);
43       if (iface == SCM_BOOL_F)
44         {
45           String msg = to_string (_f ("Unknown interface `%s'",
46                                       ly_symbol2string (scm_car (ifs)).to_str0 ()));
47           programming_error (msg);
48           continue;
49         }
50
51       found = found || (scm_c_memq (sym, scm_caddr (iface)) != SCM_BOOL_F);
52     }
53
54   if (!found)
55     {
56       String str = to_string (_f ("Grob `%s' has no interface for property `%s'",
57                                   me->name ().to_str0 (),
58                                   ly_symbol2string (sym).to_str0 ()));
59       programming_error (str);
60     }
61 }