]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/include/translator.icc
Issue 1375/2: Create Translator_creator class
[lilypond.git] / lily / include / translator.icc
index 20954ead0b6b1c670783ac07a8697421d55f0c6c..9bd6163fea45eec75a60c3cbdb8682517ba50caf 100644 (file)
    A macro to automate administration of translators.
 */
 #define ADD_THIS_TRANSLATOR(T)                                          \
-  SCM T::static_description_ = SCM_EOL;                                 \
   static void _ ## T ## _adder ()                                       \
   {                                                                     \
     T::boot ();                                                         \
-    T *t = new T(0);                                                    \
-    T::static_description_ =                                            \
-      scm_permanent_object (t->static_translator_description ());       \
-    add_translator (t);                                                 \
-  }                                                                     \
-  SCM T::translator_description () const                                \
-  {                                                                     \
-    return static_description_;                                         \
+    add_translator_creator (Translator_creator::alloc<T>()->unprotect (), \
+                            scm_from_ascii_symbol (#T),                 \
+                            T::static_translator_description ());       \
   }                                                                     \
   ADD_GLOBAL_CTOR (_ ## T ## _adder);                                   \
   /* end define */
 
-#define DEFINE_TRANSLATOR_LISTENER_LIST(T) \
-  Protected_scm T::listener_list_ (SCM_EOL)
+#define DEFINE_TRANSLATOR_LISTENER_LIST(T)                              \
+  Protected_scm T::listener_list_ (SCM_EOL);                            \
+  /* end define */
 
 #define DEFINE_ACKNOWLEDGERS(classname) \
   Drul_array<Protected_scm> classname::acknowledge_static_array_drul_;  \
@@ -61,9 +56,9 @@
   }                                                                     \
   /* end define */
 
-#define DEFINE_TRANSLATOR_DOC(classname, desc, grobs, read, write)              \
+#define DEFINE_TRANSLATOR_DOC(classname, desc, grobs, read, write)      \
   SCM                                                                   \
-  classname::static_translator_description () const                     \
+  classname::static_translator_description ()                           \
   {                                                                     \
     return Translator::static_translator_description (grobs, desc, listener_list_, read, write); \
   }
   {                                                                     \
     ptrs[START_TRANSLATION_TIMESTEP] =                                  \
       method_finder <&T::start_translation_timestep> ();                \
-                                                                       \
-    ptrs[STOP_TRANSLATION_TIMESTEP] =                                  \
+                                                                        \
+    ptrs[STOP_TRANSLATION_TIMESTEP] =                                   \
       method_finder <&T::stop_translation_timestep> ();                 \
                                                                         \
-    ptrs[PROCESS_MUSIC] =                                              \
+    ptrs[PROCESS_MUSIC] =                                               \
       method_finder <&T::process_music> ();                             \
-                                                                       \
-    ptrs[PROCESS_ACKNOWLEDGED] =                                       \
+                                                                        \
+    ptrs[PROCESS_ACKNOWLEDGED] =                                        \
       method_finder <&T::process_acknowledged> ();                      \
   }
 
@@ -115,6 +110,11 @@ void add_acknowledger (SCM ptr,
 /*
   Implement the method cl::listen_##m, and make it listen to stream
   events of class m.
+
+  At macro call time, neither creator instances (which are anonymous
+  and only accessible via the translator registry) nor translator
+  instances exist, so the only named place where we can store it is in
+  a static member of the translator class.
  */
 #define ADD_LISTENER_FOR(cl, m, ev)                                     \
   listener_list_ = scm_acons                                            \