2 lilypond-key.cc -- implement Lilypond_{grob, context}_key
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "lilypond-key.hh"
11 Lilypond_grob_key::Lilypond_grob_key (Object_key const *context,
14 int disambiguation_count)
17 creation_moment_ = start;
19 disambiguation_count_ = disambiguation_count;
23 Lilypond_grob_key::derived_mark () const
26 scm_gc_mark (context_->self_scm ());
29 // todo: reverse order of comparison for efficiency reasons.
31 Lilypond_grob_key::do_compare (Object_key const *key) const
33 Lilypond_grob_key const *other = dynamic_cast<Lilypond_grob_key const *> (key);
36 c = context_->compare (other->context_);
40 c = Moment::compare (creation_moment_, other->creation_moment_);
44 c = grob_name_.compare (other->grob_name_);
48 c = sign (disambiguation_count_ - other->disambiguation_count_);
56 Lilypond_grob_key::get_type () const
62 Lilypond_grob_key::as_scheme () const
64 return scm_list_4 (context_ ? context_->self_scm () : SCM_BOOL_F,
65 creation_moment_.smobbed_copy (),
66 scm_makfrom0str (grob_name_.c_str ()),
67 scm_from_int (disambiguation_count_));
71 Lilypond_grob_key::from_scheme (SCM a)
73 return new Lilypond_grob_key (unsmob_key (scm_car (a)),
74 *unsmob_moment (scm_cadr (a)),
75 ly_scm2string (scm_caddr (a)),
76 scm_to_int (scm_list_ref (a, scm_from_int (3))));
79 /****************************************************************/
82 Lilypond_context_key::derived_mark () const
85 scm_gc_mark (parent_context_->self_scm ());
88 Lilypond_context_key::Lilypond_context_key (Object_key const *parent,
94 disambiguation_count_ = count;
95 parent_context_ = parent;
96 start_moment_ = start;
102 Lilypond_context_key::do_compare (Object_key const *key) const
104 Lilypond_context_key const *other
105 = dynamic_cast<Lilypond_context_key const *> (key);
108 if (parent_context_ && other->parent_context_)
110 c = parent_context_->compare (other->parent_context_);
114 else if (parent_context_)
116 else if (other->parent_context_)
119 c = Moment::compare (start_moment_, other->start_moment_);
123 c = context_name_.compare (other->context_name_);
127 c = id_.compare (other->id_);
131 c = sign (disambiguation_count_ - other->disambiguation_count_);
139 Lilypond_context_key::get_type () const
145 Lilypond_context_key::as_scheme () const
147 return scm_list_5 (parent_context_ ? parent_context_->self_scm () : SCM_BOOL_F,
148 start_moment_.smobbed_copy (),
149 scm_makfrom0str (context_name_.c_str ()),
150 scm_makfrom0str (id_.c_str ()),
151 scm_from_int (disambiguation_count_));
155 Lilypond_context_key::from_scheme (SCM a)
157 return new Lilypond_context_key (unsmob_key (scm_car (a)),
158 *unsmob_moment (scm_cadr (a)),
159 ly_scm2string (scm_list_ref (a, scm_from_int (2))),
160 ly_scm2string (scm_list_ref (a, scm_from_int (3))),
161 scm_to_int (scm_list_ref (a, scm_from_int (4))));
164 /****************************************************************/
167 Lilypond_general_key::get_type () const
173 Lilypond_general_key::derived_mark () const
176 scm_gc_mark (parent_->self_scm ());
179 Lilypond_general_key::Lilypond_general_key (Object_key const *parent,
185 disambiguation_count_ = count;
189 Lilypond_general_key::do_compare (Object_key const *key)const
191 Lilypond_general_key const *other
192 = dynamic_cast<Lilypond_general_key const *> (key);
194 if (parent_ && other->parent_)
195 parent_->compare (other->parent_);
198 else if (other->parent_)
201 int c = name_.compare (other->name_);
205 c = sign (disambiguation_count_ - other->disambiguation_count_);
213 Lilypond_general_key::as_scheme () const
215 return scm_list_3 (parent_ ? parent_->self_scm () : SCM_BOOL_F,
216 scm_makfrom0str (name_.c_str ()),
217 scm_from_int (disambiguation_count_));
221 Lilypond_general_key::from_scheme (SCM a)
223 return new Lilypond_general_key (unsmob_key (scm_car (a)),
224 ly_scm2string (scm_list_ref (a, scm_from_int (1))),
225 scm_to_int (scm_list_ref (a, scm_from_int (2))));