2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2015 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 "grob-array.hh"
26 Grob_array::item (vsize i)
28 return dynamic_cast<Item *> (grobs_.at (i));
32 Grob_array::spanner (vsize i)
34 return dynamic_cast<Spanner *> (grobs_.at (i));
37 Grob_array::Grob_array ()
43 Grob_array::mark_smob () const
45 #if 0 /* see System::derived_mark () const */
46 for (vsize i = 0; i < grobs_.size (); i++)
47 scm_gc_mark (grobs_[i]->self_scm ());
53 Grob_array::print_smob (SCM port, scm_print_state *) const
55 scm_puts ("#<Grob_array", port);
56 for (vsize i = 0; i < size (); i++)
58 scm_display (grob (i)->self_scm (), port);
66 Grob_array::make_array ()
69 return ga.smobbed_copy ();
73 Grob_array::remove_duplicates ()
81 Grob_array::filter (bool (*predicate) (const Grob *))
84 for (vsize i = 0; i < grobs_.size (); ++i)
85 if (predicate (grobs_[i]))
86 grobs_[new_size++] = grobs_[i];
87 grobs_.resize (new_size);
88 // could call grobs_.shrink_to_fit () with C++11
92 Grob_array::filter_map (Grob * (*map_fun) (Grob *))
95 for (vsize i = 0; i < grobs_.size (); ++i)
96 if (Grob *grob = map_fun (grobs_[i]))
97 grobs_[new_size++] = grob;
98 grobs_.resize (new_size);
99 // could call grobs_.shrink_to_fit () with C++11
103 Grob_array::filter_map_assign (const Grob_array &src,
104 Grob * (*map_fun) (Grob *))
109 grobs_.reserve (src.grobs_.size ());
110 for (vsize i = 0; i < src.grobs_.size (); i++)
111 if (Grob *grob = map_fun (src.grobs_[i]))
112 grobs_.push_back (grob);
113 // could call grobs_.shrink_to_fit () with C++11
116 filter_map (map_fun);
119 const char Grob_array::type_p_name_[] = "ly:grob-array?";
123 grob_list_to_grob_array (SCM lst)
125 SCM arr_scm = Grob_array::make_array ();
126 Grob_array *ga = unsmob<Grob_array> (arr_scm);
127 for (SCM s = lst; scm_is_pair (s); s = scm_cdr (s))
128 ga->add (unsmob<Grob> (scm_car (s)));
133 grob_array_to_list (Grob_array *array)
138 for (vsize i = 0; i < array->size (); i++)
140 *tail = scm_cons (array->grob (i)->self_scm (), SCM_EOL);
141 tail = SCM_CDRLOC (*tail);