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