From: Jan Nieuwenhuizen Date: Wed, 1 Feb 2006 23:53:13 +0000 (+0000) Subject: * flower/test-std.cc: Add simple unit test for vector migration. X-Git-Tag: release/2.7.31~26 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=932933b488622911d513602970f0cfc6d5cdb93c;p=lilypond.git * flower/test-std.cc: Add simple unit test for vector migration. * stepmake/stepmake/test*: Unit test support. --- diff --git a/ChangeLog b/ChangeLog index 0d57a291bf..14c7311b08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-02-02 Jan Nieuwenhuizen + + * flower/include/std-vector.hh (slice): Remove. + 2006-02-01 Graham Percival * Documentation/user/putting.itely: fixes from Erik. diff --git a/flower/include/array.hh b/flower/include/array.hh index 9a5b2e4026..fbd3d83620 100644 --- a/flower/include/array.hh +++ b/flower/include/array.hh @@ -38,7 +38,8 @@ template void arrcpy (T *dest, T const *src, int count); template class Array { -protected: +public: + /// maximum length of array. vsize max_; @@ -60,6 +61,9 @@ protected: public: /* std::vector interface */ + typedef T* iterator; + typedef T const* const_iterator; + Array () { array_ = 0; @@ -73,6 +77,8 @@ public: max_ = size_ = src.size_; } + Array (const_iterator begin, const_iterator end); + T const &back () const { return (*this)[size_ - 1]; @@ -115,7 +121,11 @@ public: return array_; } - typedef T* iterator; + T const* + data () const + { + return array_; + } iterator begin () @@ -123,7 +133,7 @@ public: return data (); } - iterator const + const_iterator begin () const { return data (); @@ -135,7 +145,7 @@ public: return data () + size_; } - iterator const + const_iterator end () const { return data () + size_; @@ -143,7 +153,8 @@ public: void clear () { - resize (0); + //resize (0); + size_ = 0; } /* std::vector uses unchecked variant for [] */ @@ -317,7 +328,6 @@ public: resize (size_ + src.size_); arrcpy (array_ + s, src.array_, src.size_); } - Array slice (vsize lower, vsize upper) const; void reverse (); }; diff --git a/flower/include/array.icc b/flower/include/array.icc index 3b6c27945c..4f1a9d0bf9 100644 --- a/flower/include/array.icc +++ b/flower/include/array.icc @@ -104,19 +104,12 @@ Array::remove_array () } template INLINE -Array -Array::slice (vsize lower, vsize upper) const +Array::Array (const_iterator b, const_iterator e) { -#if !STD_VECTOR - assert (lower >= 0 && lower <= upper && upper <= size_); -#else - assert (lower <= upper && upper <= size_); -#endif - Array r; - vsize s = upper - lower; - r.resize (s); - arrcpy (r.array_, array_ + lower, s); - return r; + vsize n = e - b; + array_ = new T[n]; + max_ = size_ = n; + arrcpy (array_, b, n); } template diff --git a/flower/include/parray.hh b/flower/include/parray.hh index 40dcb22305..d89c2b95d2 100644 --- a/flower/include/parray.hh +++ b/flower/include/parray.hh @@ -21,7 +21,7 @@ template class Link_array : private Array { - Link_array (Array v) + Link_array (Array const &v) :Array (v) { } @@ -73,6 +73,7 @@ public: : Array (src) { } + /// access element T *elem (int i) const { @@ -187,7 +188,7 @@ public: Link_array slice (int l, int u) const { - return Array::slice (l, u); + return Array::Array (begin () + l, begin () + u); } void concat (Link_array const &a2) { diff --git a/flower/include/std-vector.hh b/flower/include/std-vector.hh index db6cb9241e..e5920fee52 100644 --- a/flower/include/std-vector.hh +++ b/flower/include/std-vector.hh @@ -41,33 +41,32 @@ namespace std { { public: typedef typename __vector::iterator iterator; + typedef typename __vector::const_iterator const_iterator; vector () : __vector () { } - vector (iterator const b, iterator const e) : __vector (b, e) + vector (const_iterator b, const_iterator e) : __vector (b, e) { } - vector (vsize b, vsize e) : __vector (iter (b), iter (e)) - { - } - - iterator iter (vsize n) + iterator + iter (vsize n) { if (n == VPOS) return this->end (); return __vector::begin () + n; } - iterator const iter (vsize n) const + const_iterator + iter (vsize n) const { if (n == VPOS) return this->end (); return __vector::begin () + n; } - + void insert (T k, vsize i) { @@ -163,12 +162,6 @@ namespace std { ::std::reverse (this->begin (), this->end ()); } - vector - slice (vsize b, vsize e) const - { - return vector (b, e); - } - void sort (int vsize=VPOS, vsize b=VPOS, vsize e=VPOS) { @@ -210,7 +203,7 @@ namespace std { vsize b=0, vsize e=VPOS) { //(void) compare; - vector::iterator const i = find (v.iter (b), v.iter (e), key); + typename vector::const_iterator i = find (v.iter (b), v.iter (e), key); if (i != v.end ()) return i - v.begin (); return VPOS; diff --git a/flower/test-std.cc b/flower/test-std.cc index 85e0a372fa..1e3f0f125f 100644 --- a/flower/test-std.cc +++ b/flower/test-std.cc @@ -10,12 +10,17 @@ using boost::unit_test::test_suite; +#if !STD_VECTOR +#define vector flower_vector +#endif + template void print (vector v) { for (vsize i = 0; i < v.size (); i++) cout << "v[" << i << "] = " << v[i] << endl; + cout << endl; } BOOST_AUTO_UNIT_TEST (vector_erase) @@ -23,23 +28,42 @@ BOOST_AUTO_UNIT_TEST (vector_erase) vector v; v.push_back (0); v.push_back (1); - BOOST_CHECK_EQUAL (v.size (), 2u); + BOOST_CHECK_EQUAL (v.size (), vsize (2)); v.erase (v.begin () + 1); - BOOST_CHECK_EQUAL (v.size (), 1u); + BOOST_CHECK_EQUAL (v.size (), vsize (1)); BOOST_CHECK_EQUAL (v.back (), 0); v.push_back (1); - BOOST_CHECK_EQUAL (v.size (), 2u); + BOOST_CHECK_EQUAL (v.size (), vsize (2)); v.erase (v.begin () + 0); - BOOST_CHECK_EQUAL (v.size (), 1u); + BOOST_CHECK_EQUAL (v.size (), vsize (1)); BOOST_CHECK_EQUAL (v.back (), 1); } +BOOST_AUTO_UNIT_TEST (vector_slice) +{ + vector v; + v.push_back (0); + v.push_back (1); + v.push_back (2); + v.push_back (3); +#if VECTOR_SLICE + BOOST_CHECK_EQUAL (v.slice (0, 0).size (), vsize (0)); + BOOST_CHECK_EQUAL (v.slice (0, v.size ()).size (), v.size ()); + BOOST_CHECK_EQUAL (v.slice (1, 2).size (), vsize (1)); +#else + BOOST_CHECK_EQUAL (vector (v.begin (), v.begin ()).size (), vsize (0)); + BOOST_CHECK_EQUAL (vector (v.begin (), v.end ()).size (), v.size ()); + BOOST_CHECK_EQUAL (vector (v.begin () + 1, v.begin () + 2).size (), + vsize (1)); +#endif +} test_suite* init_unit_test_suite (int, char**) { test_suite *test = BOOST_TEST_SUITE("std::Flower"); test->add (BOOST_TEST_CASE (vector_erase)); + test->add (BOOST_TEST_CASE (vector_slice)); return test; } diff --git a/lily/beaming-info.cc b/lily/beaming-info.cc index 7a5428c1ba..9109aea5a7 100644 --- a/lily/beaming-info.cc +++ b/lily/beaming-info.cc @@ -68,8 +68,10 @@ Beaming_info_list::beamify (Moment &beat_length, bool subdivide) Drul_array splits; int m = best_splitpoint_index (beat_length, subdivide); bool split = subdivide && (m & at_beat); m = m & ~at_beat; - splits[LEFT].infos_ = infos_.slice (0, m); - splits[RIGHT].infos_ = infos_.slice (m, infos_.size ()); + splits[LEFT].infos_ = std::vector (infos_.begin (), + infos_.begin () + m); + splits[RIGHT].infos_ = std::vector (infos_.begin () + m, + infos_.end ()); Direction d = LEFT; diff --git a/lily/new-fingering-engraver.cc b/lily/new-fingering-engraver.cc index 23d735ec9f..02bb58267b 100644 --- a/lily/new-fingering-engraver.cc +++ b/lily/new-fingering-engraver.cc @@ -246,8 +246,10 @@ New_fingering_engraver::position_scripts (SCM orientations, else if (up_p && down_p) { int center = scripts->size () / 2; - down.concat (scripts->slice (0, center)); - up.concat (scripts->slice (center, scripts->size ())); + down.concat (std::vector (scripts->begin (), + scripts->begin () + center)); + up.concat (std::vector (scripts->begin () + center, + scripts->end ())); } else if (up_p) {