From: Dan Eble Date: Fri, 24 Jul 2015 17:22:42 +0000 (-0400) Subject: Issue 4541 (1/2) Introduce a Grob_interface class X-Git-Tag: release/2.19.26-1~49 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e14a171e46de06072e82513b62632bbeaa987a26;p=lilypond.git Issue 4541 (1/2) Introduce a Grob_interface class Add Grob_interface and make some changes in preparation for a large automated replacement. --- diff --git a/lily/axis-group-interface.cc b/lily/axis-group-interface.cc index 4aad5860c7..09f6ab471b 100644 --- a/lily/axis-group-interface.cc +++ b/lily/axis-group-interface.cc @@ -101,7 +101,7 @@ Axis_group_interface::relative_maybe_bound_group_extent (vector const &e Grob *se = elts[i]; if (!to_boolean (se->get_property ("cross-staff"))) { - Interval dims = (bound && has_interface (se) + Interval dims = (bound && Axis_group_interface::has_interface (se) ? generic_bound_extent (se, common, a) : se->extent (common, a)); if (!dims.is_empty ()) @@ -599,7 +599,7 @@ Axis_group_interface::get_children (Grob *me, vector *found) { found->push_back (me); - if (!has_interface (me)) + if (!Axis_group_interface::has_interface (me)) return; extract_grob_set (me, "elements", elements); diff --git a/lily/include/grob-interface.hh b/lily/include/grob-interface.hh index fc9e58c4a2..8590373a0a 100644 --- a/lily/include/grob-interface.hh +++ b/lily/include/grob-interface.hh @@ -22,21 +22,22 @@ #include "lily-guile.hh" +class Grob; + +// TODO: remove DECLARE_GROB_INTERFACE #define DECLARE_GROB_INTERFACE() \ - static SCM interface_symbol_; \ - static bool has_interface (Grob*) + static bool has_interface (Grob *g) -#define ADD_INTERFACE(cl, b, c) \ - SCM cl::interface_symbol_; \ +// TODO: remove cl::has_interface and use ::has_interface directly +#define ADD_INTERFACE(cl, b, c) \ + Grob_interface cl ## _interface_initializer; \ + template <> char const *Grob_interface::cxx_name_ (#cl); \ + template <> char const *Grob_interface::description_ (b); \ + template <> char const *Grob_interface::variables_ (c); \ bool cl::has_interface (Grob *me) \ { \ - return me->internal_has_interface (interface_symbol_); \ - } \ - void cl ## _init_ifaces () \ - { \ - cl::interface_symbol_ = add_interface (#cl, b, c); \ - } \ - ADD_SCM_INIT_FUNC (cl ## ifaces, cl ## _init_ifaces); + return ::has_interface (me); \ + } SCM add_interface (char const *cxx_name, char const *descr, @@ -46,5 +47,33 @@ SCM ly_add_interface (SCM, SCM, SCM); void internal_add_interface (SCM, SCM, SCM); SCM ly_all_grob_interfaces (); +template +class Grob_interface +{ +public: + Grob_interface () + { + add_scm_init_func (Grob_interface::init); + } + +private: + static void init () + { + interface_symbol_ = ::add_interface (cxx_name_, description_, variables_); + } + + template + friend bool has_interface(Grob *); + +private: + static SCM interface_symbol_; + static char const *cxx_name_; + static char const *description_; + static char const *variables_; +}; + +template +SCM Grob_interface::interface_symbol_; + #endif /* INTERFACE_HH */ diff --git a/lily/include/grob.hh b/lily/include/grob.hh index 8b2c4249ea..5ef3722766 100644 --- a/lily/include/grob.hh +++ b/lily/include/grob.hh @@ -175,6 +175,12 @@ public: static SCM internal_skylines_from_element_stencils (SCM, Axis); }; +template +inline bool has_interface(Grob *g) +{ + return g && g->internal_has_interface (Grob_interface::interface_symbol_); +} + /* unification */ void uniquify (vector &); diff --git a/lily/note-column.cc b/lily/note-column.cc index f5b6f35e90..a5da30a8c7 100644 --- a/lily/note-column.cc +++ b/lily/note-column.cc @@ -107,7 +107,7 @@ Note_column::dir (Grob *me) return (Direction)sign (head_positions_interval (me).center ()); } - if (has_interface (me)) + if (Note_column::has_interface (me)) programming_error ("Note_column without heads and stem"); else programming_error ("dir() given grob without Note_column interface");