]> git.donarmstrong.com Git - lilypond.git/blob - lily/prob.cc
bff24e5adeb5d998d58d6deaa3e00f50e3a6e8d2
[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
29 Prob::~Prob ()
30 {
31 }
32
33 Prob::Prob (Prob const &src)
34 {
35   immutable_property_alist_ = src.immutable_property_alist_;
36   mutable_property_alist_ = SCM_EOL;
37   self_scm_ = SCM_EOL;
38   type_ = src.type_;
39
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. */
43   smobify_self ();
44   mutable_property_alist_ = src.copy_mutable_properties ();
45 }
46
47
48 SCM
49 Prob::copy_mutable_properties () const
50 {
51   return ly_deep_copy (mutable_property_alist_);
52 }
53
54 void
55 Prob::derived_mark () const
56 {
57 }
58
59 SCM
60 Prob::mark_smob (SCM smob)
61 {
62   Prob *system = (Prob *) SCM_CELL_WORD_1 (smob);
63   scm_gc_mark (system->mutable_property_alist_);
64   system->derived_mark ();
65   
66   return system->immutable_property_alist_;
67 }
68
69 int
70 Prob::print_smob (SCM smob, SCM port, scm_print_state*)
71 {
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);
80   
81   scm_puts (" >\n", port);
82   return 1;
83 }
84
85
86
87 SCM
88 Prob::internal_get_property (SCM sym) const
89 {
90   /*
91     TODO: type checking
92    */
93   SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
94   if (s != SCM_BOOL_F)
95     return scm_cdr (s);
96
97   s = scm_sloppy_assq (sym, immutable_property_alist_);
98   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
99 }
100
101 void
102 Prob::internal_set_property (SCM sym, SCM val
103 #ifndef NDEBUG
104                              , char const *file, int line, char const *fun
105 #endif
106                              ) 
107 {
108   if (do_internal_type_checking_global)
109     type_check_assignment (sym, val);
110   
111   mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, val);
112 }
113
114 void
115 Prob::type_check_assignment (SCM sym, SCM val) const
116 {
117   (void) sym;
118   (void) val;
119 }
120
121 SCM
122 Prob::get_property_alist (bool m) const
123 {
124   return (m) ? mutable_property_alist_ : immutable_property_alist_;
125 }
126
127 string
128 Prob::name () const
129 {
130   SCM nm = get_property ("name");
131   if (scm_is_symbol (nm))
132     return ly_symbol2string (nm);
133   else
134     return this->class_name ();
135 }
136