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 extern void check_interfaces_for_property (Grob const *me, SCM sym);
39 Grob::internal_set_property (SCM sym, SCM v)
42 SCM grob_p = ly_lily_module_constant ("ly:grob?");
43 SCM grob_list_p = ly_lily_module_constant ("grob-list?");
44 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
47 || type == grob_list_p
48 || (unsmob_grob (v) && ly_symbol2scm ("cause") != sym))
50 scm_display (scm_list_2 (sym, type), scm_current_output_port ());
55 /* Perhaps we simply do the assq_set, but what the heck. */
59 if (do_internal_type_checking_global)
61 if (!ly_is_procedure (v)
62 && !type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
64 check_interfaces_for_property (this, sym);
67 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, v);
70 //#define PROFILE_PROPERTY_ACCESSES
75 Retrieve property without triggering callback.
78 Grob::get_property_data (SCM sym) const
81 if (profile_property_accesses)
82 note_property_access (&grob_property_lookup_table, sym);
85 SCM handle = scm_sloppy_assq (sym, mutable_property_alist_);
86 if (handle != SCM_BOOL_F)
87 return scm_cdr (handle);
89 handle = scm_sloppy_assq (sym, immutable_property_alist_);
91 if (do_internal_type_checking_global && scm_is_pair (handle))
93 SCM val = scm_cdr (handle);
94 if (!ly_is_procedure (val)
95 && !type_check_assignment (sym, val,
96 ly_symbol2scm ("backend-type?")))
99 check_interfaces_for_property (this, sym);
102 return (handle == SCM_BOOL_F) ? SCM_EOL : scm_cdr (handle);
106 Grob::internal_get_property (SCM sym) const
108 SCM val = get_property_data (sym);
109 if (ly_is_procedure (val))
111 val = ((Grob*)this)->try_callback (sym, val);
118 #include "protected-scm.hh"
119 Protected_scm grob_property_callback_stack = SCM_EOL;
120 bool debug_property_callbacks = 0;
124 Grob::try_callback (SCM sym, SCM proc)
126 SCM marker = ly_symbol2scm ("calculation-in-progress");
128 need to put a value in SYM to ensure that we don't get a
131 mutable_property_alist_
132 = scm_assq_set_x (mutable_property_alist_, sym, marker);
135 if (debug_property_callbacks)
136 grob_property_callback_stack = scm_acons (sym, proc, grob_property_callback_stack);
138 SCM value = scm_call_1 (proc, self_scm ());
140 if (debug_property_callbacks)
141 grob_property_callback_stack = scm_cdr (grob_property_callback_stack);
145 If the function returns SCM_UNSPECIFIED, we assume the
146 property has been set with an explicit set_property()
149 if (value == SCM_UNSPECIFIED)
151 value = internal_get_property (sym);
153 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, marker);
156 internal_set_property (sym, value);
162 Grob::internal_set_object (SCM s, SCM v)
164 /* Perhaps we simply do the assq_set, but what the heck. */
168 object_alist_ = scm_assq_set_x (object_alist_, s, v);
172 Grob::del_property (SCM sym)
174 mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, sym);
178 Grob::internal_get_object (SCM sym) const
180 #ifdef PROFILE_PROPERTY_ACCESSES
181 note_property_access (&grob_property_lookup_table, sym);
184 SCM s = scm_sloppy_assq (sym, object_alist_);
186 return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
190 Grob::substitute_object_links (SCM crit, SCM orig)
192 set_break_subsititution (crit);
193 object_alist_ = substitute_object_alist (orig, object_alist_);
197 Grob::is_live () const
199 return immutable_property_alist_ != SCM_EOL;