]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/grob-array.cc
Release: bump Welcome versions.
[lilypond.git] / lily / grob-array.cc
index d08aa3d1e7fa83630a998a4b1bf792db78161287..f5228dfd7148d91296dac7765b8b197cb162f34c 100644 (file)
@@ -21,7 +21,6 @@
 #include "item.hh"
 #include "spanner.hh"
 
-using std::vector;
 
 Item *
 Grob_array::item (vsize i)
@@ -40,18 +39,6 @@ Grob_array::Grob_array ()
   ordered_ = true;
 }
 
-vector<Grob *> &
-Grob_array::array_reference ()
-{
-  return grobs_;
-}
-
-vector<Grob *> const &
-Grob_array::array () const
-{
-  return grobs_;
-}
-
 SCM
 Grob_array::mark_smob () const
 {
@@ -82,12 +69,6 @@ Grob_array::make_array ()
   return ga.smobbed_copy ();
 }
 
-void
-Grob_array::clear ()
-{
-  grobs_.clear ();
-}
-
 void
 Grob_array::remove_duplicates ()
 {
@@ -96,19 +77,46 @@ Grob_array::remove_duplicates ()
   uniquify (grobs_);
 }
 
-bool
-Grob_array::empty () const
+void
+Grob_array::filter (bool (*predicate) (const Grob *))
+{
+  vsize new_size = 0;
+  for (vsize i = 0; i < grobs_.size (); ++i)
+    if (predicate (grobs_[i]))
+      grobs_[new_size++] = grobs_[i];
+  grobs_.resize (new_size);
+  // could call grobs_.shrink_to_fit () with C++11
+}
+
+void
+Grob_array::filter_map (Grob * (*map_fun) (Grob *))
 {
-  return grobs_.empty ();
+  vsize new_size = 0;
+  for (vsize i = 0; i < grobs_.size (); ++i)
+    if (Grob *grob = map_fun (grobs_[i]))
+      grobs_[new_size++] = grob;
+  grobs_.resize (new_size);
+  // could call grobs_.shrink_to_fit () with C++11
 }
 
 void
-Grob_array::set_array (vector<Grob *> const &src)
+Grob_array::filter_map_assign (const Grob_array &src,
+                               Grob * (*map_fun) (Grob *))
 {
-  grobs_ = src;
+  if (&src != this)
+    {
+      grobs_.resize (0);
+      grobs_.reserve (src.grobs_.size ());
+      for (vsize i = 0; i < src.grobs_.size (); i++)
+        if (Grob *grob = map_fun (src.grobs_[i]))
+          grobs_.push_back (grob);
+      // could call grobs_.shrink_to_fit () with C++11
+    }
+  else
+    filter_map (map_fun);
 }
 
-const char Grob_array::type_p_name_[] = "ly:grob-array?";
+const char * const Grob_array::type_p_name_ = "ly:grob-array?";
 
 
 SCM