From: Jan Nieuwenhuizen Date: Thu, 2 Feb 2006 15:44:16 +0000 (+0000) Subject: * flower/include/std-vector.hh X-Git-Tag: release/2.7.31~14 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ff90d34b47b91a7321ff9b21fe20133911376364;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 604b6deeaf..76ed56b991 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ 2006-02-02 Jan Nieuwenhuizen - * flower/include/std-vector.hh + * flower/string-convert.cc (convert::unsigned_string): Bugfix: + remove superfluous `d'. + + * flower/include/std-vector.hh (boundary, top): Detach from class. + Remove empty vector shell. + * flower/include/array.hh (reverse, swap): Detach from class. Update users. diff --git a/flower/include/array.hh b/flower/include/array.hh index 72cde83723..98e4d1f060 100644 --- a/flower/include/array.hh +++ b/flower/include/array.hh @@ -283,52 +283,43 @@ public: arrcpy (array_, src.array_, size_); } - /// access last entry - T &top (vsize j) + void unordered_del (vsize i) { - return (*this)[size_ - j - 1]; + at (i) = back (); + resize (size () -1); } - /// return last entry - T top (vsize j) const +}; + + template + T const & + back (Array const &v, vsize i) { - return (*this)[size_ - j - 1]; + return v[v.size () - i - 1]; } - T &boundary (int dir, vsize idx) + template + T& + back (Array &v, vsize i) { - assert (dir); - if (dir == 1) - return top (idx); - else - return at (idx); + return v[v.size () - i - 1]; } - T boundary (int dir, vsize idx) const + + template + T const & + boundary (Array const &v, int dir, vsize i) { assert (dir); - if (dir == 1) - return top (idx); - else - return at (idx); + return v[dir == 1 ? i : v.size () - 1 - i]; } - void unordered_del (vsize i) + template + T & + boundary (Array &v, int dir, vsize i) { - at (i) = back (); - resize (size () -1); + assert (dir); + return v[dir == 1 ? i : v.size () - 1 - i]; } -}; -#if 0 - template - void - swap (T *a, T *b) - { - T t = *a; - *a = *b; - *b = t; - } -#endif - template void reverse (Array &v) diff --git a/flower/include/parray.hh b/flower/include/parray.hh index f5a2d373bf..2e90dd7c78 100644 --- a/flower/include/parray.hh +++ b/flower/include/parray.hh @@ -112,14 +112,13 @@ public: Array::push_back (t); } - /// return last entry - T *top (int j) const + T *top (vsize j) { - return (T *) Array::top (j); + return (*this)[size_ - j - 1]; } - T *& top (int i) + T *& top (vsize j) const { - return (T *&) Array::top (i); + return (*this)[size_ - j - 1]; } void substitute (T *old, T *new_p) diff --git a/flower/include/std-vector.hh b/flower/include/std-vector.hh index c2226734b4..10018dc1e7 100644 --- a/flower/include/std-vector.hh +++ b/flower/include/std-vector.hh @@ -23,9 +23,7 @@ #if STD_VECTOR -#define vector __vector #include -#undef vector namespace std { @@ -35,55 +33,35 @@ namespace std { #define VPOS UINT_MAX #endif - /* Interface without pointer arithmetic (iterator) semantics. */ template - class vector : public __vector + T const & + boundary (vector const &v, int dir, vsize i) { - public: - typedef typename __vector::iterator iterator; - typedef typename __vector::const_iterator const_iterator; - - vector () : __vector () - { - } - - vector (const_iterator b, const_iterator e) : __vector (b, e) - { - } - - /* Flower-Array compatibility. */ - T const & - boundary (int dir, vsize i) const - { - assert (dir); - if (dir == 1) - return this->top (i); - else - return this->at (i); - } + assert (dir); + return v[dir == 1 ? i : v.size () - 1 - i]; + } - T & - boundary (int dir, vsize i) - { - assert (dir); - if (dir == 1) - return this->top (i); - else - return this->at (i); - } + template + T & + boundary (vector &v, int dir, vsize i) + { + assert (dir); + return v[dir == 1 ? i : v.size () - 1 - i]; + } - T const & - top (vsize i) const - { - return (*this)[this->size () - i - 1]; - } + template + T const & + back (vector const &v, vsize i) + { + return v[v.size () - i - 1]; + } - T& - top (vsize i) - { - return (*this)[this->size () - i - 1]; - } - }; + template + T& + back (vector &v, vsize i) + { + return v[v.size () - i - 1]; + } #if 0 template diff --git a/flower/polynomial.cc b/flower/polynomial.cc index 4d9687de38..5f71914767 100644 --- a/flower/polynomial.cc +++ b/flower/polynomial.cc @@ -88,7 +88,7 @@ Polynomial::clean () We only do relative comparisons. Absolute comparisons break down in degenerate cases. */ while (degree () > 0 - && (fabs (coefs_.back ()) < FUDGE * fabs (coefs_.top (1)) + && (fabs (coefs_.back ()) < FUDGE * fabs (back (coefs_, 1)) || !coefs_.back ())) coefs_.pop_back (); } diff --git a/flower/string-convert.cc b/flower/string-convert.cc index 07aef9f3f4..eda9aa9012 100644 --- a/flower/string-convert.cc +++ b/flower/string-convert.cc @@ -349,7 +349,7 @@ std::string String_convert::unsigned_string (unsigned u) { char s[STRING_BUFFER_LEN]; - sprintf (s, "%ud", u); + sprintf (s, "%u", u); return s; } diff --git a/lily/beaming-info.cc b/lily/beaming-info.cc index 11c6dde0c6..c4444c17a6 100644 --- a/lily/beaming-info.cc +++ b/lily/beaming-info.cc @@ -53,8 +53,8 @@ Beaming_info_list::beam_extend_count (Direction d) const if (infos_.size () == 1) return infos_[0].beams_i_drul_[d]; - Beaming_info thisbeam = infos_.boundary (d, 0); - Beaming_info next = infos_.boundary (d, 1); + Beaming_info thisbeam = boundary (infos_, d, 0); + Beaming_info next = boundary (infos_, d, 1); return min (thisbeam.beams_i_drul_[-d], next.beams_i_drul_[d]); } @@ -87,7 +87,7 @@ Beaming_info_list::beamify (Moment &beat_length, bool subdivide) do { if (splits[d].infos_.size () != 1) - splits[d].infos_.boundary (-d, 0).beams_i_drul_[-d] = middle_beams; + boundary (splits[d].infos_, -d, 0).beams_i_drul_[-d] = middle_beams; } while (flip (&d) != LEFT); diff --git a/lily/tie-formatting-problem.cc b/lily/tie-formatting-problem.cc index 4f3449caa2..d1462d4f4b 100644 --- a/lily/tie-formatting-problem.cc +++ b/lily/tie-formatting-problem.cc @@ -144,7 +144,7 @@ Tie_formatting_problem::set_chord_outline (Link_array bounds, Interval y; if (boxes.size()) { - Box b = boxes.boundary (updowndir, 0); + Box b = boundary (boxes, updowndir, 0); x = b[X_AXIS]; x[-d] = b[X_AXIS].linear_combination (-d / 2); y[-updowndir] = b[Y_AXIS][updowndir]; @@ -785,12 +785,12 @@ Tie_formatting_problem::get_variations (Ties_configuration const &ties) Direction d = DOWN; do { - if (ties.boundary (d, 0).dir_ == d) + if (boundary (ties, d, 0).dir_ == d) { Tie_configuration_variation var; var.index_ = (d == DOWN) ? 0 : ties.size () - 1; - var.suggestion_ = get_configuration (ties.boundary (d, 0).position_ + d, - d); + var.suggestion_ = get_configuration (boundary (ties, d, 0).position_ + + d, d); vars.push_back (var); } }