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 Grob::get_interfaces () const
37 extern void check_interfaces_for_property (Grob const *me, SCM sym);
40 Grob::internal_set_property (SCM sym, SCM v)
43 SCM grob_p = ly_lily_module_constant ("ly:grob?");
44 SCM grob_list_p = ly_lily_module_constant ("grob-list?");
45 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
48 || type == grob_list_p
49 || (unsmob_grob (v) && ly_symbol2scm ("cause") != sym))
51 scm_display (scm_list_2 (sym, type), scm_current_output_port ());
56 /* Perhaps we simply do the assq_set, but what the heck. */
60 if (do_internal_type_checking_global)
62 if (!ly_is_procedure (v)
63 && !type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
65 check_interfaces_for_property (this, sym);
68 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, v);
71 //#define PROFILE_PROPERTY_ACCESSES
73 Grob::get_property_data (SCM sym) const
76 if (profile_property_accesses)
77 note_property_access (&grob_property_lookup_table, sym);
80 SCM handle = scm_sloppy_assq (sym, mutable_property_alist_);
81 if (handle != SCM_BOOL_F)
82 return scm_cdr (handle);
84 handle = scm_sloppy_assq (sym, immutable_property_alist_);
86 if (do_internal_type_checking_global && scm_is_pair (handle))
88 SCM val = scm_cdr (handle);
89 if (!ly_is_procedure (val)
90 && !type_check_assignment (sym, val,
91 ly_symbol2scm ("backend-type?")))
94 check_interfaces_for_property (this, sym);
97 return (handle == SCM_BOOL_F) ? SCM_EOL : scm_cdr (handle);
101 Grob::internal_get_property (SCM sym) const
103 SCM val = get_property_data (sym);
104 if (ly_is_procedure (val)
105 || is_callback_chain (val)
106 || is_simple_closure (val))
108 val = ((Grob*)this)->try_callback (sym, val);
115 #include "protected-scm.hh"
116 Protected_scm grob_property_callback_stack = SCM_EOL;
117 bool debug_property_callbacks = 0;
121 Grob::try_callback (SCM sym, SCM proc)
123 SCM marker = ly_symbol2scm ("calculation-in-progress");
125 need to put a value in SYM to ensure that we don't get a
128 mutable_property_alist_
129 = scm_assq_set_x (mutable_property_alist_, sym, marker);
132 if (debug_property_callbacks)
133 grob_property_callback_stack = scm_acons (sym, proc, grob_property_callback_stack);
137 if (ly_is_procedure (proc))
138 value = scm_call_1 (proc, self_scm ());
139 else if (is_simple_closure (proc))
141 value = evaluate_with_simple_closure (self_scm (),
142 simple_closure_expression (proc));
145 if (debug_property_callbacks)
146 grob_property_callback_stack = scm_cdr (grob_property_callback_stack);
150 If the function returns SCM_UNSPECIFIED, we assume the
151 property has been set with an explicit set_property()
154 if (value == SCM_UNSPECIFIED)
156 value = internal_get_property (sym);
158 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, marker);
161 internal_set_property (sym, value);
167 Grob::internal_set_object (SCM s, SCM v)
169 /* Perhaps we simply do the assq_set, but what the heck. */
173 object_alist_ = scm_assq_set_x (object_alist_, s, v);
177 Grob::del_property (SCM sym)
179 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, sym);
183 Grob::internal_get_object (SCM sym) const
185 #ifdef PROFILE_PROPERTY_ACCESSES
186 note_property_access (&grob_property_lookup_table, sym);
189 SCM s = scm_sloppy_assq (sym, object_alist_);
191 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
195 Grob::substitute_object_links (SCM crit, SCM orig)
197 set_break_subsititution (crit);
198 object_alist_ = substitute_object_alist (orig, object_alist_);
202 Grob::is_live () const
204 return immutable_property_alist_ != SCM_EOL;