2 object-key.cc -- implement Object_key
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "lilypond-key.hh"
11 #include "ly-smobs.icc"
14 Object_key::mark_smob (SCM key)
16 Object_key* k = (Object_key*) SCM_CELL_WORD_1 (key);
22 Object_key::derived_mark () const
27 Object_key::~Object_key()
32 Object_key::get_type () const
38 Object_key::print_smob (SCM smob, SCM port, scm_print_state*)
40 Object_key* k = (Object_key*) SCM_CELL_WORD_1 (smob);
41 scm_puts ("#<Object_key ", port);
42 scm_display (scm_from_int (k->get_type()), port);
47 Object_key::Object_key ()
53 Object_key::compare (Object_key const *other) const
58 int c = sign (get_type () - other->get_type());
62 return do_compare (other);
65 IMPLEMENT_SMOBS (Object_key);
68 Object_key::equal_p (SCM a , SCM b)
70 Object_key *ka = unsmob_key (a);
71 Object_key *kb = unsmob_key (b);
73 return (ka->compare (kb)) ? SCM_BOOL_F : SCM_BOOL_T;
77 Object_key::do_compare (Object_key const *) const
84 Object_key::dump () const
86 return scm_cons (scm_from_int (get_type()),
93 Object_key::as_scheme () const
99 Object_key::from_scheme (SCM)
101 return new Object_key();
105 Object_key_type type_;
106 Object_key* (*ctor_)(SCM);
108 {BASE_KEY, Object_key::from_scheme},
109 {COPIED_KEY, Copied_key::from_scheme},
110 {GENERAL_KEY, Lilypond_general_key::from_scheme},
111 {GROB_KEY, Lilypond_grob_key::from_scheme},
112 {CONTEXT_KEY, Lilypond_context_key::from_scheme},
117 Object_key::undump (SCM scm_key)
119 int t = scm_to_int (scm_car (scm_key));
120 assert (t == undumpers[t].type_);
121 return (undumpers[t].ctor_)(scm_cdr (scm_key));
124 /****************************************************************/
126 Copied_key::Copied_key (Object_key const* key, int count)
133 Copied_key::get_type () const
139 Copied_key::do_compare (Object_key const *key) const
141 Copied_key const *other = dynamic_cast<Copied_key const*> (key);
143 int c = original_->compare (other->original_);
147 return sign (copy_count_ - other->copy_count_);
151 Copied_key::derived_mark () const
153 scm_gc_mark (original_->self_scm ());
157 Copied_key::as_scheme () const
159 return scm_list_2 (original_ ? original_->self_scm() : SCM_BOOL_F, scm_from_int (copy_count_));
164 Copied_key::from_scheme (SCM a)
166 return new Copied_key (unsmob_key (scm_car (a)),
167 scm_to_int (scm_list_ref (a, scm_from_int (1))));