]> git.donarmstrong.com Git - lilypond.git/blob - lily/translator-ctors.cc
* The grand 2005-2006 replace.
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.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   SCM l = global_translator_dict ? global_translator_dict->to_alist () : SCM_EOL;
23
24   for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
25     scm_set_car_x (s, scm_cdar (s));
26
27   return l;
28 }
29
30 void
31 add_translator (Translator *t)
32 {
33   if (!global_translator_dict)
34     global_translator_dict = new Scheme_hash_table;
35
36   SCM k = ly_symbol2scm (t->class_name ());
37   global_translator_dict->set (k, t->self_scm ());
38
39   t->unprotect ();
40 }
41
42 Translator *
43 get_translator (SCM sym)
44 {
45   SCM v = SCM_BOOL_F;
46   if (global_translator_dict)
47     global_translator_dict->try_retrieve (sym, &v);
48
49   if (v == SCM_BOOL_F)
50     error (_f ("unknown translator: `%s'", ly_symbol2string (sym).to_str0 ()));
51
52   return unsmob_translator (v);
53 }
54