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;
33 Prob::Prob (Prob const &src)
35 immutable_property_alist_ = src.immutable_property_alist_;
36 mutable_property_alist_ = SCM_EOL;
40 /* First we smobify_self, then we copy over the stuff. If we don't,
41 stack vars that hold the copy might be optimized away, meaning
42 that they won't be protected from GC. */
44 mutable_property_alist_ = src.copy_mutable_properties ();
49 Prob::copy_mutable_properties () const
51 return ly_deep_copy (mutable_property_alist_);
55 Prob::derived_mark () const
60 Prob::mark_smob (SCM smob)
62 Prob *system = (Prob *) SCM_CELL_WORD_1 (smob);
63 scm_gc_mark (system->mutable_property_alist_);
64 system->derived_mark ();
66 return system->immutable_property_alist_;
70 Prob::print_smob (SCM smob, SCM port, scm_print_state*)
72 Prob *p = (Prob *) SCM_CELL_WORD_1 (smob);
73 scm_puts ("#<", port);
74 scm_puts ("Prob: ", port);
75 scm_display (p->type_, port);
76 scm_puts (" C++: ", port);
77 scm_puts (p->class_name (), port);
78 scm_display (p->mutable_property_alist_, port);
79 scm_display (p->immutable_property_alist_, port);
81 scm_puts (" >\n", port);
88 Prob::internal_get_property (SCM sym) const
93 SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
97 s = scm_sloppy_assq (sym, immutable_property_alist_);
98 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
102 Prob::internal_set_property (SCM sym, SCM val)
104 if (do_internal_type_checking_global)
105 type_check_assignment (sym, val);
107 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, val);
111 Prob::type_check_assignment (SCM sym, SCM val) const
118 Prob::get_property_alist (bool m) const
120 return (m) ? mutable_property_alist_ : immutable_property_alist_;
126 SCM nm = get_property ("name");
127 if (scm_is_symbol (nm))
128 return ly_symbol2string (nm);
130 return this->class_name ();