]> git.donarmstrong.com Git - lilypond.git/blob - lily/music-constructor.cc
5d567c02afe49d34b1c8655b7f466fea91ce7f85
[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--2002  Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include <map>                  // UGH.
11 #include "warn.hh"
12 #include "music-constructor.hh"
13 typedef Music* (*Music_ctor) ();
14
15 static std::map<String,Music_ctor> *ctors_map_;
16
17 void
18 add_music_ctor (String s,  Music_ctor c)
19 {
20   if (!ctors_map_)
21     ctors_map_ = new std::map<String, Music_ctor>;
22   
23  (*ctors_map_)[s] = c;
24 }
25
26
27 Music_ctor
28 get_music_ctor (String s)
29 {
30   if (ctors_map_->find (s) == ctors_map_->end ())
31     return 0;
32
33   return (* ctors_map_)[s];
34 }
35
36 Music* 
37 make_music (String s)
38 {
39   Music_ctor c = get_music_ctor (s);
40   if (!c)
41     programming_error (String ("No constructor for music: ") + s);
42   assert (c);
43   
44   return (*c) ();
45 }
46