2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "pointer-group-interface.hh"
22 #include "grob-array.hh"
26 Pointer_group_interface::count (Grob *me, SCM sym)
28 Grob_array *arr = unsmob_grob_array (me->internal_get_object (sym));
29 return arr ? arr->size () : 0;
33 Pointer_group_interface::add_grob (Grob *me, SCM sym, SCM p)
35 add_grob (me, sym, unsmob_grob (p));
39 Pointer_group_interface::set_ordered (Grob *me, SCM sym, bool ordered)
41 Grob_array *arr = get_grob_array (me, sym);
42 arr->set_ordered (ordered);
46 Pointer_group_interface::get_grob_array (Grob *me, SCM sym)
48 SCM scm_arr = me->internal_get_object (sym);
49 Grob_array *arr = unsmob_grob_array (scm_arr);
52 scm_arr = Grob_array::make_array ();
53 arr = unsmob_grob_array (scm_arr);
54 me->set_object (sym, scm_arr);
60 Pointer_group_interface::find_grob (Grob *me, SCM sym, bool (*pred) (Grob *))
62 Grob_array *arr = get_grob_array (me, sym);
64 for (vsize i = 0; i < arr->size (); i++)
65 if (pred (arr->grob (i)))
71 // If the grob array is unordered, we assume that duplicates should
72 // be removed. This makes sense for things like side-position-elements,
73 // which may be added recursively numerous times and thus will eat up
74 // computation time when skylines are calculated.
75 // If the array is ordered, then we don't remove duplicates.
78 Pointer_group_interface::add_grob (Grob *me, SCM sym, Grob *p)
80 Grob_array *arr = get_grob_array (me, sym);
83 arr->remove_duplicates ();
87 Pointer_group_interface::add_unordered_grob (Grob *me, SCM sym, Grob *p)
89 Grob_array *arr = get_grob_array (me, sym);
91 arr->set_ordered (false);
92 arr->remove_duplicates ();
95 static vector<Grob *> empty_array;
97 vector<Grob *> const &
98 ly_scm2link_array (SCM x)
100 Grob_array *arr = unsmob_grob_array (x);
101 return arr ? arr->array () : empty_array;
104 vector<Grob *> const &
105 internal_extract_grob_array (Grob const *elt, SCM symbol)
108 ? ly_scm2link_array (elt->internal_get_object (symbol))
113 internal_extract_item_array (Grob const *elt, SCM symbol)
115 Grob_array *arr = unsmob_grob_array (elt->internal_get_object (symbol));
116 vector<Item *> items;
117 for (vsize i = 0; arr && i < arr->size (); i++)
118 items.push_back (arr->item (i));