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>
11 #include "object-key.hh"
12 #include "lilypond-key.hh"
14 Lilypond_grob_key::Lilypond_grob_key (Object_key const *context,
17 int disambiguation_count)
20 creation_moment_ = start;
22 disambiguation_count_ = disambiguation_count;
26 Lilypond_grob_key::derived_mark () const
28 scm_gc_mark (context_->self_scm ());
31 // todo: reverse order of comparison for efficiency reasons.
33 Lilypond_grob_key::do_compare (Object_key const* key) const
35 Lilypond_grob_key const * other = dynamic_cast<Lilypond_grob_key const*> (key);
38 c = context_->compare (other->context_);
42 c = Moment::compare (creation_moment_, other->creation_moment_);
46 c = String::compare (grob_name_, other->grob_name_);
50 c = sign (disambiguation_count_ - other->disambiguation_count_);
59 Lilypond_grob_key::get_type () const
66 Lilypond_grob_key::as_scheme () const
68 return scm_list_4 (context_ ? context_->self_scm() : SCM_BOOL_F,
69 creation_moment_.smobbed_copy(),
70 scm_makfrom0str (grob_name_.to_str0()),
71 scm_from_int (disambiguation_count_));
76 Lilypond_grob_key::from_scheme (SCM a)
78 return new Lilypond_grob_key (unsmob_key (scm_car (a)),
79 *unsmob_moment (scm_cadr (a)),
80 ly_scm2string (scm_caddr (a)),
81 scm_to_int (scm_list_ref (a, scm_from_int (3))));
85 /****************************************************************/
88 Lilypond_context_key::derived_mark () const
91 scm_gc_mark (parent_context_->self_scm ());
94 Lilypond_context_key::Lilypond_context_key (Object_key const *parent,
100 disambiguation_count_ = count;
101 parent_context_ = parent;
102 start_moment_ = start;
103 context_name_ = type;
109 Lilypond_context_key::do_compare (Object_key const *key) const
111 Lilypond_context_key const * other
112 = dynamic_cast<Lilypond_context_key const*> (key);
115 if (parent_context_ && other->parent_context_)
117 c = parent_context_->compare (other->parent_context_);
121 else if (parent_context_)
123 else if (other->parent_context_)
127 c = Moment::compare (start_moment_, other->start_moment_);
131 c = String::compare (context_name_, other->context_name_);
135 c = String::compare (id_, other->id_);
139 c = sign (disambiguation_count_ - other->disambiguation_count_);
147 Lilypond_context_key::get_type () const
154 Lilypond_context_key::as_scheme () const
156 return scm_list_5 (parent_context_ ? parent_context_->self_scm() : SCM_BOOL_F,
157 start_moment_.smobbed_copy(),
158 scm_makfrom0str (context_name_.to_str0()),
159 scm_makfrom0str (id_.to_str0()),
160 scm_from_int (disambiguation_count_));
164 Lilypond_context_key::from_scheme (SCM a)
166 return new Lilypond_context_key (unsmob_key (scm_car (a)),
167 *unsmob_moment (scm_cadr (a)),
168 ly_scm2string (scm_list_ref (a, scm_from_int (2))),
169 ly_scm2string (scm_list_ref (a, scm_from_int (3))),
170 scm_to_int (scm_list_ref (a, scm_from_int (4))));
174 /****************************************************************/
177 Lilypond_general_key::get_type () const
183 Lilypond_general_key::derived_mark () const
186 scm_gc_mark (parent_->self_scm ());
189 Lilypond_general_key::Lilypond_general_key (Object_key const*parent,
195 disambiguation_count_ = count;
200 Lilypond_general_key::do_compare (Object_key const* key)const
202 Lilypond_general_key const* other
203 = dynamic_cast<Lilypond_general_key const*> (key);
205 if (parent_ && other->parent_)
206 parent_->compare (other->parent_);
209 else if (other->parent_)
212 int c = String::compare (name_, other->name_);
216 c = sign (disambiguation_count_ - other->disambiguation_count_);
224 Lilypond_general_key::as_scheme () const
226 return scm_list_3 (parent_ ? parent_->self_scm() : SCM_BOOL_F,
227 scm_makfrom0str (name_.to_str0()),
228 scm_from_int (disambiguation_count_));
232 Lilypond_general_key::from_scheme (SCM a)
234 return new Lilypond_general_key (unsmob_key (scm_car (a)),
235 ly_scm2string (scm_list_ref (a, scm_from_int (1))),
236 scm_to_int (scm_list_ref (a, scm_from_int (2))));