]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-property.cc
* flower
[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 "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
19 SCM
20 Grob::get_property_alist_chain (SCM def) const
21 {
22   return scm_list_n (mutable_property_alist_,
23                      immutable_property_alist_,
24                      def,
25                      SCM_UNDEFINED);
26 }
27
28 /*
29   This special add_thing routine is slightly more efficient than
30
31   set_prop (name, cons (thing, get_prop (name)))
32
33   since it can reuse the handle returned by scm_assq ().
34 */
35 void
36 Grob::add_to_list_property (SCM sym, SCM thing)
37 {
38   SCM handle
39     = scm_sloppy_assq (sym, mutable_property_alist_);
40
41   if (handle != SCM_BOOL_F)
42     {
43       scm_set_cdr_x (handle, scm_cons (thing, scm_cdr (handle)));
44     }
45   else
46     {
47       /*
48         There is no mutable prop yet, so create an entry, and put it in front of the
49         mutable prop list.
50       */
51       handle = scm_sloppy_assq (sym, immutable_property_alist_);
52       SCM tail = (handle != SCM_BOOL_F) ? scm_cdr (handle) : SCM_EOL;
53       SCM val = scm_cons (thing, tail);
54
55       mutable_property_alist_ = scm_cons (scm_cons (sym, val),
56                                           mutable_property_alist_);
57     }
58 }
59
60 extern void check_interfaces_for_property (Grob const *me, SCM sym);
61
62 void
63 Grob::internal_set_property (SCM s, SCM v)
64 {
65   /* Perhaps we simply do the assq_set, but what the heck. */
66   if (!is_live ())
67     return;
68
69   if (do_internal_type_checking_global)
70     {
71       if (!type_check_assignment (s, v, ly_symbol2scm ("backend-type?")))
72         abort ();
73       check_interfaces_for_property (this, s);
74     }
75
76   mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, s, v);
77 }
78
79 SCM
80 Grob::internal_get_property (SCM sym) const
81 {
82   SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
83   if (s != SCM_BOOL_F)
84     return scm_cdr (s);
85
86   s = scm_sloppy_assq (sym, immutable_property_alist_);
87
88   if (do_internal_type_checking_global && scm_is_pair (s))
89     {
90       if (!type_check_assignment (sym, scm_cdr (s),
91                                   ly_symbol2scm ("backend-type?")))
92         abort ();
93
94       check_interfaces_for_property (this, sym);
95     }
96
97   return (s == SCM_BOOL_F) ? SCM_EOL : scm_cdr (s);
98 }
99
100 void
101 Grob::substitute_mutable_properties (SCM crit, SCM orig)
102 {
103   set_break_subsititution (crit);
104   mutable_property_alist_ = substitute_mutable_property_alist (orig);
105 }
106
107 bool
108 Grob::is_live () const
109 {
110   return immutable_property_alist_ != SCM_EOL;
111 }