]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-property.cc
d912621dac89f105b2269b6de042f3669dc9001a
[lilypond.git] / lily / grob-property.cc
1 /*
2   Implement storage and manipulation of grob properties.
3  */
4
5 #include <cstring>
6 #include <math.h>
7
8 #include "main.hh"
9 #include "input-smob.hh"
10 #include "group-interface.hh"
11 #include "misc.hh"
12 #include "paper-score.hh"
13 #include "output-def.hh"
14 #include "spanner.hh"
15 #include "item.hh"
16 #include "misc.hh"
17 #include "item.hh"
18
19
20 SCM
21 Grob::get_property_alist_chain (SCM def) const
22 {
23   return scm_list_n (mutable_property_alist_,
24                      immutable_property_alist_,
25                      def,
26                      SCM_UNDEFINED);
27 }
28
29
30
31 /*
32   This special add_thing routine is slightly more efficient than
33
34     set_prop (name, cons (thing, get_prop (name)))
35
36   since it can reuse the handle returned by scm_assq ().
37 */
38 void
39 Grob::add_to_list_property (SCM sym, SCM thing) 
40 {
41   SCM handle
42     = scm_sloppy_assq (sym, mutable_property_alist_)
43     ;
44
45   if (handle != SCM_BOOL_F)
46     {
47       scm_set_cdr_x (handle, scm_cons (thing, scm_cdr (handle)));
48     }
49   else
50     {
51       /*
52         There is no mutable prop yet, so create an entry, and put it in front of the
53         mutable prop list.
54       */
55       handle = scm_sloppy_assq (sym, immutable_property_alist_);
56       SCM tail = (handle != SCM_BOOL_F) ? scm_cdr (handle) : SCM_EOL;
57       SCM val = scm_cons (thing, tail);
58
59       mutable_property_alist_ = scm_cons (scm_cons (sym, val),
60                                          mutable_property_alist_);
61     }
62 }
63
64
65 extern void check_interfaces_for_property (Grob const *me, SCM sym);
66
67 void
68 Grob::internal_set_property (SCM s, SCM v)
69 {
70   /* Perhaps we simply do the assq_set, but what the heck. */
71   if (!is_live ())
72     return;
73
74   if (do_internal_type_checking_global)
75     {
76       if (!type_check_assignment (s, v, ly_symbol2scm ("backend-type?")))
77         abort ();
78       check_interfaces_for_property (this, s);
79     }
80
81   mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, s, v);
82 }
83
84
85 SCM
86 Grob::internal_get_property (SCM sym) const
87 {
88   SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
89   if (s != SCM_BOOL_F)
90     return scm_cdr (s);
91
92   s = scm_sloppy_assq (sym, immutable_property_alist_);
93   
94   if (do_internal_type_checking_global && scm_is_pair (s))
95     {
96       if (!type_check_assignment (sym, scm_cdr (s),
97                                   ly_symbol2scm ("backend-type?")))
98         abort ();
99
100       check_interfaces_for_property (this, sym);
101     }
102
103   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s); 
104 }
105
106 void
107 Grob::substitute_mutable_properties (SCM crit, SCM orig)
108 {
109   set_break_subsititution (crit);
110   mutable_property_alist_ = substitute_mutable_property_alist (orig);
111 }
112
113
114 bool
115 Grob::is_live () const
116 {
117   return immutable_property_alist_ != SCM_EOL;
118 }