]> git.donarmstrong.com Git - lilypond.git/blob - lily/object-key-undumper.cc
Merge branch 'jneeman' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond into jneeman
[lilypond.git] / lily / object-key-undumper.cc
1 /*
2   object-key-undumper.cc -- implement Object_key_undumper
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "object-key-undumper.hh"
10
11 #include "ly-smobs.icc"
12
13 IMPLEMENT_SMOBS (Object_key_undumper);
14 IMPLEMENT_DEFAULT_EQUAL_P (Object_key_undumper);
15
16 SCM
17 Object_key_undumper::mark_smob (SCM smob)
18 {
19   Object_key_undumper *undumper = (Object_key_undumper *) SCM_CELL_WORD_1 (smob);
20   for (Int_to_key_map::const_iterator i (undumper->keys_.begin ());
21        i != undumper->keys_.end (); i++)
22     scm_gc_mark ((*i).second->self_scm ());
23
24   return SCM_BOOL_F;
25 }
26
27 int
28 Object_key_undumper::print_smob (SCM s, SCM port, scm_print_state*)
29 {
30   (void) s;
31   scm_puts ("#<Object_key_undumper>", port);
32   return 1;
33 }
34
35 Object_key_undumper::Object_key_undumper ()
36 {
37   smobify_self ();
38 }
39
40 void
41 Object_key_undumper::parse_contents (SCM contents)
42 {
43   for (SCM s = contents; scm_is_pair (s); s = scm_cdr (s))
44     {
45       SCM entry = scm_car (s);
46       if (scm_car (entry) != ly_symbol2scm ("define-key"))
47         continue;
48
49       int number = scm_to_int (scm_cadr (entry));
50       SCM skey = scm_caddr (entry);
51
52       SCM new_key = SCM_EOL;
53       SCM *tail = &new_key;
54       for (SCM t = skey; scm_is_pair (t); t = scm_cdr (t))
55         {
56           SCM item = scm_car (t);
57           if (scm_is_pair (item)
58               && scm_car (item) == ly_symbol2scm ("key"))
59             {
60               int index = scm_to_int (scm_cadr (item));
61               Object_key const *key = get_key (index);
62               *tail = scm_cons (key->self_scm (), SCM_EOL);
63             }
64           else
65             *tail = scm_cons (item, SCM_EOL);
66           tail = SCM_CDRLOC (*tail);
67         }
68
69       Object_key *k = Object_key::undump (new_key);
70       keys_[number] = k;
71       k->unprotect ();
72     }
73 }
74
75 Object_key const *
76 Object_key_undumper::get_key (int idx)
77 {
78   Int_to_key_map::const_iterator i (keys_.find (idx));
79   assert (i != keys_.end ());
80
81   return (*i).second;
82 }
83
84 Object_key_undumper::~Object_key_undumper ()
85 {
86 }