2 lilypond-key.cc -- implement Lilypond_{grob, context}_key
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2005 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
25 scm_gc_mark (context_->self_scm ());
28 // todo: reverse order of comparison for efficiency reasons.
30 Lilypond_grob_key::do_compare (Object_key const *key) const
32 Lilypond_grob_key const *other = dynamic_cast<Lilypond_grob_key const *> (key);
35 c = context_->compare (other->context_);
39 c = Moment::compare (creation_moment_, other->creation_moment_);
43 c = String::compare (grob_name_, other->grob_name_);
47 c = sign (disambiguation_count_ - other->disambiguation_count_);
55 Lilypond_grob_key::get_type () const
61 Lilypond_grob_key::as_scheme () const
63 return scm_list_4 (context_ ? context_->self_scm () : SCM_BOOL_F,
64 creation_moment_.smobbed_copy (),
65 scm_makfrom0str (grob_name_.to_str0 ()),
66 scm_from_int (disambiguation_count_));
70 Lilypond_grob_key::from_scheme (SCM a)
72 return new Lilypond_grob_key (unsmob_key (scm_car (a)),
73 *unsmob_moment (scm_cadr (a)),
74 ly_scm2string (scm_caddr (a)),
75 scm_to_int (scm_list_ref (a, scm_from_int (3))));
78 /****************************************************************/
81 Lilypond_context_key::derived_mark () const
84 scm_gc_mark (parent_context_->self_scm ());
87 Lilypond_context_key::Lilypond_context_key (Object_key const *parent,
93 disambiguation_count_ = count;
94 parent_context_ = parent;
95 start_moment_ = start;
101 Lilypond_context_key::do_compare (Object_key const *key) const
103 Lilypond_context_key const *other
104 = dynamic_cast<Lilypond_context_key const *> (key);
107 if (parent_context_ && other->parent_context_)
109 c = parent_context_->compare (other->parent_context_);
113 else if (parent_context_)
115 else if (other->parent_context_)
118 c = Moment::compare (start_moment_, other->start_moment_);
122 c = String::compare (context_name_, other->context_name_);
126 c = String::compare (id_, other->id_);
130 c = sign (disambiguation_count_ - other->disambiguation_count_);
138 Lilypond_context_key::get_type () const
144 Lilypond_context_key::as_scheme () const
146 return scm_list_5 (parent_context_ ? parent_context_->self_scm () : SCM_BOOL_F,
147 start_moment_.smobbed_copy (),
148 scm_makfrom0str (context_name_.to_str0 ()),
149 scm_makfrom0str (id_.to_str0 ()),
150 scm_from_int (disambiguation_count_));
154 Lilypond_context_key::from_scheme (SCM a)
156 return new Lilypond_context_key (unsmob_key (scm_car (a)),
157 *unsmob_moment (scm_cadr (a)),
158 ly_scm2string (scm_list_ref (a, scm_from_int (2))),
159 ly_scm2string (scm_list_ref (a, scm_from_int (3))),
160 scm_to_int (scm_list_ref (a, scm_from_int (4))));
163 /****************************************************************/
166 Lilypond_general_key::get_type () const
172 Lilypond_general_key::derived_mark () const
175 scm_gc_mark (parent_->self_scm ());
178 Lilypond_general_key::Lilypond_general_key (Object_key const *parent,
184 disambiguation_count_ = count;
188 Lilypond_general_key::do_compare (Object_key const *key)const
190 Lilypond_general_key const *other
191 = dynamic_cast<Lilypond_general_key const *> (key);
193 if (parent_ && other->parent_)
194 parent_->compare (other->parent_);
197 else if (other->parent_)
200 int c = String::compare (name_, other->name_);
204 c = sign (disambiguation_count_ - other->disambiguation_count_);
212 Lilypond_general_key::as_scheme () const
214 return scm_list_3 (parent_ ? parent_->self_scm () : SCM_BOOL_F,
215 scm_makfrom0str (name_.to_str0 ()),
216 scm_from_int (disambiguation_count_));
220 Lilypond_general_key::from_scheme (SCM a)
222 return new Lilypond_general_key (unsmob_key (scm_car (a)),
223 ly_scm2string (scm_list_ref (a, scm_from_int (1))),
224 scm_to_int (scm_list_ref (a, scm_from_int (2))));