2 prob.cc -- implement Prob
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2006 Jan Nieuwenhuizen <janneke@gnu.org>
14 #include "ly-smobs.icc"
16 IMPLEMENT_SMOBS (Prob);
17 IMPLEMENT_TYPE_P (Prob, "ly:prob?");
20 Prob::equal_p (SCM sa, SCM sb)
22 /* This comparison function is only designed to make the copy
23 constructor preserve equality.
25 Perhaps it would be better to use a more strict definition of
26 equality; e.g., that that two probs are equal iff they can be
27 distinguished by calls to ly:prob-property.
29 Prob *probs[2] = {unsmob_prob (sa), unsmob_prob (sb)};
33 for (i = 0; i < 2; i++)
35 props[i][0] = probs[i]->immutable_property_alist_;
36 props[i][1] = probs[i]->mutable_property_alist_;
39 if (strcmp (probs[0]->class_name (), probs[1]->class_name ()))
42 /* Compare mutable and immutable lists, element by element. */
43 for (i = 0; i < 2; i++)
45 SCM aprop = props[0][i];
46 SCM bprop = props[1][i];
49 scm_is_pair (aprop) && scm_is_pair(bprop);
50 aprop = scm_cdr (aprop), bprop = scm_cdr (bprop))
52 SCM aval = scm_cdar (aprop);
53 SCM bval = scm_cdar (bprop);
54 if (scm_caar (aprop) != scm_caar (bprop) ||
56 !(unsmob_input (aval) && unsmob_input (bval))
58 !to_boolean (scm_equal_p (aval, bval))))
62 /* is one list shorter? */
63 if (aprop != SCM_EOL || bprop != SCM_EOL)
70 Prob::Prob (SCM type, SCM immutable_init)
73 mutable_property_alist_ = SCM_EOL;
74 immutable_property_alist_ = immutable_init;
84 Prob::Prob (Prob const &src)
86 immutable_property_alist_ = src.immutable_property_alist_;
87 mutable_property_alist_ = SCM_EOL;
91 /* First we smobify_self, then we copy over the stuff. If we don't,
92 stack vars that hold the copy might be optimized away, meaning
93 that they won't be protected from GC. */
95 mutable_property_alist_ = src.copy_mutable_properties ();
100 Prob::copy_mutable_properties () const
102 return ly_deep_copy (mutable_property_alist_);
106 Prob::derived_mark () const
111 Prob::mark_smob (SCM smob)
113 ASSERT_LIVE_IS_ALLOWED();
115 Prob *system = (Prob *) SCM_CELL_WORD_1 (smob);
116 scm_gc_mark (system->mutable_property_alist_);
117 system->derived_mark ();
119 return system->immutable_property_alist_;
123 Prob::print_smob (SCM smob, SCM port, scm_print_state*)
125 Prob *p = (Prob *) SCM_CELL_WORD_1 (smob);
126 scm_puts ("#<", port);
127 scm_puts ("Prob: ", port);
128 scm_display (p->type_, port);
129 scm_puts (" C++: ", port);
130 scm_puts (p->class_name (), port);
131 scm_display (p->mutable_property_alist_, port);
132 scm_display (p->immutable_property_alist_, port);
134 scm_puts (" >\n", port);
141 Prob::internal_get_property (SCM sym) const
146 SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
150 s = scm_sloppy_assq (sym, immutable_property_alist_);
151 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
155 Prob::internal_set_property (SCM sym, SCM val
157 , char const *file, int line, char const *fun
167 if (do_internal_type_checking_global)
168 type_check_assignment (sym, val);
170 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, val);
174 Prob::type_check_assignment (SCM sym, SCM val) const
181 Prob::get_property_alist (bool m) const
183 return (m) ? mutable_property_alist_ : immutable_property_alist_;
189 SCM nm = get_property ("name");
190 if (scm_is_symbol (nm))
191 return ly_symbol2string (nm);
193 return this->class_name ();