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?");
17 IMPLEMENT_DEFAULT_EQUAL_P (Prob);
19 Prob::Prob (SCM type, SCM immutable_init)
22 mutable_property_alist_ = SCM_EOL;
23 immutable_property_alist_ = immutable_init;
32 Prob::Prob (Prob const &src)
34 immutable_property_alist_ = src.immutable_property_alist_;
35 mutable_property_alist_ = SCM_EOL;
39 /* First we smobify_self, then we copy over the stuff. If we don't,
40 stack vars that hold the copy might be optimized away, meaning
41 that they won't be protected from GC. */
43 mutable_property_alist_ = src.copy_mutable_properties ();
48 Prob::copy_mutable_properties () const
50 return ly_deep_copy (mutable_property_alist_);
54 Prob::derived_mark () const
59 Prob::mark_smob (SCM smob)
61 Prob *system = (Prob *) SCM_CELL_WORD_1 (smob);
62 scm_gc_mark (system->mutable_property_alist_);
63 system->derived_mark ();
65 return system->immutable_property_alist_;
69 Prob::print_smob (SCM smob, SCM port, scm_print_state*)
71 Prob *p = (Prob *) SCM_CELL_WORD_1 (smob);
72 scm_puts ("#<", port);
73 scm_puts ("Prob: ", port);
74 scm_display (p->type_, port);
75 scm_puts (" C++: ", port);
76 scm_puts (p->class_name (), port);
77 scm_display (p->mutable_property_alist_, port);
78 scm_display (p->immutable_property_alist_, port);
80 scm_puts (" >\n", port);
87 Prob::internal_get_property (SCM sym) const
92 SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
96 s = scm_sloppy_assq (sym, immutable_property_alist_);
97 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
101 Prob::internal_set_property (SCM sym, SCM val)
103 if (do_internal_type_checking_global)
104 type_check_assignment (sym, val);
106 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, val);
110 Prob::type_check_assignment (SCM sym, SCM val) const
117 Prob::get_property_alist (bool m) const
119 return (m) ? mutable_property_alist_ : immutable_property_alist_;
125 SCM nm = get_property ("name");
126 if (scm_is_symbol (nm))
127 return ly_symbol2string (nm);
129 return this->class_name ();