From: Jan Nieuwenhuizen Date: Thu, 2 Feb 2006 15:13:22 +0000 (+0000) Subject: * flower/include/std-vector.hh X-Git-Tag: release/2.7.31~15 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c8e9703dffb4d1e774ead41c150fe9d3ef29bc4c;p=lilypond.git * 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 * flower/include/array.hh (elem, elem_ref): Globally replace by at (). --- diff --git a/ChangeLog b/ChangeLog index 244399ea03..604b6deeaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,12 @@ 2006-02-02 Jan Nieuwenhuizen + * 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 diff --git a/flower/include/array.hh b/flower/include/array.hh index 8a941c13aa..72cde83723 100644 --- a/flower/include/array.hh +++ b/flower/include/array.hh @@ -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 + void + swap (T *a, T *b) + { + T t = *a; + *a = *b; + *b = t; + } +#endif + + template + void + reverse (Array &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" } diff --git a/flower/include/array.icc b/flower/include/array.icc index 924646df5a..560ec31c72 100644 --- a/flower/include/array.icc +++ b/flower/include/array.icc @@ -48,24 +48,16 @@ vector_sort (Array &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 INLINE void -Array::reverse () -{ - vsize h = size_ / 2; - for (vsize i = 0, j = size_ - 1; i < h; i++, j--) - swap (i, j); -} - template INLINE void Array::OK () const @@ -79,17 +71,6 @@ Array::OK () const assert (array_); } -template INLINE -T * -Array::remove_array () -{ - T *p = array_; - size_ = 0; - max_ = 0; - array_ = 0; - return p; -} - template INLINE Array::Array (const_iterator b, const_iterator e) { diff --git a/flower/include/parray.hh b/flower/include/parray.hh index e85c1d9f73..f5a2d373bf 100644 --- a/flower/include/parray.hh +++ b/flower/include/parray.hh @@ -53,7 +53,6 @@ public: /* Flower compat */ Array::unordered_del; - Array::reverse; Array::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 @@ -344,5 +357,6 @@ binary_search_bounds (Link_array const &table, while (*hi - *lo > 1); } + #endif // PARRAY_HH diff --git a/flower/include/std-vector.hh b/flower/include/std-vector.hh index c70c9449a9..c2226734b4 100644 --- a/flower/include/std-vector.hh +++ b/flower/include/std-vector.hh @@ -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, 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 + void + swap (T *a, T *b) + { + T t = *a; + *a = *b; + *b = t; + } + // ugh, c&p template void vector_sort (vector &v, int (*compare) (T const &, T const &), @@ -199,16 +185,25 @@ vector_sort (vector &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 + void + reverse (vector &v) + { + // CHECKME: for a simple vector, like vector, this should + // expand to memrev. + ::std::reverse (v.begin (), v.end ()); + } + #endif } diff --git a/lily/beam.cc b/lily/beam.cc index 448871d574..d91431a919 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -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; diff --git a/lily/cluster.cc b/lily/cluster.cc index ade7667c63..cefb02f782 100644 --- a/lily/cluster.cc +++ b/lily/cluster.cc @@ -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); diff --git a/lily/include/source-file.hh b/lily/include/source-file.hh index 098ae75925..6f7f75e683 100644 --- a/lily/include/source-file.hh +++ b/lily/include/source-file.hh @@ -70,6 +70,7 @@ private: Link_array newline_locations_; istream *istream_; char *contents_str0_; + std::vector chs_; int length_; void load_stdin (); void init_port (); diff --git a/lily/source-file.cc b/lily/source-file.cc index d4a3681da2..a25d071074 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -35,20 +35,14 @@ void Source_file::load_stdin () { length_ = 0; - + chs_.clear (); int c; -#if STD_VECTOR - std::vector &chs = *new std::vector; // ugh. ugh. -#else - std::vector 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 *