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