]> git.donarmstrong.com Git - lilypond.git/blob - lily/prob.cc
* lily/music.cc (derived_mark): derive Music from Prob.
[lilypond.git] / lily / prob.cc
1 /*
2   paper-system.cc -- implement Paper_system
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 immutable_init)
20 {
21   self_scm_ = SCM_EOL;
22   mutable_property_alist_ = SCM_EOL;
23   immutable_property_alist_ = immutable_init;
24   smobify_self ();
25 }
26
27 Prob::~Prob ()
28 {
29 }
30
31 Prob::Prob (Prob const &src)
32 {
33   immutable_property_alist_ = src.immutable_property_alist_;
34   mutable_property_alist_ = SCM_EOL;
35   self_scm_ = SCM_EOL;
36
37   /* First we smobify_self, then we copy over the stuff.  If we don't,
38      stack vars that hold the copy might be optimized away, meaning
39      that they won't be protected from GC. */
40   smobify_self ();
41   mutable_property_alist_ = src.copy_mutable_properties ();
42 }
43
44
45 SCM
46 Prob::copy_mutable_properties () const
47 {
48   return ly_deep_copy (mutable_property_alist_);
49 }
50
51 void
52 Prob::derived_mark () const
53 {
54 }
55
56 SCM
57 Prob::mark_smob (SCM smob)
58 {
59   Prob *system = (Prob *) SCM_CELL_WORD_1 (smob);
60   scm_gc_mark (system->mutable_property_alist_);
61   system->derived_mark ();
62   
63   return system->immutable_property_alist_;
64 }
65
66 int
67 Prob::print_smob (SCM smob, SCM port, scm_print_state*)
68 {
69   Prob *p = (Prob *) SCM_CELL_WORD_1 (smob);
70   scm_puts ("#<", port);
71   scm_puts ("Prob: ", port);
72
73   
74   scm_puts (p->class_name (), port);
75   scm_display (p->mutable_property_alist_, port);
76   scm_display (p->immutable_property_alist_, port);
77   
78   scm_puts (" >\n", port);
79   return 1;
80 }
81
82
83
84 SCM
85 Prob::internal_get_property (SCM sym) const
86 {
87   /*
88     TODO: type checking
89    */
90   SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
91   if (s != SCM_BOOL_F)
92     return scm_cdr (s);
93
94   s = scm_sloppy_assq (sym, immutable_property_alist_);
95   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
96 }
97
98 void
99 Prob::internal_set_property (SCM sym, SCM val) 
100 {
101   if (do_internal_type_checking_global)
102     type_check_assignment (sym, val);
103   
104   mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, val);
105 }
106
107 void
108 Prob::type_check_assignment (SCM sym, SCM val) const
109 {
110   (void) sym;
111   (void) val;
112 }
113
114 SCM
115 Prob::get_property_alist (bool m) const
116 {
117   return (m) ? mutable_property_alist_ : immutable_property_alist_;
118 }
119
120 String
121 Prob::name () const
122 {
123   SCM nm = get_property ("name");
124   if (scm_is_symbol (nm))
125     return ly_symbol2string (nm);
126   else
127     return this->class_name ();
128 }
129