]> git.donarmstrong.com Git - lilypond.git/blob - lily/music-constructor.cc
* lily/modified-font-metric.cc (text_dimension): try
[lilypond.git] / lily / music-constructor.cc
1 /*   
2   music-constructor.cc --  implement Music_constructor
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2001--2004  Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "music-constructor.hh"
11
12 #include <map>                  // UGH.
13 #include <cassert>
14
15 #include "warn.hh"
16
17 typedef Music *(*Music_ctor) ();
18
19 static std::map<String,Music_ctor> *ctors_map_;
20
21 void
22 add_music_ctor (String s, Music_ctor c)
23 {
24   if (!ctors_map_)
25     ctors_map_ = new std::map<String, Music_ctor>;
26   
27  (*ctors_map_)[s] = c;
28 }
29
30 Music_ctor
31 get_music_ctor (String s)
32 {
33   if (ctors_map_->find (s) == ctors_map_->end ())
34     return 0;
35
36   return (*ctors_map_)[s];
37 }
38
39 Music * 
40 make_music (String s)
41 {
42   Music_ctor c = get_music_ctor (s);
43   if (!c)
44     programming_error (String ("No constructor for music: ") + s);
45   assert (c);
46   
47   return (*c) ();
48 }
49