2 tweak-registration.cc -- implement Tweak_registry
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "tweak-registration.hh"
12 #include "object-key-undumper.hh"
15 #include "ly-smobs.icc"
18 Tweak_registry::clear ()
21 undumper_ = new Object_key_undumper();
22 scm_gc_unprotect_object (undumper_->self_scm ());
26 Tweak_registry::insert_tweak_from_file (SCM tweak)
28 SCM skey = scm_car (tweak);
30 assert(scm_is_pair (skey) &&
31 scm_car (skey) == ly_symbol2scm ("key"));
33 Object_key const * key = undumper_->get_key (scm_to_int (scm_cadr (skey)));
34 if (tweaks_.find (key) == tweaks_.end())
36 tweaks_[key] = SCM_EOL;
39 tweaks_[key] = scm_cons (scm_cdr (tweak), tweaks_[key]);
44 Tweak_registry::insert_grob_tweak (Grob *g, SCM tweak)
46 Object_key const * key = g->get_key ();
47 if (tweaks_.find (key) == tweaks_.end())
49 tweaks_[key] = SCM_EOL;
52 tweaks_[key] = scm_cons (tweak, tweaks_[key]);
57 Tweak_registry::get_tweaks (Grob *g)
59 Object_key const *key = g->get_key();
60 if (tweaks_.find (key) == tweaks_.end())
67 Tweak_registry::Tweak_registry ()
71 undumper_ = new Object_key_undumper();
72 scm_gc_unprotect_object (undumper_->self_scm ());
75 Tweak_registry::~Tweak_registry ()
80 Tweak_registry::list_tweaks ()
83 for (Tweak_map::const_iterator i (tweaks_.begin ());
87 const Object_key * key = (*i).first;
88 for (SCM t = (*i).second; scm_is_pair (t); t = scm_cdr (t))
90 retval = scm_cons (scm_cons (key->self_scm(), scm_car (t)), retval);
98 Tweak_registry::mark_smob (SCM smob)
100 Tweak_registry *me = (Tweak_registry*) SCM_CELL_WORD_1(smob);
102 for (Tweak_map::const_iterator i (me->tweaks_.begin ());
103 i != me->tweaks_.end();
106 scm_gc_mark ((*i).first->self_scm());
107 scm_gc_mark ((*i).second);
111 scm_gc_mark (me->undumper_->self_scm());
117 Tweak_registry::print_smob (SCM smob, SCM port, scm_print_state*)
119 (void) smob; // smother warning.
120 scm_puts ("#<Tweak_registry>", port);
125 Tweak_registry::undumper () const
130 IMPLEMENT_DEFAULT_EQUAL_P(Tweak_registry);
131 IMPLEMENT_SMOBS(Tweak_registry);
134 Tweak_registry * global_registry_;
137 init_global_tweak_registry()
139 global_registry_ = new Tweak_registry();