]> git.donarmstrong.com Git - lilypond.git/commitdiff
* flower/include/std-vector.hh
authorJan Nieuwenhuizen <janneke@gnu.org>
Thu, 2 Feb 2006 15:13:22 +0000 (15:13 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Thu, 2 Feb 2006 15:13:22 +0000 (15:13 +0000)
* flower/include/array.hh (reverse, swap): Detach from class.
Update users.

* flower/include/std-vector.hh
* flower/include/array.hh (concat): Globally change to insert ().

* flower/include/std-vector.hh
* flower/include/parray.hh
* flower/include/array.hh (elem, elem_ref): Globally replace by
at ().

ChangeLog
flower/include/array.hh
flower/include/array.icc
flower/include/parray.hh
flower/include/std-vector.hh
lily/beam.cc
lily/cluster.cc
lily/include/source-file.hh
lily/source-file.cc

index 244399ea03e0189529c8adc972f0e18c6693ba09..604b6deeaf3954d6d5bacb675bdafa3b05b6287c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,12 @@
 2006-02-02  Jan Nieuwenhuizen  <janneke@gnu.org>
 
+       * flower/include/std-vector.hh
+       * flower/include/array.hh (reverse, swap): Detach from class.
+       Update users.
+       
        * flower/include/std-vector.hh
        * flower/include/array.hh (concat): Globally change to insert ().
+
        
        * flower/include/std-vector.hh
        * flower/include/parray.hh
index 8a941c13aab70cf8ac176bf620326618c5bfc6bd..72cde837233aa698e0210b580105d8e2604dc98b 100644 (file)
@@ -283,8 +283,6 @@ public:
     arrcpy (array_, src.array_, size_);
   }
 
-  T *remove_array ();
-
   /// access last entry
   T &top (vsize j)
   {
@@ -312,21 +310,34 @@ public:
     else
       return at (idx);
   }
-  void swap (vsize i, vsize j)
-  {
-    T t ((*this)[i]);
-    (*this)[i] = (*this)[j];
-    (*this)[j] = t;
-  }
 
   void unordered_del (vsize i)
   {
     at (i) = back ();
     resize (size () -1);
   }
-  void reverse ();
 };
 
+#if 0
+  template<class T>
+  void
+  swap (T *a, T *b)
+  {
+    T t = *a;
+    *a = *b;
+    *b = t;
+  }
+#endif
+  
+  template<class T>
+  void
+  reverse (Array<T> &v)
+  {
+    vsize h = v.size () / 2;
+    for (vsize i = 0, j = v.size () - 1; i < h; i++, j--)
+      swap (v[i], v[j]);
+  }
+
 #include "array.icc"
 
 }
index 924646df5a87b75fda3396eaa171d4efa82621f3..560ec31c72b4d9271801087bb84b62ce9a5eeb12 100644 (file)
@@ -48,24 +48,16 @@ vector_sort (Array<T> &v, int (*compare) (T const &, T const &),
     }
   if (lower >= upper)
     return;
-  v.swap (lower, (lower + upper) / 2);
+  swap (v[lower], v[(lower + upper) / 2]);
   vsize last = lower;
   for (vsize i = lower +1; i <= upper; i++)
     if (compare (v.array_[i], v.array_[lower]) < 0)
-      v.swap (++last, i);
-  v.swap (lower, last);
+      swap (v[++last], v[i]);
+  swap (v[lower], v[last]);
   vector_sort (v, compare, lower, last - 1);
   vector_sort (v, compare, last + 1, upper);
 }
 
-template<class T> INLINE void
-Array<T>::reverse ()
-{
-  vsize h = size_ / 2;
-  for (vsize i = 0, j = size_ - 1; i < h; i++, j--)
-    swap (i, j);
-}
-
 template<class T> INLINE
 void
 Array<T>::OK () const
@@ -79,17 +71,6 @@ Array<T>::OK () const
     assert (array_);
 }
 
-template<class T> INLINE
-T *
-Array<T>::remove_array ()
-{
-  T *p = array_;
-  size_ = 0;
-  max_ = 0;
-  array_ = 0;
-  return p;
-}
-
 template<class T> INLINE
 Array<T>::Array (const_iterator b, const_iterator e)
 {
index e85c1d9f73a1dc636168cf330e6650c8b6fa89da..f5a2d373bf7ab4d1633c4fda204612367f89115a 100644 (file)
@@ -53,7 +53,6 @@ public:
 
   /* Flower compat */
   Array<void *>::unordered_del;
-  Array<void *>::reverse;
   Array<void *>::tighten_maxsize;
 
   static int default_compare (T *const &p1, T *const &p2)
@@ -213,6 +212,20 @@ public:
     else
       return 0;
   }
