2 Implement storage and manipulation of grob properties.
8 #include "input-smob.hh"
9 #include "pointer-group-interface.hh"
11 #include "paper-score.hh"
12 #include "output-def.hh"
17 #include "program-option.hh"
21 Grob::get_property_alist_chain (SCM def) const
23 return scm_list_n (mutable_property_alist_,
24 immutable_property_alist_,
30 Grob::get_interfaces () const
36 This special add_thing routine is slightly more efficient than
38 set_prop (name, cons (thing, get_prop (name)))
40 since it can reuse the handle returned by scm_assq ().
44 Grob::add_to_list_property (SCM sym, SCM thing)
47 = scm_sloppy_assq (sym, mutable_property_alist_);
49 if (handle != SCM_BOOL_F)
50 scm_set_cdr_x (handle, scm_cons (thing, scm_cdr (handle)));
54 There is no mutable prop yet, so create an entry, and put it in front of the
57 handle = scm_sloppy_assq (sym, immutable_property_alist_);
58 SCM tail = (handle != SCM_BOOL_F) ? scm_cdr (handle) : SCM_EOL;
59 SCM val = scm_cons (thing, tail);
61 mutable_property_alist_ = scm_cons (scm_cons (sym, val),
62 mutable_property_alist_);
66 extern void check_interfaces_for_property (Grob const *me, SCM sym);
69 Grob::internal_set_property (SCM sym, SCM v)
72 SCM grob_p = ly_lily_module_constant ("ly:grob?");
73 SCM grob_list_p = ly_lily_module_constant ("grob-list?");
74 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
77 || type == grob_list_p
78 || (unsmob_grob (v) && ly_symbol2scm ("cause") != sym))
80 scm_display (scm_list_2 (sym, type), scm_current_output_port ());
85 /* Perhaps we simply do the assq_set, but what the heck. */
89 if (do_internal_type_checking_global)
91 if (!type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
93 check_interfaces_for_property (this, sym);
96 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, v);
99 //#define PROFILE_PROPERTY_ACCESSES
104 Retrieve property without triggering callback.
107 Grob::get_property_data (SCM sym) const
110 if (profile_property_accesses)
111 note_property_access (&grob_property_lookup_table, sym);
114 SCM handle = scm_sloppy_assq (sym, mutable_property_alist_);
115 if (handle != SCM_BOOL_F)
116 return scm_cdr (handle);
118 handle = scm_sloppy_assq (sym, immutable_property_alist_);
120 if (do_internal_type_checking_global && scm_is_pair (handle))
122 if (!type_check_assignment (sym, scm_cdr (handle),
123 ly_symbol2scm ("backend-type?")))
126 check_interfaces_for_property (this, sym);
129 return (handle == SCM_BOOL_F) ? SCM_EOL : scm_cdr (handle);
133 Grob::internal_get_property (SCM sym) const
136 if (profile_property_accesses)
137 note_property_access (&grob_property_lookup_table, sym);
140 SCM handle = scm_sloppy_assq (sym, mutable_property_alist_);
141 if (handle != SCM_BOOL_F)
142 return scm_cdr (handle);
144 handle = scm_sloppy_assq (sym, immutable_property_alist_);
146 if (do_internal_type_checking_global && scm_is_pair (handle))
148 if (!type_check_assignment (sym, scm_cdr (handle),
149 ly_symbol2scm ("backend-type?")))
152 check_interfaces_for_property (this, sym);
156 if (handle == SCM_BOOL_F)
158 SCM value = ((Grob*) this)->try_callback (sym);
159 if (value != SCM_UNSPECIFIED)
163 return (handle == SCM_BOOL_F) ? SCM_EOL : scm_cdr (handle);
167 #include "protected-scm.hh"
168 Protected_scm grob_property_callback_stack = SCM_EOL;
169 bool debug_property_callbacks = 1;
173 Grob::try_callback (SCM sym)
175 SCM handle = scm_sloppy_assq (sym, property_callbacks_);
176 if (scm_is_pair (handle))
178 SCM proc = scm_cdr (handle);
179 if (ly_is_procedure (proc))
181 SCM marker = ly_symbol2scm ("calculation-in-progress");
183 need to put a value in SYM to ensure that we don't get a
186 mutable_property_alist_
187 = scm_assq_set_x (mutable_property_alist_, sym, marker);
190 if (debug_property_callbacks)
191 grob_property_callback_stack = scm_acons (sym, proc, grob_property_callback_stack);
193 SCM value = scm_call_1 (proc, self_scm ());
195 if (debug_property_callbacks)
196 grob_property_callback_stack = scm_cdr (grob_property_callback_stack);
200 If the function returns SCM_UNSPECIFIED, we assume the
201 property has been set with an explicit set_property()
204 if (value == SCM_UNSPECIFIED)
206 value = internal_get_property (sym);
208 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, marker);
211 internal_set_property (sym, value);
216 programming_error ("Callback should be procedure type");
219 return SCM_UNSPECIFIED;
223 Grob::internal_set_object (SCM s, SCM v)
225 /* Perhaps we simply do the assq_set, but what the heck. */
229 object_alist_ = scm_assq_set_x (object_alist_, s, v);
233 Grob::set_callback (SCM s, SCM v)
235 /* Perhaps we simply do the assq_set, but what the heck. */
240 property_callbacks_ is r/o in principle, so we tack it in front.
242 property_callbacks_ = scm_acons (s,v, property_callbacks_);
248 Grob::internal_get_object (SCM sym) const
250 #ifdef PROFILE_PROPERTY_ACCESSES
251 note_property_access (&grob_property_lookup_table, sym);
254 SCM s = scm_sloppy_assq (sym, object_alist_);
256 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
260 Grob::substitute_object_links (SCM crit, SCM orig)
262 set_break_subsititution (crit);
263 object_alist_ = substitute_object_alist (orig, object_alist_);
267 Grob::is_live () const
269 return immutable_property_alist_ != SCM_EOL;