]> git.donarmstrong.com Git - lilypond.git/blob - lily/music-constructor.cc
* Documentation/index.html.in: Fix url to one big page. (backportme)
[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 <map>                  // UGH.
11 #include <assert.h>
12
13 #include "warn.hh"
14 #include "music-constructor.hh"
15
16 typedef Music *(*Music_ctor) ();
17
18 static std::map<String,Music_ctor> *ctors_map_;
19
20 void
21 add_music_ctor (String s, Music_ctor c)
22 {
23   if (!ctors_map_)
24     ctors_map_ = new std::map<String, Music_ctor>;
25   
26  (*ctors_map_)[s] = c;
27 }
28
29 Music_ctor
30 get_music_ctor (String s)
31 {
32   if (ctors_map_->find (s) == ctors_map_->end ())
33     return 0;
34
35   return (*ctors_map_)[s];
36 }
37
38 Music * 
39 make_music (String s)
40 {
41   Music_ctor c = get_music_ctor (s);
42   if (!c)
43     programming_error (String ("No constructor for music: ") + s);
44   assert (c);
45   
46   return (*c) ();
47 }
48