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