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>
9 #include "grob-array.hh"
13 #include "ly-smobs.icc"
16 Grob_array::item (vsize i)
18 return dynamic_cast<Item *> (grobs_.at (i));
22 Grob_array::spanner (vsize i)
24 return dynamic_cast<Spanner *> (grobs_.at (i));
27 Grob_array::Grob_array ()
33 Grob_array::array_reference ()
39 Grob_array::array () const
45 Grob_array::mark_smob (SCM 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 ());
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);
73 Grob_array::make_array ()
76 return ga.smobbed_copy ();
86 Grob_array::remove_duplicates ()
90 vector_sort (grobs_, less<Grob*> ());
95 Grob_array::empty () const
97 return grobs_.empty ();
101 Grob_array::set_array (vector<Grob*> const &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)));