Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / grob-array.cc
blob217ea78aa917cd2bd3baa98efa97892ff1537543
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2011 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"
21 #include "item.hh"
22 #include "spanner.hh"
24 #include "ly-smobs.icc"
26 Item *
27 Grob_array::item (vsize i)
29 return dynamic_cast<Item *> (grobs_.at (i));
32 Spanner *
33 Grob_array::spanner (vsize i)
35 return dynamic_cast<Spanner *> (grobs_.at (i));
38 Grob_array::Grob_array ()
40 ordered_ = true;
43 vector<Grob*> &
44 Grob_array::array_reference ()
46 return grobs_;
49 vector<Grob*> const &
50 Grob_array::array () const
52 return grobs_;
55 SCM
56 Grob_array::mark_smob (SCM s)
58 (void) s;
60 #if 0 /* see System::derived_mark () const */
61 Grob_array *ga = unsmob_grob_array (s);
62 for (vsize i = 0; i < ga->grobs_.size (); i++)
63 scm_gc_mark (ga->grobs_[i]->self_scm ());
64 #endif
65 return SCM_UNDEFINED;
68 int
69 Grob_array::print_smob (SCM arr, SCM port, scm_print_state*)
71 scm_puts ("#<Grob_array", port);
73 Grob_array *grob_arr = unsmob (arr);
74 for (vsize i = 0; i < grob_arr->size (); i++)
76 scm_display (grob_arr->grob (i)->self_scm (), port);
77 scm_puts (" ", port);
79 scm_puts (">", port);
80 return 1;
83 SCM
84 Grob_array::make_array ()
86 Grob_array ga;
87 return ga.smobbed_copy ();
90 void
91 Grob_array::clear ()
93 grobs_.clear ();
96 void
97 Grob_array::remove_duplicates ()
99 assert (!ordered_);
101 vector_sort (grobs_, less<Grob*> ());
102 ::uniq (grobs_);
105 bool
106 Grob_array::empty () const
108 return grobs_.empty ();
111 void
112 Grob_array::set_array (vector<Grob*> const &src)
114 grobs_ = src;
117 IMPLEMENT_SIMPLE_SMOBS (Grob_array);
118 IMPLEMENT_TYPE_P (Grob_array, "ly:grob-array?");
120 IMPLEMENT_DEFAULT_EQUAL_P (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)));
129 return arr_scm;
133 grob_array_to_list (Grob_array *array)
135 SCM list = SCM_EOL;
136 SCM *tail = &list;
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);
143 return list;