|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64805 - in sandbox/SOC/2010/bit_masks: boost/integer boost/integer/detail/bitfield_vector lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-08-14 16:49:23
Author: bbartman
Date: 2010-08-14 16:49:18 EDT (Sat, 14 Aug 2010)
New Revision: 64805
URL: http://svn.boost.org/trac/boost/changeset/64805
Log:
all iterators completed and tested
Text files modified:
sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp | 126 ++++++++++++++++++++++++++++++-
sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/iterator_base.hpp | 5
sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_iterator_test.cpp | 157 ++++++++++++++++++++++++++++++++++++++-
3 files changed, 275 insertions(+), 13 deletions(-)
Modified: sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp 2010-08-14 16:49:18 EDT (Sat, 14 Aug 2010)
@@ -38,8 +38,6 @@
typedef typename _base::proxy_ref_type reference;
typedef typename _base::difference_type difference_type;
-
-
bf_vector_iterator()
:_base()
{ }
@@ -93,7 +91,33 @@
this->previous();
return ret;
}
-
+
+ _self& operator+=(int rhs) {
+ this->advance(rhs);
+ return *this;
+ }
+
+ _self& operator-=(int rhs) {
+ this->advance(rhs * -1);
+ return *this;
+ }
+
+ _self operator+(int rhs) const {
+ _self ret(*this);
+ ret.advance(rhs);
+ return ret;
+ }
+
+ _self operator-(int rhs) const {
+ _self ret(*this);
+ ret.advance(rhs * -1);
+ return ret;
+ }
+
+ difference_type operator-(_self const& rhs) const {
+ return this->distance( static_cast<_base>(rhs) );
+ }
+
bool operator==(_self const& rhs) const {
return this->is_equal(rhs);
}
@@ -137,6 +161,10 @@
:_base( static_cast<proxy_ref_type>(x) )
{ }
+ const_bf_vector_iterator(storage_ptr_t ptr, std::size_t offset)
+ :_base(ptr, offset)
+ { }
+
reference operator*() const {
return this->const_deref();
}
@@ -173,6 +201,32 @@
this->previous();
return ret;
}
+
+ _self& operator+=(int rhs) {
+ this->advance(rhs);
+ return *this;
+ }
+
+ _self& operator-=(int rhs) {
+ this->advance(rhs * -1);
+ return *this;
+ }
+
+ _self operator+(int rhs) const {
+ _self ret(*this);
+ ret.advance(rhs);
+ return ret;
+ }
+
+ _self operator-(int rhs) const {
+ _self ret(*this);
+ ret.advance(rhs * -1);
+ return ret;
+ }
+
+ difference_type operator-(_self const& rhs) const {
+ return this->distance(static_cast<_base>(rhs) );
+ }
bool operator==(_self const& rhs) const {
return this->is_equal(rhs);
@@ -209,6 +263,10 @@
:_base()
{ }
+ bf_vector_reverse_iterator(storage_ptr_t ptr, std::size_t offset)
+ :_base(ptr, offset)
+ { }
+
bf_vector_reverse_iterator(_self const& rhs)
:_base( static_cast<_base>(rhs) )
{ }
@@ -252,6 +310,32 @@
this->next();
return ret;
}
+
+ _self& operator+=(int rhs) {
+ this->advance(rhs * -1);
+ return *this;
+ }
+
+ _self& operator-=(int rhs) {
+ this->advance(rhs);
+ return *this;
+ }
+
+ _self operator+(int rhs) const {
+ _self ret(*this);
+ ret.advance(rhs * -1);
+ return ret;
+ }
+
+ _self operator-(int rhs) const {
+ _self ret(*this);
+ ret.advance(rhs);
+ return ret;
+ }
+
+ difference_type operator-(_self const& rhs) const {
+ return rhs.distance( static_cast<_base>(*this) );
+ }
bool operator==(_self const& rhs) const {
return this->is_equal(rhs);
@@ -262,7 +346,7 @@
}
bool operator<(_self const& rhs) const {
- return this->is_greater(static_cast<_base>(rhs));
+ return rhs.is_greater(static_cast<_base>(*this));
}
};
@@ -292,12 +376,16 @@
:_base( static_cast<_base>(rhs) )
{ }
+ const_bf_vector_reverse_iterator(storage_ptr_t ptr, std::size_t offset)
+ :_base(ptr, offset)
+ { }
+
explicit const_bf_vector_reverse_iterator(reference const& x)
:_base( static_cast<proxy_ref_type>(x) )
{ }
reference operator*() const {
- return this->deref();
+ return this->const_deref();
}
reference operator[](intmax_t index) const {
@@ -331,6 +419,32 @@
this->next();
return ret;
}
+
+ _self& operator+=(int rhs) {
+ this->advance(rhs * -1);
+ return *this;
+ }
+
+ _self& operator-=(int rhs) {
+ this->advance(rhs);
+ return *this;
+ }
+
+ _self operator+(int rhs) const {
+ _self ret(*this);
+ ret.advance(rhs * -1);
+ return ret;
+ }
+
+ _self operator-(int rhs) const {
+ _self ret(*this);
+ ret.advance(rhs);
+ return ret;
+ }
+
+ difference_type operator-(_self const& rhs) const {
+ return rhs.distance( static_cast<_base>(*this) );
+ }
bool operator==(_self const& rhs) const {
return this->is_equal(rhs);
@@ -341,7 +455,7 @@
}
bool operator<(_self const& rhs) const {
- return this->is_greater(static_cast<_base>(rhs));
+ return rhs.is_greater(static_cast<_base>(*this));
}
};
Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/iterator_base.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/iterator_base.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/iterator_base.hpp 2010-08-14 16:49:18 EDT (Sat, 14 Aug 2010)
@@ -145,8 +145,7 @@
// increment and decrement operations and this only works if
// the value is true otherwise the value is zero which is
// the behavior I want.
- _bit_offset = (std::size_t((previous_offset%8)<0)<<3)
- + (previous_offset % 8);
+ _bit_offset = (std::size_t((previous_offset%8)<0)<<3) + (previous_offset % 8);
}
void next() {
@@ -198,7 +197,7 @@
}
}
- bool is_greater(_self const& rhs) {
+ bool is_greater(_self const& rhs) const {
if(_ptr >= rhs._ptr) {
if(_bit_offset > rhs._bit_offset) {
return true;
Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_iterator_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_iterator_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_iterator_test.cpp 2010-08-14 16:49:18 EDT (Sat, 14 Aug 2010)
@@ -18,15 +18,164 @@
int main() {
// bf_vector_iterator
{
- typedef bf_vector_iterator<unsigned int, 3> iter_1;
- typedef bf_vector_iterator<unsigned int, 9> iter_2;
- typedef bf_vector_iterator<unsigned int, 10> iter_3;
-
+ typedef bf_vector_iterator<unsigned int, 4> iter_1;
// default constructor
iter_1 i1;
BOOST_TEST(!i1);
+ storage_t storage[20];
+ std::memset(storage,0,20);
+
+ // 2 parameter constructor
+ iter_1 i2(storage,0);
+ BOOST_TEST(i2);
+ // copy constructor
+ iter_1 i3(i2);
+ BOOST_TEST(i3 == i2);
+ ++i2;
+
+ BOOST_TEST(i3 < i2);
+ BOOST_TEST(i3 != i2);
+ *i3 = 4;
+ --i2;
+
+ BOOST_TEST(*i2 == 4);
+ i2++;
+ BOOST_TEST(*i2 == 0);
+ i2 -= 1;
+ BOOST_TEST(i2 == i3);
+
+ i2+=2;
+ i2--;
+ i3++;
+ BOOST_TEST(i3 == i2);
+ iter_1 i4(storage,0);
+ iter_1 i5(storage,0);
+ BOOST_TEST( i5 - i4 == 0);
+ i5+=4;
+ BOOST_TEST( i5 - i4 == 4);
+ }
+ {
+ typedef const_bf_vector_iterator<unsigned int, 4> iter_1;
+ typedef bf_vector_iterator<unsigned int, 4> iter_2;
+ iter_1 i1;
+ BOOST_TEST(!i1);
+
+ storage_t storage[20];
+ std::memset(storage,0,20);
+
+ // 2 parameter constructor
+ iter_1 i2(storage,0);
+ BOOST_TEST(i2);
+ // copy constructor
+ iter_1 i3(i2);
+ BOOST_TEST(i3 == i2);
+ ++i2;
+
+ BOOST_TEST(i3 < i2);
+ BOOST_TEST(i3 != i2);
+ iter_2 non_const_iter(storage,0);
+ *non_const_iter = 4;
+ --i2;
+
+ BOOST_TEST(*i2 == 4);
+ i2++;
+ BOOST_TEST(*i2 == 0);
+ i2 -= 1;
+ BOOST_TEST(i2 == i3);
+
+ i2+=2;
+ i2--;
+ i3++;
+ BOOST_TEST(i3 == i2);
+ iter_2 i4(storage,0);
+ iter_2 i5(storage,0);
+ BOOST_TEST( i5 - i4 == 0);
+ i5+=4;
+ BOOST_TEST( i5 - i4 == 4);
+ }
+ {
+ typedef bf_vector_reverse_iterator<unsigned int, 4> iter_1;
+ iter_1 i1;
+ BOOST_TEST(!i1);
+
+ storage_t storage[20];
+ std::memset(storage,0,20);
+
+ // 2 parameter constructor
+ iter_1 i2(storage + 19, 0);
+ BOOST_TEST(i2);
+ // copy constructor
+ iter_1 i3(i2);
+ BOOST_TEST(i3 == i2);
+ ++i2;
+
+ BOOST_TEST(i3 < i2);
+ BOOST_TEST(i3 != i2);
+
+ *i2 = 4;
+ --i2;
+
+ BOOST_TEST(*i2 == 0);
+ i2++;
+ BOOST_TEST(*i2 == 4);
+
+ i2 -= 1;
+ BOOST_TEST(i2 == i3);
+
+ i2+=2;
+ i2--;
+ i3++;
+ BOOST_TEST(i3 == i2);
+ iter_1 i4(storage,0);
+ iter_1 i5(storage,0);
+ BOOST_TEST( i5 - i4 == 0);
+ i5+=4;
+ BOOST_TEST( i5 - i4 == 4);
+ }
+
+ {
+ typedef bf_vector_reverse_iterator<unsigned int, 4> iter_2;
+ typedef const_bf_vector_reverse_iterator<unsigned int, 4> iter_1;
+ iter_1 i1;
+ BOOST_TEST(!i1);
+
+ storage_t storage[20];
+ std::memset(storage,0,20);
+
+ // 2 parameter constructor
+ iter_1 i2(storage + 19, 0);
+ BOOST_TEST(i2);
+ // copy constructor
+ iter_1 i3(i2);
+ BOOST_TEST(i3 == i2);
+ ++i2;
+
+ BOOST_TEST(i3 < i2);
+ BOOST_TEST(i3 != i2);
+ iter_2 non_const_iter(storage,0);
+ *non_const_iter = 4;
+ iter_1 const_iter(storage,0);
+ BOOST_TEST(*const_iter == 4);
+
+ --i2;
+
+ BOOST_TEST(*i2 == 0);
+ i2++;
+
+ i2 -= 1;
+ BOOST_TEST(i2 == i3);
+
+ i2+=2;
+ i2--;
+ i3++;
+ BOOST_TEST(i3 == i2);
+ iter_1 i4(storage,0);
+ iter_1 i5(storage,0);
+ BOOST_TEST( i5 - i4 == 0);
+ i5+=4;
+ BOOST_TEST( i5 - i4 == 4);
}
return boost::report_errors();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk