]> git.donarmstrong.com Git - lilypond.git/blob - lily/translator-ctors.cc
* lily/translator-def.cc (get_translator_names): new function
[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--2003 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 an list of a all translator objects that may be instantiated "
21           " during a lilypond run.")
22 {
23   SCM l = global_translator_dict ?  global_translator_dict->to_alist () : SCM_EOL;
24
25   for (SCM s =l; gh_pair_p (s); s = gh_cdr (s))
26     {
27       gh_set_car_x (s, gh_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
43 Translator*
44 get_translator (SCM sym)
45 {
46   SCM v = SCM_BOOL_F;
47   if (global_translator_dict)
48     global_translator_dict->try_retrieve (sym, &v);
49
50   if (v == SCM_BOOL_F)
51     error (_f ("unknown translator: `%s'", ly_symbol2string (sym).to_str0 ()));
52
53   return unsmob_translator (v);
54 }
55