2 grob-interface.cc -- implement graphic objects interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "protected-scm.hh"
10 #include "grob-interface.hh"
11 #include "lily-guile.hh"
15 Protected_scm all_ifaces
;
17 void add_interface (const char * symbol
,
21 SCM s
= ly_symbol2scm (symbol
);
22 SCM d
= scm_makfrom0str (descr
);
23 SCM l
= parse_symbol_list (vars
);
25 ly_add_interface (s
,d
,l
);
29 LY_DEFINE (ly_add_interface
, "ly:add-interface", 3,0,0, (SCM a
, SCM b
, SCM c
),
30 "Add an interface description.")
32 SCM_ASSERT_TYPE (ly_c_symbol_p (a
), a
, SCM_ARG1
, __FUNCTION__
, "symbol");
33 SCM_ASSERT_TYPE (ly_c_string_p (b
), b
, SCM_ARG2
, __FUNCTION__
, "string");
34 SCM_ASSERT_TYPE (ly_c_list_p (c
), c
, SCM_ARG3
, __FUNCTION__
, "list of syms");
35 if (!ly_c_vector_p (all_ifaces
))
36 all_ifaces
= scm_make_vector (scm_int2num (40), SCM_EOL
);
38 SCM entry
= scm_list_n (a
, b
, c
, SCM_UNDEFINED
);
40 scm_hashq_set_x (all_ifaces
, a
, entry
);
42 return SCM_UNSPECIFIED
;
46 LY_DEFINE (ly_all_grob_interfaces
, "ly:all-grob-interfaces",
48 "Get a hash table with all interface descriptions.")
55 check_interfaces_for_property (Grob
const *me
, SCM sym
)
57 if (sym
== ly_symbol2scm ("meta"))
60 otherwise we get in a nasty recursion loop.
65 SCM ifs
= me
->get_property ("interfaces");
68 for (; !found
&& ly_c_pair_p (ifs
); ifs
=ly_cdr (ifs
))
70 SCM iface
= scm_hashq_ref (all_ifaces
, ly_car (ifs
), SCM_BOOL_F
);
71 if (iface
== SCM_BOOL_F
)
73 String msg
= to_string (_f ("Unknown interface `%s'",
74 ly_symbol2string (ly_car (ifs
)).to_str0 ()));
75 programming_error (msg
);
79 found
= found
|| (scm_c_memq (sym
, ly_caddr (iface
)) != SCM_BOOL_F
);
84 String str
= to_string (_f ("Grob `%s' has no interface for property `%s'",
85 me
->name ().to_str0 (),
86 ly_symbol2string (sym
).to_str0 ()));
87 programming_error (str
);