]> git.donarmstrong.com Git - lilypond.git/blob - lily/translator-ctors.cc
* scm/music-functions.scm (has-request-chord): don't use
[lilypond.git] / lily / translator-ctors.cc
1 /*
2   translator-ctors.cc -- implement Translator construction
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "translator.hh"
10 #include "scm-hash.hh"
11 #include "warn.hh"
12
13 /*
14   should delete these after exit.
15 */
16
17 Scheme_hash_table *global_translator_dict = 0;
18
19 LY_DEFINE (get_all_translators, "ly:get-all-translators", 0, 0, 0,  (),
20           "Return a list of all translator objects that may be instantiated. "
21            )
22 {
23   SCM l = global_translator_dict ?  global_translator_dict->to_alist () : SCM_EOL;
24
25   for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
26     {
27       scm_set_car_x (s, scm_cdar (s));
28     }
29
30   return l;
31 }
32
33 void
34 add_translator (Translator *t)
35 {
36   if (!global_translator_dict)
37     global_translator_dict = new Scheme_hash_table;
38
39   SCM k = ly_symbol2scm  (classname (t));
40   global_translator_dict->set (k, t->self_scm ());
41
42   scm_gc_unprotect_object (t->self_scm ());
43 }
44
45 Translator*
46 get_translator (SCM sym)
47 {
48   SCM v = SCM_BOOL_F;
49   if (global_translator_dict)
50     global_translator_dict->try_retrieve (sym, &v);
51
52   if (v == SCM_BOOL_F)
53     error (_f ("unknown translator: `%s'", ly_symbol2string (sym).to_str0 ()));
54
55   return unsmob_translator (v);
56 }
57