diff options
author | Dan Eble <nine.fierce.ballads@gmail.com> | 2015-07-24 13:22:42 -0400 |
---|---|---|
committer | Dan Eble <nine.fierce.ballads@gmail.com> | 2015-08-14 17:21:18 -0400 |
commit | e14a171e46de06072e82513b62632bbeaa987a26 (patch) | |
tree | bd5bf9e68b06481c34bc62e0fa84499cfd8ab4b4 | |
parent | ef18cc27b8103c2f1ce50924ecf55b66fa6b746a (diff) |
Issue 4541 (1/2) Introduce a Grob_interface class
Add Grob_interface and make some changes in preparation for a large
automated replacement.
-rw-r--r-- | lily/axis-group-interface.cc | 4 | ||||
-rw-r--r-- | lily/include/grob-interface.hh | 51 | ||||
-rw-r--r-- | lily/include/grob.hh | 6 | ||||
-rw-r--r-- | lily/note-column.cc | 2 |
4 files changed, 49 insertions, 14 deletions
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<Grob *> 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<Grob *> *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> cl ## _interface_initializer; \ + template <> char const *Grob_interface<cl>::cxx_name_ (#cl); \ + template <> char const *Grob_interface<cl>::description_ (b); \ + template <> char const *Grob_interface<cl>::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<cl> (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 Interface> +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 <class T> + friend bool has_interface(Grob *); + +private: + static SCM interface_symbol_; + static char const *cxx_name_; + static char const *description_; + static char const *variables_; +}; + +template <class Interface> +SCM Grob_interface<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 <class T> +inline bool has_interface(Grob *g) +{ + return g && g->internal_has_interface (Grob_interface<T>::interface_symbol_); +} + /* unification */ void uniquify (vector <Grob *> &); 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"); |