Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / pointer-group-interface.cc
bloba8ebb09ffcaa53dd13e10fbf36cf3bc126a86ffb
1 /*
2 pointer-group-interface.cc -- implement Pointer_group_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "pointer-group-interface.hh"
11 #include "grob-array.hh"
12 #include "grob.hh"
14 int
15 Pointer_group_interface::count (Grob *me, SCM sym)
17 Grob_array *arr = unsmob_grob_array (me->internal_get_object (sym));
18 return arr ? arr->size () : 0;
21 void
22 Pointer_group_interface::add_grob (Grob *me, SCM sym, SCM p)
24 add_grob (me, sym, unsmob_grob (p));
27 void
28 Pointer_group_interface::set_ordered (Grob *me, SCM sym, bool ordered)
30 Grob_array *arr = get_grob_array (me, sym);
31 arr->set_ordered (ordered);
34 Grob_array *
35 Pointer_group_interface::get_grob_array (Grob *me, SCM sym)
37 SCM scm_arr = me->internal_get_object (sym);
38 Grob_array *arr = unsmob_grob_array (scm_arr);
39 if (!arr)
41 scm_arr = Grob_array::make_array ();
42 arr = unsmob_grob_array (scm_arr);
43 me->set_object (sym, scm_arr);
45 return arr;
48 Grob *
49 Pointer_group_interface::find_grob (Grob *me, SCM sym, bool (*pred) (Grob*))
51 Grob_array *arr = get_grob_array (me, sym);
53 for (vsize i = 0; i < arr->size (); i++)
54 if (pred (arr->grob (i)))
55 return arr->grob (i);
57 return 0;
60 void
61 Pointer_group_interface::add_grob (Grob *me, SCM sym, Grob *p)
63 Grob_array *arr = get_grob_array (me, sym);
64 arr->add (p);
67 void
68 Pointer_group_interface::add_unordered_grob (Grob *me, SCM sym, Grob *p)
70 Grob_array *arr = get_grob_array (me, sym);
71 arr->add (p);
72 arr->set_ordered (false);
75 static vector<Grob*> empty_array;
77 vector<Grob*> const &
78 ly_scm2link_array (SCM x)
80 Grob_array *arr = unsmob_grob_array (x);
81 return arr ? arr->array () : empty_array;
84 vector<Grob*> const &
85 internal_extract_grob_array (Grob const *elt, SCM symbol)
87 return elt
88 ? ly_scm2link_array (elt->internal_get_object (symbol))
89 : empty_array;
92 vector<Item*>
93 internal_extract_item_array (Grob const *elt, SCM symbol)
95 Grob_array *arr = unsmob_grob_array (elt->internal_get_object (symbol));
96 vector<Item*> items;
97 for (vsize i = 0; arr && i < arr->size (); i++)
98 items.push_back (arr->item (i));
100 return items;