]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/include/grob-interface.hh
Issue 4541 (1/2) Introduce a Grob_interface class
[lilypond.git] / lily / include / grob-interface.hh
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 */