Nitpick: ly:spanner-bound grob name slur -> spanner.
[lilypond.git] / lily / grob-array.cc
blob9cf6e39e5f133a63fd4df150a78fab62196f809a
1 /*
2 grob-array.cc -- implement Grob_array
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "grob-array.hh"
10 #include "item.hh"
11 #include "spanner.hh"
13 #include "ly-smobs.icc"
15 Item *
16 Grob_array::item (vsize i)
18 return dynamic_cast<Item *> (grobs_.at (i));
21 Spanner *
22 Grob_array::spanner (vsize i)
24 return dynamic_cast<Spanner *> (grobs_.at (i));
27 Grob_array::Grob_array ()
29 ordered_ = true;
32 vector<Grob*> &
33 Grob_array::array_reference ()
35 return grobs_;
38 vector<Grob*> const &
39 Grob_array::array () const
41 return grobs_;
44 SCM
45 Grob_array::mark_smob (SCM s)
47 (void) s;
49 #if 0 /* see System::derived_mark () const */
50 Grob_array *ga = unsmob_grob_array (s);
51 for (vsize i = 0; i < ga->grobs_.size (); i++)
52 scm_gc_mark (ga->grobs_[i]->self_scm ());
53 #endif
54 return SCM_UNDEFINED;
57 int
58 Grob_array::print_smob (SCM arr, SCM port, scm_print_state*)
60 scm_puts ("#<Grob_array", port);
62 Grob_array *grob_arr = unsmob (arr);
63 for (vsize i = 0; i < grob_arr->size (); i++)
65 scm_display (grob_arr->grob (i)->self_scm (), port);
66 scm_puts (" ", port);
68 scm_puts (">", port);
69 return 1;
72 SCM
73 Grob_array::make_array ()
75 Grob_array ga;
76 return ga.smobbed_copy ();
79 void
80 Grob_array::clear ()
82 grobs_.clear ();
85 void
86 Grob_array::remove_duplicates ()
88 assert (!ordered_);
90 vector_sort (grobs_, less<Grob*> ());
91 ::uniq (grobs_);
94 bool
95 Grob_array::empty () const
97 return grobs_.empty ();
100 void
101 Grob_array::set_array (vector<Grob*> const &src)
103 grobs_ = src;
106 IMPLEMENT_SIMPLE_SMOBS (Grob_array);
107 IMPLEMENT_TYPE_P (Grob_array, "ly:grob-array?");
109 IMPLEMENT_DEFAULT_EQUAL_P (Grob_array);
112 grob_list_to_grob_array (SCM lst)
114 SCM arr_scm = Grob_array::make_array ();
115 Grob_array *ga = unsmob_grob_array (arr_scm);
116 for (SCM s = lst; scm_is_pair (s); s = scm_cdr (s))
117 ga->add (unsmob_grob (scm_car (s)));
118 return arr_scm;