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 (!ly_is_procedure (v)
92 && !type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
94 check_interfaces_for_property (this, sym);
97 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, v);
100 //#define PROFILE_PROPERTY_ACCESSES
105 Retrieve property without triggering callback.
108 Grob::get_property_data (SCM sym) const
111 if (profile_property_accesses)
112 note_property_access (&grob_property_lookup_table, sym);
115 SCM handle = scm_sloppy_assq (sym, mutable_property_alist_);
116 if (handle != SCM_BOOL_F)
117 return scm_cdr (handle);
119 handle = scm_sloppy_assq (sym, immutable_property_alist_);
121 if (do_internal_type_checking_global && scm_is_pair (handle))
123 SCM val = scm_cdr (handle);
124 if (!ly_is_procedure (val)
125 && !type_check_assignment (sym, val,
126 ly_symbol2scm ("backend-type?")))
129 check_interfaces_for_property (this, sym);
132 return (handle == SCM_BOOL_F) ? SCM_EOL : scm_cdr (handle);
136 Grob::internal_get_property (SCM sym) const
138 SCM val = get_property_data (sym);
139 if (ly_is_procedure (val))
141 val = ((Grob*)this)->try_callback (sym, val);
148 #include "protected-scm.hh"
149 Protected_scm grob_property_callback_stack = SCM_EOL;
150 bool debug_property_callbacks = 1;
154 Grob::try_callback (SCM sym, SCM proc)
156 SCM marker = ly_symbol2scm ("calculation-in-progress");
158 need to put a value in SYM to ensure that we don't get a
161 mutable_property_alist_
162 = scm_assq_set_x (mutable_property_alist_, sym, marker);
165 if (debug_property_callbacks)
166 grob_property_callback_stack = scm_acons (sym, proc, grob_property_callback_stack);
168 SCM value = scm_call_1 (proc, self_scm ());
170 if (debug_property_callbacks)
171 grob_property_callback_stack = scm_cdr (grob_property_callback_stack);
175 If the function returns SCM_UNSPECIFIED, we assume the
176 property has been set with an explicit set_property()
179 if (value == SCM_UNSPECIFIED)
181 value = internal_get_property (sym);
183 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, marker);
186 internal_set_property (sym, value);
192 Grob::internal_set_object (SCM s, SCM v)
194 /* Perhaps we simply do the assq_set, but what the heck. */
198 object_alist_ = scm_assq_set_x (object_alist_, s, v);
202 Grob::del_property (SCM sym)
204 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, sym);
208 Grob::internal_get_object (SCM sym) const
210 #ifdef PROFILE_PROPERTY_ACCESSES
211 note_property_access (&grob_property_lookup_table, sym);
214 SCM s = scm_sloppy_assq (sym, object_alist_);
216 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
220 Grob::substitute_object_links (SCM crit, SCM orig)
222 set_break_subsititution (crit);
223 object_alist_ = substitute_object_alist (orig, object_alist_);
227 Grob::is_live () const
229 return immutable_property_alist_ != SCM_EOL;