]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/translator.icc
ce57a3c4d6ba3705a99a8912ab3911b183534c8a
[lilypond.git] / lily / include / translator.icc
1 /*
2   translator.icc -- declare Translator glue wiring.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #ifndef TRANSLATOR_ICC
11 #define TRANSLATOR_ICC
12
13 /**
14    A macro to automate administration of translators.
15 */
16 #define ADD_THIS_TRANSLATOR(T)                                          \
17   SCM T::static_description_ = SCM_EOL;                                 \
18   static void _ ## T ## _adder ()                                       \
19   {                                                                     \
20     T *t = new T;                                                       \
21     T::static_description_ = t->static_translator_description ();       \
22     scm_permanent_object (T::static_description_);                      \
23     add_translator (t);                                                 \
24   }                                                                     \
25   SCM T::translator_description () const                                \
26   {                                                                     \
27     return static_description_;                                         \
28   }                                                                     \
29   ADD_GLOBAL_CTOR (_ ## T ## _adder);
30
31 #define ADD_TRANSLATOR(classname, desc, grobs, accepted, acked, read, write) \
32   IMPLEMENT_FETCH_PRECOMPUTABLE_METHODS(classname); \
33   ADD_THIS_TRANSLATOR (classname);                                      \
34   SCM                                                                   \
35   classname::static_translator_description () const                     \
36   {                                                                     \
37     SCM static_properties = SCM_EOL;                                    \
38     /*  static_properties = acons (name , gh_str02scm (Translator::name (self_scm ())), \
39         static_properties_);                                            \
40     */                                                                  \
41     static_properties = scm_acons (ly_symbol2scm ("grobs-created"),     \
42                                    parse_symbol_list (grobs), static_properties); \
43                                                                         \
44     static_properties = scm_acons (ly_symbol2scm ("description"),       \
45                                    scm_makfrom0str (desc), static_properties); \
46                                                                         \
47     static_properties = scm_acons (ly_symbol2scm ("interfaces-acked"),  \
48                                    parse_symbol_list (acked), static_properties); \
49     static_properties = scm_acons (ly_symbol2scm ("events-accepted"),   \
50                                    parse_symbol_list (accepted), static_properties); \
51                                                                         \
52     static_properties = scm_acons (ly_symbol2scm ("properties-read"),   \
53                                    parse_symbol_list (read), static_properties); \
54                                                                         \
55     static_properties = scm_acons (ly_symbol2scm ("properties-written"), \
56                                    parse_symbol_list (write), static_properties); \
57                                                                         \
58     return static_properties;                                           \
59   }
60
61 #define IMPLEMENT_FETCH_PRECOMPUTABLE_METHODS(T) \
62 void \
63 T::fetch_precomputable_methods (Translator_void_method_ptr ptrs[])\
64 {                                                                       \
65   ptrs[START_TRANSLATION_TIMESTEP] =                                    \
66     ((Translator_void_method_ptr) &T::start_translation_timestep == \
67      (Translator_void_method_ptr) &Translator::start_translation_timestep)      \
68     ? 0                                                                 \
69     : (Translator_void_method_ptr) &T::start_translation_timestep;      \
70                                                                         \
71   ptrs[STOP_TRANSLATION_TIMESTEP] =                                     \
72     ((Translator_void_method_ptr) &T::stop_translation_timestep == (Translator_void_method_ptr) &Translator::stop_translation_timestep) \
73     ? 0                                                                 \
74     : (Translator_void_method_ptr) &T::stop_translation_timestep;       \
75                                                                         \
76   ptrs[PROCESS_MUSIC] =                                                 \
77     ((Translator_void_method_ptr) &T::process_music == (Translator_void_method_ptr) &Translator::process_music)                 \
78     ? 0                                                                 \
79     : (Translator_void_method_ptr) &T::process_music;           \
80                                                                         \
81   ptrs[PROCESS_ACKNOWLEDGED] =                                          \
82     ((Translator_void_method_ptr) &T::process_acknowledged == (Translator_void_method_ptr) &Translator::process_acknowledged)   \
83     ? 0                                                                 \
84     : (Translator_void_method_ptr) &T::process_acknowledged;            \
85 }
86
87
88 #endif /* TRANSLATOR_ICC */
89