2 lilypond-key.cc -- implement Lilypond_{grob,context}_key
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "lilypond-key.hh"
12 Lilypond_grob_key::Lilypond_grob_key (Object_key const *context,
15 int disambiguation_count)
18 creation_moment_ = start;
20 disambiguation_count_ = disambiguation_count;
24 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 = String::compare (grob_name_, other->grob_name_);
48 c = sign (disambiguation_count_ - other->disambiguation_count_);
57 Lilypond_grob_key::get_type () const
64 Lilypond_grob_key::as_scheme () const
66 return scm_list_4 (context_ ? context_->self_scm() : SCM_BOOL_F,
67 creation_moment_.smobbed_copy(),
68 scm_makfrom0str (grob_name_.to_str0()),
69 scm_from_int (disambiguation_count_));
74 Lilypond_grob_key::from_scheme (SCM a)
76 return new Lilypond_grob_key (unsmob_key (scm_car (a)),
77 *unsmob_moment (scm_cadr (a)),
78 ly_scm2string (scm_caddr (a)),
79 scm_to_int (scm_list_ref (a, scm_from_int (3))));
83 /****************************************************************/
86 Lilypond_context_key::derived_mark () const
89 scm_gc_mark (parent_context_->self_scm ());
92 Lilypond_context_key::Lilypond_context_key (Object_key const *parent,
98 disambiguation_count_ = count;
99 parent_context_ = parent;
100 start_moment_ = start;
101 context_name_ = type;
107 Lilypond_context_key::do_compare (Object_key const *key) const
109 Lilypond_context_key const * other
110 = dynamic_cast<Lilypond_context_key const*> (key);
113 if (parent_context_ && other->parent_context_)
115 c = parent_context_->compare (other->parent_context_);
119 else if (parent_context_)
121 else if (other->parent_context_)
125 c = Moment::compare (start_moment_, other->start_moment_);
129 c = String::compare (context_name_, other->context_name_);
133 c = String::compare (id_, other->id_);
137 c = sign (disambiguation_count_ - other->disambiguation_count_);
145 Lilypond_context_key::get_type () const
152 Lilypond_context_key::as_scheme () const
154 return scm_list_5 (parent_context_ ? parent_context_->self_scm() : SCM_BOOL_F,
155 start_moment_.smobbed_copy(),
156 scm_makfrom0str (context_name_.to_str0()),
157 scm_makfrom0str (id_.to_str0()),
158 scm_from_int (disambiguation_count_));
162 Lilypond_context_key::from_scheme (SCM a)
164 return new Lilypond_context_key (unsmob_key (scm_car (a)),
165 *unsmob_moment (scm_cadr (a)),
166 ly_scm2string (scm_list_ref (a, scm_from_int (2))),
167 ly_scm2string (scm_list_ref (a, scm_from_int (3))),
168 scm_to_int (scm_list_ref (a, scm_from_int (4))));
172 /****************************************************************/
175 Lilypond_general_key::get_type () const
181 Lilypond_general_key::derived_mark () const
184 scm_gc_mark (parent_->self_scm ());
187 Lilypond_general_key::Lilypond_general_key (Object_key const*parent,
193 disambiguation_count_ = count;
198 Lilypond_general_key::do_compare (Object_key const* key)const
200 Lilypond_general_key const* other
201 = dynamic_cast<Lilypond_general_key const*> (key);
203 if (parent_ && other->parent_)
204 parent_->compare (other->parent_);
207 else if (other->parent_)
210 int c = String::compare (name_, other->name_);
214 c = sign (disambiguation_count_ - other->disambiguation_count_);
222 Lilypond_general_key::as_scheme () const
224 return scm_list_3 (parent_ ? parent_->self_scm() : SCM_BOOL_F,
225 scm_makfrom0str (name_.to_str0()),
226 scm_from_int (disambiguation_count_));
230 Lilypond_general_key::from_scheme (SCM a)
232 return new Lilypond_general_key (unsmob_key (scm_car (a)),
233 ly_scm2string (scm_list_ref (a, scm_from_int (1))),
234 scm_to_int (scm_list_ref (a, scm_from_int (2))));