]> git.donarmstrong.com Git - lilypond.git/blob - lily/translator-ctors.cc
d9b47995f486242d7811c4d7583cef930f8339a4
[lilypond.git] / lily / translator-ctors.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "translator.hh"
21
22 #include "international.hh"
23 #include "scm-hash.hh"
24 #include "warn.hh"
25
26 /*
27   should delete these after exit.
28 */
29
30 Scheme_hash_table *global_translator_dict = 0;
31
32 LY_DEFINE (get_all_translators, "ly:get-all-translators", 0, 0, 0, (),
33            "Return a list of all translator objects that may be"
34            " instantiated.")
35 {
36   SCM l = global_translator_dict ? global_translator_dict->to_alist () : SCM_EOL;
37
38   for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
39     scm_set_car_x (s, scm_cdar (s));
40
41   return l;
42 }
43
44 void
45 add_translator (Translator *t)
46 {
47   if (!global_translator_dict)
48     global_translator_dict = new Scheme_hash_table;
49
50   SCM k = ly_symbol2scm (t->class_name ());
51   global_translator_dict->set (k, t->self_scm ());
52
53   t->unprotect ();
54 }
55
56 Translator *
57 get_translator (SCM sym)
58 {
59   SCM v = SCM_BOOL_F;
60   if (global_translator_dict)
61     global_translator_dict->try_retrieve (sym, &v);
62
63   if (v == SCM_BOOL_F)
64     {
65       warning (_f ("unknown translator: `%s'", ly_symbol2string (sym).c_str ()));
66       return 0;
67     }
68
69   return unsmob_translator (v);
70 }
71