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"
19 #include "simple-closure.hh"
22 Grob::get_property_alist_chain (SCM def) const
24 return scm_list_n (mutable_property_alist_,
25 immutable_property_alist_,
31 extern void check_interfaces_for_property (Grob const *me, SCM sym);
34 Grob::internal_set_property (SCM sym, SCM v)
37 SCM grob_p = ly_lily_module_constant ("ly:grob?");
38 SCM grob_list_p = ly_lily_module_constant ("grob-list?");
39 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
42 || type == grob_list_p
43 || (unsmob_grob (v) && ly_symbol2scm ("cause") != sym))
45 scm_display (scm_list_2 (sym, type), scm_current_output_port ());
50 /* Perhaps we simply do the assq_set, but what the heck. */
54 if (do_internal_type_checking_global)
56 if (!ly_is_procedure (v)
57 && !is_simple_closure (v)
58 && v != ly_symbol2scm ("calculation-in-progress")
59 && !type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
61 check_interfaces_for_property (this, sym);
64 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, v);
67 //#define PROFILE_PROPERTY_ACCESSES
69 Grob::get_property_data (SCM sym) const
72 if (profile_property_accesses)
73 note_property_access (&grob_property_lookup_table, sym);
76 SCM handle = scm_sloppy_assq (sym, mutable_property_alist_);
77 if (handle != SCM_BOOL_F)
78 return scm_cdr (handle);
80 handle = scm_sloppy_assq (sym, immutable_property_alist_);
82 if (do_internal_type_checking_global && scm_is_pair (handle))
84 SCM val = scm_cdr (handle);
85 if (!ly_is_procedure (val)
86 && !is_simple_closure (val)
87 && !type_check_assignment (sym, val,
88 ly_symbol2scm ("backend-type?")))
91 check_interfaces_for_property (this, sym);
94 return (handle == SCM_BOOL_F) ? SCM_EOL : scm_cdr (handle);
98 Grob::internal_get_property (SCM sym) const
100 SCM val = get_property_data (sym);
101 if (ly_is_procedure (val)
102 || is_simple_closure (val))
104 val = ((Grob*)this)->try_callback (sym, val);
111 #include "protected-scm.hh"
113 Protected_scm grob_property_callback_stack = SCM_EOL;
114 bool debug_property_callbacks = 0;
118 Grob::try_callback (SCM sym, SCM proc)
120 SCM marker = ly_symbol2scm ("calculation-in-progress");
122 need to put a value in SYM to ensure that we don't get a
125 mutable_property_alist_
126 = scm_assq_set_x (mutable_property_alist_, sym, marker);
129 if (debug_property_callbacks)
130 grob_property_callback_stack = scm_acons (sym, proc, grob_property_callback_stack);
134 if (ly_is_procedure (proc))
135 value = scm_call_1 (proc, self_scm ());
136 else if (is_simple_closure (proc))
138 value = evaluate_with_simple_closure (self_scm (),
139 simple_closure_expression (proc));
142 if (debug_property_callbacks)
143 grob_property_callback_stack = scm_cdr (grob_property_callback_stack);
147 If the function returns SCM_UNSPECIFIED, we assume the
148 property has been set with an explicit set_property()
151 if (value == SCM_UNSPECIFIED)
153 value = internal_get_property (sym);
155 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, marker);
158 internal_set_property (sym, value);
164 Grob::internal_set_object (SCM s, SCM v)
166 /* Perhaps we simply do the assq_set, but what the heck. */
170 object_alist_ = scm_assq_set_x (object_alist_, s, v);
174 Grob::del_property (SCM sym)
176 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, sym);
180 Grob::internal_get_object (SCM sym) const
182 #ifdef PROFILE_PROPERTY_ACCESSES
183 note_property_access (&grob_property_lookup_table, sym);
186 SCM s = scm_sloppy_assq (sym, object_alist_);
188 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
192 Grob::is_live () const
194 return immutable_property_alist_ != SCM_EOL;
199 Grob::internal_has_interface (SCM k)
201 return scm_c_memq (k, interfaces_) != SCM_BOOL_F;