2 prob.cc -- implement Prob
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2006 Jan Nieuwenhuizen <janneke@gnu.org>
13 #include "ly-smobs.icc"
15 IMPLEMENT_SMOBS (Prob);
16 IMPLEMENT_TYPE_P (Prob, "ly:prob?");
19 Prob::equal_p (SCM sa, SCM sb)
21 /* This comparison function is only designed to make the copy
22 constructor preserve equality.
24 Perhaps it would be better to use a more strict definition of
25 equality; e.g., that that two probs are equal iff they can be
26 distinguished by calls to ly:prob-property.
28 Prob *probs[2] = {unsmob_prob (sa), unsmob_prob (sb)};
32 for (i = 0; i < 2; i++)
34 props[i][0] = probs[i]->immutable_property_alist_;
35 props[i][1] = probs[i]->mutable_property_alist_;
38 if (strcmp (probs[0]->class_name (), probs[1]->class_name ()))
41 /* Compare mutable and immutable lists, element by element. */
42 for (i = 0; i < 2; i++)
44 SCM aprop = props[0][i], bprop = props[1][i];
46 for (; scm_is_pair (aprop) && scm_is_pair(bprop); aprop = scm_cdr (aprop), bprop = scm_cdr (bprop))
48 if (scm_caar (aprop) != scm_caar (bprop) ||
49 !to_boolean (scm_equal_p (scm_cdar (aprop), scm_cdar (bprop))))
53 /* is one list shorter? */
54 if (aprop != SCM_EOL || bprop != SCM_EOL)
61 Prob::Prob (SCM type, SCM immutable_init)
64 mutable_property_alist_ = SCM_EOL;
65 immutable_property_alist_ = immutable_init;
75 Prob::Prob (Prob const &src)
77 immutable_property_alist_ = src.immutable_property_alist_;
78 mutable_property_alist_ = SCM_EOL;
82 /* First we smobify_self, then we copy over the stuff. If we don't,
83 stack vars that hold the copy might be optimized away, meaning
84 that they won't be protected from GC. */
86 mutable_property_alist_ = src.copy_mutable_properties ();
91 Prob::copy_mutable_properties () const
93 return ly_deep_copy (mutable_property_alist_);
97 Prob::derived_mark () const
102 Prob::mark_smob (SCM smob)
104 Prob *system = (Prob *) SCM_CELL_WORD_1 (smob);
105 scm_gc_mark (system->mutable_property_alist_);
106 system->derived_mark ();
108 return system->immutable_property_alist_;
112 Prob::print_smob (SCM smob, SCM port, scm_print_state*)
114 Prob *p = (Prob *) SCM_CELL_WORD_1 (smob);
115 scm_puts ("#<", port);
116 scm_puts ("Prob: ", port);
117 scm_display (p->type_, port);
118 scm_puts (" C++: ", port);
119 scm_puts (p->class_name (), port);
120 scm_display (p->mutable_property_alist_, port);
121 scm_display (p->immutable_property_alist_, port);
123 scm_puts (" >\n", port);
130 Prob::internal_get_property (SCM sym) const
135 SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
139 s = scm_sloppy_assq (sym, immutable_property_alist_);
140 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
144 Prob::internal_set_property (SCM sym, SCM val
146 , char const *file, int line, char const *fun
156 if (do_internal_type_checking_global)
157 type_check_assignment (sym, val);
159 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, val);
163 Prob::type_check_assignment (SCM sym, SCM val) const
170 Prob::get_property_alist (bool m) const
172 return (m) ? mutable_property_alist_ : immutable_property_alist_;
178 SCM nm = get_property ("name");
179 if (scm_is_symbol (nm))
180 return ly_symbol2string (nm);
182 return this->class_name ();