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 && !type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
60 check_interfaces_for_property (this, sym);
63 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, v);
66 //#define PROFILE_PROPERTY_ACCESSES
68 Grob::get_property_data (SCM sym) const
71 if (profile_property_accesses)
72 note_property_access (&grob_property_lookup_table, sym);
75 SCM handle = scm_sloppy_assq (sym, mutable_property_alist_);
76 if (handle != SCM_BOOL_F)
77 return scm_cdr (handle);
79 handle = scm_sloppy_assq (sym, immutable_property_alist_);
81 if (do_internal_type_checking_global && scm_is_pair (handle))
83 SCM val = scm_cdr (handle);
84 if (!ly_is_procedure (val)
85 && !is_simple_closure (val)
86 && !type_check_assignment (sym, val,
87 ly_symbol2scm ("backend-type?")))
90 check_interfaces_for_property (this, sym);
93 return (handle == SCM_BOOL_F) ? SCM_EOL : scm_cdr (handle);
97 Grob::internal_get_property (SCM sym) const
99 SCM val = get_property_data (sym);
100 if (ly_is_procedure (val)
101 || is_simple_closure (val))
103 val = ((Grob*)this)->try_callback (sym, val);
110 #include "protected-scm.hh"
112 Protected_scm grob_property_callback_stack = SCM_EOL;
113 bool debug_property_callbacks = 0;
117 Grob::try_callback (SCM sym, SCM proc)
119 SCM marker = ly_symbol2scm ("calculation-in-progress");
121 need to put a value in SYM to ensure that we don't get a
124 mutable_property_alist_
125 = scm_assq_set_x (mutable_property_alist_, sym, marker);
128 if (debug_property_callbacks)
129 grob_property_callback_stack = scm_acons (sym, proc, grob_property_callback_stack);
133 if (ly_is_procedure (proc))
134 value = scm_call_1 (proc, self_scm ());
135 else if (is_simple_closure (proc))
137 value = evaluate_with_simple_closure (self_scm (),
138 simple_closure_expression (proc));
141 if (debug_property_callbacks)
142 grob_property_callback_stack = scm_cdr (grob_property_callback_stack);
146 If the function returns SCM_UNSPECIFIED, we assume the
147 property has been set with an explicit set_property()
150 if (value == SCM_UNSPECIFIED)
152 value = internal_get_property (sym);
154 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, marker);
157 internal_set_property (sym, value);
163 Grob::internal_set_object (SCM s, SCM v)
165 /* Perhaps we simply do the assq_set, but what the heck. */
169 object_alist_ = scm_assq_set_x (object_alist_, s, v);
173 Grob::del_property (SCM sym)
175 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, sym);
179 Grob::internal_get_object (SCM sym) const
181 #ifdef PROFILE_PROPERTY_ACCESSES
182 note_property_access (&grob_property_lookup_table, sym);
185 SCM s = scm_sloppy_assq (sym, object_alist_);
187 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
191 Grob::is_live () const
193 return immutable_property_alist_ != SCM_EOL;
198 Grob::internal_has_interface (SCM k)
200 return scm_c_memq (k, interfaces_) != SCM_BOOL_F;