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