From 516d97f9a3f38aa406ca5819a41e1e0f5473e320 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 2 Feb 2006 14:00:45 +0000 Subject: [PATCH] * flower/include/std-vector.hh * flower/include/parray.hh * flower/include/array.hh (elem, elem_ref): Globally replace by at (). --- ChangeLog | 10 ++++++++ flower/include/array.hh | 33 ++++++++++++++++++------- flower/include/array.icc | 15 ------------ flower/include/parray.hh | 6 ++++- flower/include/std-vector.hh | 6 ----- flower/test-std.cc | 55 ++++++++++++++++++++++++++++++++++++++++++ lily/accidental-placement.cc | 2 +- lily/beaming-info.cc | 2 +- lily/new-fingering-engraver.cc | 12 ++++----- 9 files changed, 101 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 560d7cd2ee..244399ea03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-02-02 Jan Nieuwenhuizen + + * 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 (). + 2006-02-02 Han-Wen Nienhuys * Documentation/topdocs/NEWS.tely (Top): use ly: prefix for members. diff --git a/flower/include/array.hh b/flower/include/array.hh index d25f34c346..8a941c13aa 100644 --- a/flower/include/array.hh +++ b/flower/include/array.hh @@ -25,7 +25,7 @@ using namespace std; namespace std { /// copy a bare (C-)array from #src# to #dest# sized #count# -template void arrcpy (T *dest, T const *src, int count); +template void arrcpy (T *dest, T const *src, vsize count); /** Scaleable array/stack template, for a type T with default constructor. @@ -195,6 +195,29 @@ public: return p; } + void + insert (iterator b, T k) + { + vsize j = b - array_; + resize (size_ + 1); + index_assert (j); + for (vsize i = size_ - 1; i > j; i--) + array_[i] = array_[i - 1]; + array_[j] = k; + } + + void + insert (iterator pos, const_iterator b, const_iterator e) + { + vsize j = pos - array_; + vsize k = e - b; + resize (size_ + k); + for (vsize i = size_ - 1; i > j + k; i--) + array_[i] = array_[i - k]; + for (vsize i = j; i < j + k; i++) + array_[i] = b[i - j]; + } + /// add to the end of array void push_back (T x) { @@ -296,19 +319,11 @@ public: (*this)[j] = t; } - void insert (iterator j, T k); - void unordered_del (vsize i) { at (i) = back (); resize (size () -1); } - void concat (Array const &src) - { - vsize s = size_; - resize (size_ + src.size_); - arrcpy (array_ + s, src.array_, src.size_); - } void reverse (); }; diff --git a/flower/include/array.icc b/flower/include/array.icc index 0d1c0ead72..924646df5a 100644 --- a/flower/include/array.icc +++ b/flower/include/array.icc @@ -37,21 +37,6 @@ arrcpy (T *dest, T const *src, vsize count) #endif } -template INLINE void -Array::insert (iterator b, T k) -{ - vsize j = b - array_; -#if !STD_VECTOR - assert (j >= 0 && j <= size_); -#else - assert (j <= size_); -#endif - resize (size_ + 1); - for (vsize i = size_ - 1; i > j; i--) - array_[i] = array_[i - 1]; - array_[j] = k; -} - template INLINE void vector_sort (Array &v, int (*compare) (T const &, T const &), vsize lower=-1, vsize upper=-1) diff --git a/flower/include/parray.hh b/flower/include/parray.hh index 80145929e1..e85c1d9f73 100644 --- a/flower/include/parray.hh +++ b/flower/include/parray.hh @@ -104,6 +104,10 @@ public: { Array::insert (b, t); } + void insert (iterator pos, const_iterator b, const_iterator e) + { + Array::insert (pos, b, e); + } void push_back (T *t) { Array::push_back (t); @@ -192,7 +196,7 @@ public: } void concat (Link_array const &a2) { - Array::concat (a2); + Array::insert (end (), a2.begin (), a2.end ()); } int find_index (T const *t) const { diff --git a/flower/include/std-vector.hh b/flower/include/std-vector.hh index 7c95720262..c70c9449a9 100644 --- a/flower/include/std-vector.hh +++ b/flower/include/std-vector.hh @@ -52,12 +52,6 @@ namespace std { } /* Flower-Array compatibility. */ - void - concat (vector const &v) - { - __vector::insert (this->end (), v.begin (), v.end ()); - } - T const & boundary (int dir, vsize i) const { diff --git a/flower/test-std.cc b/flower/test-std.cc index bd79ffd95e..72e86f110a 100644 --- a/flower/test-std.cc +++ b/flower/test-std.cc @@ -3,6 +3,8 @@ #endif #include "std-vector.hh" +#include "parray.hh" + #include #include @@ -23,6 +25,16 @@ print (vector v) cout << endl; } +template +void +print (Link_array v) +{ + for (vsize i = 0; i < v.size (); i++) + cout << "v[" << i << "] = " << *v[i] << endl; + cout << endl; +} + + BOOST_AUTO_UNIT_TEST (vector_erase) { vector v; @@ -91,6 +103,48 @@ BOOST_AUTO_UNIT_TEST (vector_insert) v.insert (v.end (), 2); #endif BOOST_CHECK_EQUAL (v.back (), 2); + vector u; + u.insert (u.begin (), v.begin (), v.end ()); + BOOST_CHECK_EQUAL (u.size (), v.size ()); + u.clear (); + u.insert (u.end (), v.begin (), v.end ()); + BOOST_CHECK_EQUAL (u.size (), v.size ()); + u.clear (); +} + +BOOST_AUTO_UNIT_TEST (parray_concat) +{ + Link_array u, v; + int a[5] = { 0, 1, 2, 3, 4 }; + u.push_back (&a[0]); + u.push_back (&a[1]); + u.push_back (&a[2]); + v.push_back (&a[3]); + v.push_back (&a[4]); + u.concat (v); + BOOST_CHECK_EQUAL (u[0], &a[0]); + BOOST_CHECK_EQUAL (u[1], &a[1]); + BOOST_CHECK_EQUAL (u[2], &a[2]); + BOOST_CHECK_EQUAL (u[3], &a[3]); + BOOST_CHECK_EQUAL (u[4], &a[4]); + BOOST_CHECK_EQUAL (u.size (), vsize (5)); + u.concat (v); + BOOST_CHECK_EQUAL (u.size (), vsize (7)); + + u.clear (); + v.clear (); + v.push_back (&a[0]); + v.push_back (&a[1]); + v.push_back (&a[2]); + v.push_back (&a[3]); + v.push_back (&a[4]); + u.concat (v); + BOOST_CHECK_EQUAL (u[0], &a[0]); + BOOST_CHECK_EQUAL (u[1], &a[1]); + BOOST_CHECK_EQUAL (u[2], &a[2]); + BOOST_CHECK_EQUAL (u[3], &a[3]); + BOOST_CHECK_EQUAL (u[4], &a[4]); + BOOST_CHECK_EQUAL (u.size (), vsize (5)); } test_suite* @@ -101,5 +155,6 @@ init_unit_test_suite (int, char**) test->add (BOOST_TEST_CASE (vector_slice)); test->add (BOOST_TEST_CASE (vector_sorting)); test->add (BOOST_TEST_CASE (vector_insert)); + test->add (BOOST_TEST_CASE (parray_concat)); return test; } diff --git a/lily/accidental-placement.cc b/lily/accidental-placement.cc index 013887153d..d35089066e 100644 --- a/lily/accidental-placement.cc +++ b/lily/accidental-placement.cc @@ -305,7 +305,7 @@ Accidental_placement::calc_positioning_done (SCM smob) std::vector boxes = Accidental_interface::accurate_boxes (a, common); - ape->extents_.concat (boxes); + ape->extents_.insert (ape->extents_.end (), boxes.begin (), boxes.end ()); for (vsize j = boxes.size (); j--;) { insert_extent_into_skyline (&ape->left_skyline_, boxes[j], Y_AXIS, LEFT); diff --git a/lily/beaming-info.cc b/lily/beaming-info.cc index 9109aea5a7..11c6dde0c6 100644 --- a/lily/beaming-info.cc +++ b/lily/beaming-info.cc @@ -92,7 +92,7 @@ Beaming_info_list::beamify (Moment &beat_length, bool subdivide) while (flip (&d) != LEFT); infos_ = splits[LEFT].infos_; - infos_.concat (splits[RIGHT].infos_); + infos_.insert (infos_.end (), splits[RIGHT].infos_.begin (), splits[RIGHT].infos_.end ()); clip_edges (); } diff --git a/lily/new-fingering-engraver.cc b/lily/new-fingering-engraver.cc index 56a0c37d28..1e74bbba34 100644 --- a/lily/new-fingering-engraver.cc +++ b/lily/new-fingering-engraver.cc @@ -241,19 +241,17 @@ New_fingering_engraver::position_scripts (SCM orientations, scripts->erase (scripts->begin ()); } - horiz.concat (*scripts); + horiz.insert (horiz.end (), scripts->begin (), scripts->end ()); } else if (up_p && down_p) { int center = scripts->size () / 2; - down.concat (std::vector (scripts->begin (), - scripts->begin () + center)); - up.concat (std::vector (scripts->begin () + center, - scripts->end ())); + down.insert (down.end (), scripts->begin (), scripts->begin () + center); + up.insert (up.end (), scripts->begin () + center, scripts->end ()); } else if (up_p) { - up.concat (*scripts); + up.insert (up.end (), scripts->begin (), scripts->end ()); scripts->clear (); } else @@ -263,7 +261,7 @@ New_fingering_engraver::position_scripts (SCM orientations, warning (_ ("no placement found for fingerings")); warning (_ ("placing below")); } - down.concat (*scripts); + down.insert (down.end (), scripts->begin (), scripts->end ()); scripts->clear (); } -- 2.11.4.GIT