2 object-key-dumper.cc -- implement Object_key_dumper
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "object-key-dumper.hh"
13 #include "ly-smobs.icc"
16 Object_key_dumper::mark_smob (SCM smob)
18 Object_key_dumper *dumper = (Object_key_dumper *) SCM_CELL_WORD_1 (smob);
20 for (Key_to_key_map::const_iterator i (dumper->serialized_keys_.begin ());
21 i != dumper->serialized_keys_.end ();
23 scm_gc_mark ((*i).first->self_scm ());
28 Object_key_dumper::print_smob (SCM, SCM port, scm_print_state*)
30 scm_puts ("#<Object_key_dumper>", port);
34 IMPLEMENT_DEFAULT_EQUAL_P (Object_key_dumper);
35 IMPLEMENT_SMOBS (Object_key_dumper);
37 Object_key_dumper::Object_key_dumper ()
39 file_contents_ = SCM_EOL;
45 Object_key_dumper::key_serial (int k)
47 return scm_list_2 (ly_symbol2scm ("key"),
52 Object_key_dumper::serialize_key (Object_key const *key)
54 SCM skey = key->dump ();
55 for (SCM s = skey; scm_is_pair (s); s = scm_cdr (s))
57 if (Object_key const *sub_key = unsmob_key (scm_car (s)))
58 scm_set_car_x (s, dump_key (sub_key));
59 else if (Moment *mom = unsmob_moment (scm_car (s)))
61 scm_list_2 (ly_symbol2scm ("unquote"),
65 file_contents_ = scm_cons (scm_list_3 (ly_symbol2scm ("define-key"),
66 scm_from_int (next_available_),
70 serialized_keys_[key] = key;
71 key_serial_numbers_[key] = next_available_;
72 SCM retval = key_serial (next_available_);
79 Object_key_dumper::dump_key (Object_key const *key)
81 if (key_serial_numbers_.find (key) != key_serial_numbers_.end ())
82 return key_serial (key_serial_numbers_[key]);
83 else if (Object_key const *serialized = serialized_keys_[key])
84 return key_serial (key_serial_numbers_[ serialized_keys_ [serialized] ]);
86 return serialize_key (key);
90 Object_key_dumper::get_file_contents () const
92 return scm_reverse (file_contents_);
95 Object_key_dumper::~Object_key_dumper ()