]> git.donarmstrong.com Git - lilypond.git/blob - lily/prob.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / prob.cc
1 /*
2   prob.cc -- implement Prob
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "prob.hh"
10 #include "main.hh"
11 #include "item.hh"
12
13 #include "ly-smobs.icc"
14
15 IMPLEMENT_SMOBS (Prob);
16 IMPLEMENT_TYPE_P (Prob, "ly:prob?");
17 IMPLEMENT_DEFAULT_EQUAL_P (Prob);
18
19 Prob::Prob (SCM type, SCM immutable_init)
20 {
21   self_scm_ = SCM_EOL;
22   mutable_property_alist_ = SCM_EOL;
23   immutable_property_alist_ = immutable_init;
24   type_ = type;
25   smobify_self ();
26 }
27
28 Prob::~Prob ()
29 {
30 }
31
32 Prob::Prob (Prob const &src)
33 {
34   immutable_property_alist_ = src.immutable_property_alist_;
35   mutable_property_alist_ = SCM_EOL;
36   self_scm_ = SCM_EOL;
37   type_ = src.type_;
38
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. */
42   smobify_self ();
43   mutable_property_alist_ = src.copy_mutable_properties ();
44 }
45
46
47 SCM
48 Prob::copy_mutable_properties () const
49 {
50   return ly_deep_copy (mutable_property_alist_);
51 }
52
53 void
54 Prob::derived_mark () const
55 {
56 }
57
58 SCM
59 Prob::mark_smob (SCM smob)
60 {
61   Prob *system = (Prob *) SCM_CELL_WORD_1 (smob);
62   scm_gc_mark (system->mutable_property_alist_);
63   system->derived_mark ();
64   
65   return system->immutable_property_alist_;
66 }
67
68 int
69 Prob::print_smob (SCM smob, SCM port, scm_print_state*)
70 {
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);
79   
80   scm_puts (" >\n", port);
81   return 1;
82 }
83
84
85
86 SCM
87 Prob::internal_get_property (SCM sym) const
88 {
89   /*
90     TODO: type checking
91    */
92   SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
93   if (s != SCM_BOOL_F)
94     return scm_cdr (s);
95
96   s = scm_sloppy_assq (sym, immutable_property_alist_);
97   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
98 }
99
100 void
101 Prob::internal_set_property (SCM sym, SCM val) 
102 {
103   if (do_internal_type_checking_global)
104     type_check_assignment (sym, val);
105   
106   mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, val);
107 }
108
109 void
110 Prob::type_check_assignment (SCM sym, SCM val) const
111 {
112   (void) sym;
113   (void) val;
114 }
115
116 SCM
117 Prob::get_property_alist (bool m) const
118 {
119   return (m) ? mutable_property_alist_ : immutable_property_alist_;
120 }
121
122 string
123 Prob::name () const
124 {
125   SCM nm = get_property ("name");
126   if (scm_is_symbol (nm))
127     return ly_symbol2string (nm);
128   else
129     return this->class_name ();
130 }
131