]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-property.cc
Nitpick run.
[lilypond.git] / lily / grob-property.cc
1 /*
2   Implement storage and manipulation of grob properties.
3 */
4
5 #include <cstring>
6 #include <math.h>
7
8 #include "main.hh"
9 #include "input-smob.hh"
10 #include "pointer-group-interface.hh"
11 #include "misc.hh"
12 #include "paper-score.hh"
13 #include "output-def.hh"
14 #include "spanner.hh"
15 #include "item.hh"
16 #include "misc.hh"
17 #include "item.hh"
18 #include "program-option.hh"
19 #include "profile.hh"
20
21 SCM
22 Grob::get_property_alist_chain (SCM def) const
23 {
24   return scm_list_n (mutable_property_alist_,
25                      immutable_property_alist_,
26                      def,
27                      SCM_UNDEFINED);
28 }
29
30 /*
31   This special add_thing routine is slightly more efficient than
32
33   set_prop (name, cons (thing, get_prop (name)))
34
35   since it can reuse the handle returned by scm_assq ().
36 */
37 // JUNKME.
38 void
39 Grob::add_to_list_property (SCM sym, SCM thing)
40 {
41   SCM handle
42     = scm_sloppy_assq (sym, mutable_property_alist_);
43
44   if (handle != SCM_BOOL_F)
45     scm_set_cdr_x (handle, scm_cons (thing, scm_cdr (handle)));
46   else
47     {
48       /*
49         There is no mutable prop yet, so create an entry, and put it in front of the
50         mutable prop list.
51       */
52       handle = scm_sloppy_assq (sym, immutable_property_alist_);
53       SCM tail = (handle != SCM_BOOL_F) ? scm_cdr (handle) : SCM_EOL;
54       SCM val = scm_cons (thing, tail);
55
56       mutable_property_alist_ = scm_cons (scm_cons (sym, val),
57                                           mutable_property_alist_);
58     }
59 }
60
61 extern void check_interfaces_for_property (Grob const *me, SCM sym);
62
63 void
64 Grob::internal_set_property (SCM sym, SCM v)
65 {
66 #ifndef NDEBUG
67   SCM grob_p = ly_lily_module_constant ("ly:grob?");
68   SCM grob_list_p = ly_lily_module_constant ("grob-list?");
69   SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
70
71   if (type == grob_p
72       || type == grob_list_p
73       || (unsmob_grob (v) && ly_symbol2scm ("cause") != sym))
74     {
75       scm_display (scm_list_2 (sym, type), scm_current_output_port ());
76       assert (0);
77     }
78 #endif
79
80   /* Perhaps we simply do the assq_set, but what the heck. */
81   if (!is_live ())
82     return;
83
84   if (do_internal_type_checking_global)
85     {
86       if (!type_check_assignment (sym, v, ly_symbol2scm ("backend-type?")))
87         abort ();
88       check_interfaces_for_property (this, sym);
89     }
90
91   mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, sym, v);
92 }
93
94 //#define PROFILE_PROPERTY_ACCESSES
95
96
97 SCM
98 Grob::internal_get_property (SCM sym) const
99 {
100 #ifndef NDEBUG
101   if (profile_property_accesses)
102     note_property_access (&grob_property_lookup_table, sym);
103 #endif
104
105   SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
106   if (s != SCM_BOOL_F)
107     return scm_cdr (s);
108
109   s = scm_sloppy_assq (sym, immutable_property_alist_);
110
111   if (do_internal_type_checking_global && scm_is_pair (s))
112     {
113       if (!type_check_assignment (sym, scm_cdr (s),
114                                   ly_symbol2scm ("backend-type?")))
115         abort ();
116
117       check_interfaces_for_property (this, sym);
118     }
119
120   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
121 }
122
123 void
124 Grob::internal_set_object (SCM s, SCM v)
125 {
126   /* Perhaps we simply do the assq_set, but what the heck. */
127   if (!is_live ())
128     return;
129
130   object_alist_ = scm_assq_set_x (object_alist_, s, v);
131 }
132
133 SCM
134 Grob::internal_get_object (SCM sym) const
135 {
136 #ifdef PROFILE_PROPERTY_ACCESSES
137   note_property_access (&grob_property_lookup_table, sym);
138 #endif
139
140   SCM s = scm_sloppy_assq (sym, object_alist_);
141
142   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
143 }
144
145 void
146 Grob::substitute_object_links (SCM crit, SCM orig)
147 {
148   set_break_subsititution (crit);
149   object_alist_ = substitute_object_alist (orig, object_alist_);
150 }
151
152 bool
153 Grob::is_live () const
154 {
155   return immutable_property_alist_ != SCM_EOL;
156 }