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 ());
32 Lilypond_grob_key::do_compare (Object_key const* key) const
34 Lilypond_grob_key const * other = dynamic_cast<Lilypond_grob_key const*> (key);
37 c = context_->compare (other->context_);
41 c = Moment::compare (creation_moment_, other->creation_moment_);
45 c = String::compare (grob_name_, other->grob_name_);
49 c = sign (disambiguation_count_ - other->disambiguation_count_);
58 Lilypond_grob_key::get_type () const
65 Lilypond_grob_key::as_scheme () const
67 return scm_list_4 (context_ ? context_->self_scm() : SCM_BOOL_F,
68 creation_moment_.smobbed_copy(),
69 scm_makfrom0str (grob_name_.to_str0()),
70 scm_from_int (disambiguation_count_));
75 Lilypond_grob_key::from_scheme (SCM a)
77 return new Lilypond_grob_key (unsmob_key (scm_car (a)),
78 *unsmob_moment (scm_cadr (a)),
79 ly_scm2string (scm_caddr (a)),
80 scm_to_int (scm_cadddr (a)));
84 /****************************************************************/
87 Lilypond_context_key::derived_mark () const
90 scm_gc_mark (parent_context_->self_scm ());
93 Lilypond_context_key::Lilypond_context_key (Object_key const *parent,
99 disambiguation_count_ = count;
100 parent_context_ = parent;
101 start_moment_ = start;
102 context_name_ = type;
108 Lilypond_context_key::do_compare (Object_key const *key) const
110 Lilypond_context_key const * other
111 = dynamic_cast<Lilypond_context_key const*> (key);
114 if (parent_context_ && other->parent_context_)
116 c = parent_context_->compare (other->parent_context_);
120 else if (parent_context_)
122 else if (other->parent_context_)
126 c = Moment::compare (start_moment_, other->start_moment_);
130 c = String::compare (context_name_, other->context_name_);
134 c = String::compare (id_, other->id_);
138 c = sign (disambiguation_count_ - other->disambiguation_count_);
146 Lilypond_context_key::get_type () const
153 Lilypond_context_key::as_scheme () const
155 return scm_list_5 (parent_context_ ? parent_context_->self_scm() : SCM_BOOL_F,
156 start_moment_.smobbed_copy(),
157 scm_makfrom0str (context_name_.to_str0()),
158 scm_makfrom0str (id_.to_str0()),
159 scm_from_int (disambiguation_count_));
163 Lilypond_context_key::from_scheme (SCM a)
165 return new Lilypond_grob_key (unsmob_key (scm_car (a)),
166 *unsmob_moment (scm_cadr (a)),
167 ly_scm2string (scm_list_ref (a, scm_from_int (2))),
168 scm_to_int (scm_list_ref (a, scm_from_int (3))));
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_);
215 c = sign (disambiguation_count_ - other->disambiguation_count_);
223 Lilypond_general_key::as_scheme () const
225 return scm_list_3 (parent_ ? parent_->self_scm() : SCM_BOOL_F,
226 scm_makfrom0str (name_.to_str0()),
227 scm_from_int (disambiguation_count_));
231 Lilypond_general_key::from_scheme (SCM a)
233 return new Lilypond_general_key (unsmob_key (scm_car (a)),
234 ly_scm2string (scm_list_ref (a, scm_from_int (1))),
235 scm_to_int (scm_list_ref (a, scm_from_int (2))));