]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-property.cc
* lily/tie-column.cc (set_manual_tie_configuration): new function.
[lilypond.git] / lily / grob-property.cc
1 /*
2   Implement storage and manipulation of grob properties.
3 */
4
5 #include <cstring>
6 #include <cmath>
7 using namespace std;
8
9 #include "main.hh"
10 #include "input-smob.hh"
11 #include "pointer-group-interface.hh"
12 #include "misc.hh"
13 #include "paper-score.hh"
14 #include "output-def.hh"
15 #include "spanner.hh"
16 #include "item.hh"
17 #include "misc.hh"
18 #include "item.hh"
19 #include "program-option.hh"
20 #include "profile.hh"
21
22 SCM
23 Grob::get_property_alist_chain (SCM def) const
24 {
25   return scm_list_n (mutable_property_alist_,
26                      immutable_property_alist_,
27                      def,
28                      SCM_UNDEFINED);
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 // JUNKME.
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   if (handle != SCM_BOOL_F)
46     scm_set_cdr_x (handle, scm_cons (thing, scm_cdr (handle)));
47   else
48     {
49       /*
50         There is no mutable prop yet, so create an entry, and put it in front of the
51         mutable prop list.
52       */
53       handle = scm_sloppy_assq (sym, immutable_property_alist_);
54       SCM tail = (handle != SCM_BOOL_F) ? scm_cdr (handle) : SCM_EOL;
55       SCM val = scm_cons (thing, tail);
56
57       mutable_property_alist_ = scm_cons (scm_cons (sym, val),
58                                           mutable_property_alist_);
59     }
60 }
61
62 extern void check_interfaces_for_property (Grob const *me, SCM sym);
63
64 void
65 Grob::internal_set_property (SCM sym, SCM v)
66 {
67 #ifndef NDEBUG
68   SCM grob_p = ly_lily_module_constant ("ly:grob?");
69   SCM grob_list_p = ly_lily_module_constant ("grob-list?");
70   SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
71
72   if (type == grob_p
73       || type == grob_list_p
74       || (unsmob_grob (v) && ly_symbol2scm ("cause") != sym))
75     {
76       scm_display (scm_list_2 (sym, type), scm_current_output_port ());
77       assert (0);
78     }
79 #endif
80
81   /* Perhaps we simply do the assq_set, but what the heck. */
82   if (!is_live ())
83     return;
84
85   if (do_internal_type_checking_global)
86     {
87       if (!type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
88         abort ();
89       check_interfaces_for_property (this, sym);
90     }
91
92   mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, v);
93 }
94
95 //#define PROFILE_PROPERTY_ACCESSES
96
97
98 SCM
99 Grob::internal_get_property (SCM sym) const
100 {
101 #ifndef NDEBUG
102   if (profile_property_accesses)
103     note_property_access (&grob_property_lookup_table, sym);
104 #endif
105
106   SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
107   if (s != SCM_BOOL_F)
108     return scm_cdr (s);
109
110   s = scm_sloppy_assq (sym, immutable_property_alist_);
111
112   if (do_internal_type_checking_global && scm_is_pair (s))
113     {
114       if (!type_check_assignment (sym, scm_cdr (s),
115                                   ly_symbol2scm ("backend-type?")))
116         abort ();
117
118       check_interfaces_for_property (this, sym);
119     }
120
121   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
122 }
123
124 void
125 Grob::internal_set_object (SCM s, SCM v)
126 {
127   /* Perhaps we simply do the assq_set, but what the heck. */
128   if (!is_live ())
129     return;
130
131   object_alist_ = scm_assq_set_x (object_alist_, s, v);
132 }
133
134 SCM
135 Grob::internal_get_object (SCM sym) const
136 {
137 #ifdef PROFILE_PROPERTY_ACCESSES
138   note_property_access (&grob_property_lookup_table, sym);
139 #endif
140
141   SCM s = scm_sloppy_assq (sym, object_alist_);
142
143   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
144 }
145
146 void
147 Grob::substitute_object_links (SCM crit, SCM orig)
148 {
149   set_break_subsititution (crit);
150   object_alist_ = substitute_object_alist (orig, object_alist_);
151 }
152
153 bool
154 Grob::is_live () const
155 {
156   return immutable_property_alist_ != SCM_EOL;
157 }