+
+  void swap (vsize i, vsize j)
+  {
+    T *t ((*this)[i]);
+    (*this)[i] = (*this)[j];
+    (*this)[j] = t;
+  }
+  void
+  reverse ()
+  {
+    vsize h = size () / 2;
+    for (vsize i = 0, j = size () - 1; i < h; i++, j--)
+      swap (i, j);
+  }
 };
 
 template<class T, class V>
@@ -344,5 +357,6 @@ binary_search_bounds (Link_array<T> const &table,
   while (*hi - *lo > 1);
 }
 
+
 #endif // PARRAY_HH
 
index c70c9449a9e4313e1c4e28d857542c94ae87d22f..c2226734b4cb37db597d17297290225ef4c84bea 100644 (file)
@@ -72,30 +72,6 @@ namespace std {
        return this->at (i);
     }
 
-    T *
-    remove_array ()
-    {
-      T *p = &(*this)[0];
-      /* FIXME: forget array? */
-      /* this->resize (0); */
-      return p;
-    }
-
-    void
-    reverse ()
-    {
-      // CHECKME: for a simple vector, like vector<int>, this should
-      // expand to memrev.
-      ::std::reverse (this->begin (), this->end ());
-    }
-
-    void swap (vsize i, vsize j)
-    {
-      T t ((*this)[i]);
-      (*this)[i] = (*this)[j];
-      (*this)[j] = t;
-    }
-
     T const &
     top (vsize i) const
     {
@@ -187,6 +163,16 @@ namespace std {
     ::std::sort (b + lower, e + upper, compare);
   }
 #else
+
+  template<typename T>
+  void
+  swap (T *a, T *b)
+  {
+    T t = *a;
+    *a = *b;
+    *b = t;
+  }
+
   // ugh, c&p
 template<typename T> void
 vector_sort (vector<T> &v, int (*compare) (T const &, T const &),
@@ -199,16 +185,25 @@ vector_sort (vector<T> &v, int (*compare) (T const &, T const &),
     }
   if (upper == VPOS || lower >= upper)
     return;
-  v.swap (lower, (lower + upper) / 2);
+  swap (v[lower], v[(lower + upper) / 2]);
   vsize last = lower;
   for (vsize i = lower +1; i <= upper; i++)
     if (compare (v[i], v[lower]) < 0)
-      v.swap (++last, i);
-  v.swap (lower, last);
+      swap (v[++last], v[i]);
+  swap (v[lower], v[last]);
   vector_sort (v, compare, lower, last - 1);
   vector_sort (v, compare, last + 1, upper);
 }
-  
+
+  template<typename T>
+  void
+  reverse (vector<T> &v)
+  {
+    // CHECKME: for a simple vector, like vector<int>, this should
+    // expand to memrev.
+    ::std::reverse (v.begin (), v.end ());
+  }
+
 #endif
 
 }
index 448871d574ed47d9909f45a0d0a4e19cacdbdd11..d91431a919cd06b52169b678931cff2fface3e17 100644 (file)
@@ -403,7 +403,7 @@ Beam::print (SCM grob)
 
          vector_sort (full_beams, default_compare);
          if (stem_dir == UP)
-           full_beams.reverse ();
+           reverse (full_beams);
        }
 
       int k = 0;
index ade7667c63fc593b70087e981489218976b66c9b..cefb02f78207f5eb95799e7bcf546ceda9e51a6e 100644 (file)
@@ -191,8 +191,8 @@ Cluster::print (SCM smob)
        }
     }
 
-  bottom_points.reverse ();
-  top_points.reverse ();
+  reverse (bottom_points);
+  reverse (top_points);
 
   Stencil out = brew_cluster_piece (me, bottom_points, top_points);
   out.translate_axis (- me->relative_coordinate (commony, Y_AXIS), Y_AXIS);
index 098ae759252a57720edc0d569fca9e19bece2f43..6f7f75e68354c7277c46a5da111e8b8961fef872 100644 (file)
@@ -70,6 +70,7 @@ private:
   Link_array<char> newline_locations_;
   istream *istream_;
   char *contents_str0_;
+  std::vector<char> chs_;
   int length_;
   void load_stdin ();
   void init_port ();
index d4a3681da26a71dce624865e1da2658c17d594b0..a25d071074dd42972e2396318dea47191b76498e 100644 (file)
@@ -35,20 +35,14 @@ void
 Source_file::load_stdin ()
 {
   length_ = 0;
-
+  chs_.clear ();
   int c;
-#if STD_VECTOR
-  std::vector<char> &chs = *new std::vector<char>; // ugh. ugh.
-#else
-  std::vector<char> chs;               // ugh.
-#endif
-  
   while ((c = fgetc (stdin)) != EOF)
-    chs.push_back (c);
+    chs_.push_back (c);
 
-  chs.push_back (0);
-  length_ = chs.size ();
-  contents_str0_ = chs.remove_array ();
+  chs_.push_back (0);
+  length_ = chs_.size ();
+  contents_str0_ = &chs_[0];
 }
 
 char *