|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64804 - 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 15:42:21
Author: bbartman
Date: 2010-08-14 15:42:16 EDT (Sat, 14 Aug 2010)
New Revision: 64804
URL: http://svn.boost.org/trac/boost/changeset/64804
Log:
forgot to add assignment operators to all of ther iterators classes and made the safe bool work correctly
Text files modified:
sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp | 292 +++++++++++++++++++++++++++++++++++----
sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/iterator_base.hpp | 18 ++
sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_iterator_test.cpp | 20 ++
sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/iterator_base_test.cpp | 18 +
4 files changed, 310 insertions(+), 38 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 15:42:16 EDT (Sat, 14 Aug 2010)
@@ -18,17 +18,15 @@
template <typename T,std::size_t>
struct bits;
+
+namespace detail {
/** Iterators. */
//@{
template<typename T, std::size_t Width>
class bf_vector_iterator
- :protected detail::bitfield_vector_iterator_base<T,Width>,
- public detail::safe_bool_impl::safe_bool<
- detail::bitfield_vector_iterator_base<T,Width>
- >
+ :protected detail::bitfield_vector_iterator_base<T,Width>
{
typedef detail::bitfield_vector_iterator_base<T,Width> _base;
- typedef detail::safe_bool_impl::safe_bool< _base > _safe_bool;
typedef bf_vector_iterator<T,Width> _self;
public:
@@ -41,25 +39,39 @@
typedef typename _base::difference_type difference_type;
+
bf_vector_iterator()
- :_base(),
- _safe_bool()
+ :_base()
{ }
bf_vector_iterator(_self const& rhs)
- :_base( static_cast<_base>(rhs) ),
- _safe_bool()
+ :_base( static_cast<_base>(rhs) )
{ }
explicit bf_vector_iterator(reference const& x)
- :_base( static_cast<_base>(x) ),
- _safe_bool()
+ :_base( static_cast<proxy_ref_type>(x) )
+ { }
+
+ bf_vector_iterator(storage_ptr_t ptr, std::size_t offset)
+ :_base(ptr, offset)
{ }
+ using _base::operator typename _base::bool_type;
+
+ _self operator=(_self const& rhs) {
+ this->assign(static_cast<_base>(rhs));
+ }
+
reference operator*() const {
return this->deref();
}
+ reference operator[](intmax_t index) const {
+ _self ret(*this);
+ ret.advance(index);
+ return ret.deref();
+ }
+
_self& operator++() {
this->next();
return *this;
@@ -90,31 +102,251 @@
return !this->is_equal(rhs);
}
+ bool operator<(_self const& rhs) const {
+ return this->is_less(static_cast<_base>(rhs));
+ }
};
template<typename T, std::size_t Width>
class const_bf_vector_iterator
- :protected detail::bitfield_vector_iterator_base<T,Width>,
- public detail::safe_bool_impl::safe_bool<
- detail::bitfield_vector_iterator_base<T,Width>
- >
-{ };
+ :protected detail::bitfield_vector_iterator_base<T,Width>
+{
+ typedef detail::bitfield_vector_iterator_base<T,Width> _base;
+ typedef const_bf_vector_iterator<T,Width> _self;
+public:
+
+ typedef typename _base::proxy_ref_type proxy_ref_type;
+ typedef typename _base::const_proxy_ref_type const_proxy_ref_type;
+ typedef typename _base::iterator_category iterator_category;
+ typedef typename _base::value_type value_type;
+ typedef typename _base::pointer pointer;
+ typedef const_proxy_ref_type reference;
+ typedef typename _base::difference_type difference_type;
+
+ using _base::operator typename _base::bool_type;
+
+ const_bf_vector_iterator()
+ :_base()
+ { }
+
+ const_bf_vector_iterator(_self const& rhs)
+ :_base( static_cast<_base>(rhs) )
+ { }
+
+ explicit const_bf_vector_iterator(reference const& x)
+ :_base( static_cast<proxy_ref_type>(x) )
+ { }
+
+ reference operator*() const {
+ return this->const_deref();
+ }
+
+ reference operator[](intmax_t index) const {
+ _self ret(*this);
+ ret.advance(index);
+ return ret.const_deref();
+ }
+
+ _self operator=(_self const& rhs) {
+ this->assign(static_cast<_base>(rhs));
+ }
+
+
+ _self& operator++() {
+ this->next();
+ return *this;
+ }
+
+ _self operator++(int) {
+ _self ret(*this);
+ this->next();
+ return ret;
+ }
+
+ _self& operator--() {
+ this->previous();
+ return *this;
+ }
+
+ _self operator--(int) {
+ _self ret(*this);
+ this->previous();
+ return ret;
+ }
+
+ bool operator==(_self const& rhs) const {
+ return this->is_equal(rhs);
+ }
+
+ bool operator!=(_self const& rhs) const {
+ return !this->is_equal(rhs);
+ }
+
+ bool operator<(_self const& rhs) const {
+ return this->is_less(static_cast<_base>(rhs));
+ }
+};
template<typename T, std::size_t Width>
class bf_vector_reverse_iterator
- :protected detail::bitfield_vector_iterator_base<T,Width>,
- public detail::safe_bool_impl::safe_bool<
- detail::bitfield_vector_iterator_base<T,Width>
- >
-{ };
+ :protected detail::bitfield_vector_iterator_base<T,Width>
+{
+ typedef detail::bitfield_vector_iterator_base<T,Width> _base;
+ typedef bf_vector_reverse_iterator<T,Width> _self;
+public:
+
+ typedef typename _base::proxy_ref_type proxy_ref_type;
+ typedef typename _base::const_proxy_ref_type const_proxy_ref_type;
+ typedef typename _base::iterator_category iterator_category;
+ typedef typename _base::value_type value_type;
+ typedef typename _base::pointer pointer;
+ typedef typename _base::proxy_ref_type reference;
+ typedef typename _base::difference_type difference_type;
+
+ using _base::operator typename _base::bool_type;
+
+ bf_vector_reverse_iterator()
+ :_base()
+ { }
+
+ bf_vector_reverse_iterator(_self const& rhs)
+ :_base( static_cast<_base>(rhs) )
+ { }
+
+ explicit bf_vector_reverse_iterator(reference const& x)
+ :_base( static_cast<proxy_ref_type>(x) )
+ { }
+
+ reference operator*() const {
+ return this->deref();
+ }
+
+ reference operator[](intmax_t index) const {
+ _self ret(*this);
+ ret.advance( index * -1);
+ return ret.deref();
+ }
+
+ _self operator=(_self const& rhs) {
+ this->assign(static_cast<_base>(rhs));
+ }
+
+ _self& operator++() {
+ this->previous();
+ return *this;
+ }
+
+ _self operator++(int) {
+ _self ret(*this);
+ this->previous();
+ return ret;
+ }
+
+ _self& operator--() {
+ this->next();
+ return *this;
+ }
+
+ _self operator--(int) {
+ _self ret(*this);
+ this->next();
+ return ret;
+ }
+
+ bool operator==(_self const& rhs) const {
+ return this->is_equal(rhs);
+ }
+
+ bool operator!=(_self const& rhs) const {
+ return !this->is_equal(rhs);
+ }
+
+ bool operator<(_self const& rhs) const {
+ return this->is_greater(static_cast<_base>(rhs));
+ }
+};
template<typename T, std::size_t Width>
class const_bf_vector_reverse_iterator
- :protected detail::bitfield_vector_iterator_base<T,Width>,
- public detail::safe_bool_impl::safe_bool<
- detail::bitfield_vector_iterator_base<T,Width>
- >
-{ };
+ :protected detail::bitfield_vector_iterator_base<T,Width>
+{
+ typedef detail::bitfield_vector_iterator_base<T,Width> _base;
+ typedef const_bf_vector_reverse_iterator<T,Width> _self;
+public:
+
+ typedef typename _base::proxy_ref_type proxy_ref_type;
+ typedef typename _base::const_proxy_ref_type const_proxy_ref_type;
+ typedef typename _base::iterator_category iterator_category;
+ typedef typename _base::value_type value_type;
+ typedef typename _base::pointer pointer;
+ typedef const_proxy_ref_type reference;
+ typedef typename _base::difference_type difference_type;
+
+ using _base::operator typename _base::bool_type;
+
+ const_bf_vector_reverse_iterator()
+ :_base()
+ { }
+
+ const_bf_vector_reverse_iterator(_self const& rhs)
+ :_base( static_cast<_base>(rhs) )
+ { }
+
+ explicit const_bf_vector_reverse_iterator(reference const& x)
+ :_base( static_cast<proxy_ref_type>(x) )
+ { }
+
+ reference operator*() const {
+ return this->deref();
+ }
+
+ reference operator[](intmax_t index) const {
+ _self ret(*this);
+ ret.advance(index * -1);
+ return ret.const_deref();
+ }
+
+ _self operator=(_self const& rhs) {
+ this->assign(static_cast<_base>(rhs));
+ }
+
+ _self& operator++() {
+ this->previous();
+ return *this;
+ }
+
+ _self operator++(int) {
+ _self ret(*this);
+ this->previous();
+ return ret;
+ }
+
+ _self& operator--() {
+ this->next();
+ return *this;
+ }
+
+ _self operator--(int) {
+ _self ret(*this);
+ this->next();
+ return ret;
+ }
+
+ bool operator==(_self const& rhs) const {
+ return this->is_equal(rhs);
+ }
+
+ bool operator!=(_self const& rhs) const {
+ return !this->is_equal(rhs);
+ }
+
+ bool operator<(_self const& rhs) const {
+ return this->is_greater(static_cast<_base>(rhs));
+ }
+};
+
+} // end detail
+
//@}
@@ -129,10 +361,10 @@
typedef detail::bitfield_vector_base<T,Allocator> _base;
public:
- typedef bf_vector_iterator<T,Width> iterator;
- typedef const_bf_vector_iterator<T,Width> const_iterator;
- typedef bf_vector_reverse_iterator<T,Width> reverse_iterator;
- typedef const_bf_vector_reverse_iterator<T,Width> const_reverse_iterator;
+ typedef detail::bf_vector_iterator<T,Width> iterator;
+ typedef detail::const_bf_vector_iterator<T,Width> const_iterator;
+ typedef detail::bf_vector_reverse_iterator<T,Width> reverse_iterator;
+ typedef detail::const_bf_vector_reverse_iterator<T,Width> const_reverse_iterator;
typedef T value_type;
typedef Allocator allocator_type;
typedef std::size_t size_type;
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 15:42:16 EDT (Sat, 14 Aug 2010)
@@ -77,21 +77,23 @@
template <typename T, std::size_t Width>
struct bitfield_vector_iterator_base
- // :safe_bool_impl::safe_bool_impl< bitfield_vector_iterator_base<T,Width> >
+ :safe_bool_impl::safe_bool< bitfield_vector_iterator_base<T,Width> >
{
/** Typedef's for iterator base class. */
//@{
+
typedef bitfield_vector_iterator_base<T,Width> _self;
+ typedef safe_bool_impl::safe_bool< _self > _base;
typedef proxy_reference_type<T,Width> proxy_ref_type;
typedef const_proxy_reference_type<T,Width> const_proxy_ref_type;
+ typedef typename _base::bool_type bool_type;
// I don't believe that this iterator can be a random access iterator
// until C++0x
typedef std::bidirectional_iterator_tag iterator_category;
typedef T value_type;
typedef T* pointer;
- // typedef proxy_ref_type reference;
typedef std::ptrdiff_t difference_type;
BOOST_STATIC_CONSTANT( std::size_t, width = Width );
//@}
@@ -195,6 +197,18 @@
return true;
}
}
+
+ bool is_greater(_self const& rhs) {
+ if(_ptr >= rhs._ptr) {
+ if(_bit_offset > rhs._bit_offset) {
+ return true;
+ }else{
+ return false;
+ }
+ }else{
+ 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 15:42:16 EDT (Sat, 14 Aug 2010)
@@ -7,6 +7,26 @@
#include <boost/integer/bitfield_vector.hpp>
#include "test_utility.hpp"
+using namespace boost::detail;
+
+/** Test suite for all 4 iterator types of a bitfield_vector.
+ * iterator
+ * const_iterator
+ * reverse_iterator
+ * const_reverse_iterator
+ */
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;
+
+
+ // default constructor
+ iter_1 i1;
+ BOOST_TEST(!i1);
+
+ }
return boost::report_errors();
}
Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/iterator_base_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/iterator_base_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/iterator_base_test.cpp 2010-08-14 15:42:16 EDT (Sat, 14 Aug 2010)
@@ -266,7 +266,6 @@
{
storage_t storage[20];
std::memset(storage,0,20);
- storage_ptr_t ptr = storage;
test_type_1 t1(storage, 0);
test_type_1 t2(t1);
BOOST_TEST( !t1.is_less(t1) );
@@ -276,12 +275,19 @@
BOOST_TEST( t2.is_less(t1) );
}
-/*
-typedef bitfield_vector_iterator_base<unsigned int, 3> test_type_1;
-typedef bitfield_vector_iterator_base<int, 20> test_type_2;
-typedef bitfield_vector_iterator_base<int, 8> test_type_3;
-*/
+ // is_greater
+ {
+ storage_t storage[20];
+ std::memset(storage,0,20);
+ test_type_1 t1(storage, 0);
+ test_type_1 t2(t1);
+ BOOST_TEST( !t1.is_greater(t1) );
+ BOOST_TEST( !t1.is_greater(t2) );
+ t1.next();
+ BOOST_TEST( t1.is_greater(t2) );
+ BOOST_TEST( !t2.is_greater(t1) );
+ }
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