]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4541 (1/2) Introduce a Grob_interface class
authorDan Eble <nine.fierce.ballads@gmail.com>
Fri, 24 Jul 2015 17:22:42 +0000 (13:22 -0400)
committerDan Eble <nine.fierce.ballads@gmail.com>
Fri, 14 Aug 2015 21:21:18 +0000 (17:21 -0400)
Add Grob_interface and make some changes in preparation for a large
automated replacement.

lily/axis-group-interface.cc
lily/include/grob-interface.hh
lily/include/grob.hh
lily/note-column.cc

index 4aad5860c7de2e5d9a1d4a0233c8819edfb1ceea..09f6ab471be1d31cd94f26cd236a0e56e515184d 100644 (file)
@@ -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);
index fc9e58c4a28c3b3d53f0a2143f5d31cd910c2db1..8590373a0ab7d2b58601396b081737b5640f4272 100644 (file)
 
 #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 */
 
index 8b2c4249ea8d91ce8781f44e46538b55308e5cb1..5ef37227662f5d6de3601dff4a42f42548dc9265 100644 (file)
@@ -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 *> &);
 
index f5b6f35e9045189b6ba5f88118cefc522b7100cf..a5da30a8c7926214df6982f11f75ac639338f009 100644 (file)
@@ -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");