2 prob.cc -- implement Prob
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2007 Jan Nieuwenhuizen <janneke@gnu.org>
15 #include "ly-smobs.icc"
17 IMPLEMENT_SMOBS (Prob);
18 IMPLEMENT_TYPE_P (Prob, "ly:prob?");
21 Prob::equal_p (SCM sa, SCM sb)
23 /* This comparison function is only designed to make the copy
24 constructor preserve equality.
26 Perhaps it would be better to use a more strict definition of
27 equality; e.g., that that two probs are equal iff they can be
28 distinguished by calls to ly:prob-property.
30 Prob *probs[2] = {unsmob_prob (sa), unsmob_prob (sb)};
34 for (i = 0; i < 2; i++)
36 props[i][0] = probs[i]->immutable_property_alist_;
37 props[i][1] = probs[i]->mutable_property_alist_;
40 if (strcmp (probs[0]->class_name (), probs[1]->class_name ()))
43 /* Compare mutable and immutable lists, element by element. */
44 for (i = 0; i < 2; i++)
46 SCM aprop = props[0][i];
47 SCM bprop = props[1][i];
50 scm_is_pair (aprop) && scm_is_pair(bprop);
51 aprop = scm_cdr (aprop), bprop = scm_cdr (bprop))
53 SCM aval = scm_cdar (aprop);
54 SCM bval = scm_cdar (bprop);
55 if (scm_caar (aprop) != scm_caar (bprop) ||
57 !(unsmob_input (aval) && unsmob_input (bval))
59 !to_boolean (scm_equal_p (aval, bval))))
63 /* is one list shorter? */
64 if (aprop != SCM_EOL || bprop != SCM_EOL)
71 Prob::Prob (SCM type, SCM immutable_init)
74 mutable_property_alist_ = SCM_EOL;
75 immutable_property_alist_ = immutable_init;
85 Prob::Prob (Prob const &src)
87 immutable_property_alist_ = src.immutable_property_alist_;
88 mutable_property_alist_ = SCM_EOL;
92 /* First we smobify_self, then we copy over the stuff. If we don't,
93 stack vars that hold the copy might be optimized away, meaning
94 that they won't be protected from GC. */
96 mutable_property_alist_ = src.copy_mutable_properties ();
101 Prob::copy_mutable_properties () const
103 return ly_deep_copy (mutable_property_alist_);
107 Prob::derived_mark () const
112 Prob::mark_smob (SCM smob)
114 ASSERT_LIVE_IS_ALLOWED();
116 Prob *system = (Prob *) SCM_CELL_WORD_1 (smob);
117 scm_gc_mark (system->mutable_property_alist_);
118 system->derived_mark ();
120 return system->immutable_property_alist_;
124 Prob::print_smob (SCM smob, SCM port, scm_print_state*)
126 Prob *p = (Prob *) SCM_CELL_WORD_1 (smob);
127 scm_puts ("#<", port);
128 scm_puts ("Prob: ", port);
129 scm_display (p->type_, port);
130 scm_puts (" C++: ", port);
131 scm_puts (p->class_name (), port);
132 scm_display (p->mutable_property_alist_, port);
133 scm_display (p->immutable_property_alist_, port);
135 scm_puts (" >\n", port);
142 Prob::internal_get_property (SCM sym) const
145 if (profile_property_accesses)
146 note_property_access (&prob_property_lookup_table, sym);
152 SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
156 s = scm_sloppy_assq (sym, immutable_property_alist_);
157 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
161 Prob::internal_set_property (SCM sym, SCM val
163 , char const *file, int line, char const *fun
173 if (do_internal_type_checking_global)
174 type_check_assignment (sym, val);
176 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, val);
180 Prob::type_check_assignment (SCM sym, SCM val) const
187 Prob::get_property_alist (bool m) const
189 return (m) ? mutable_property_alist_ : immutable_property_alist_;
195 SCM nm = get_property ("name");
196 if (scm_is_symbol (nm))
197 return ly_symbol2string (nm);
199 return this->class_name ();