Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64802 - in sandbox/SOC/2010/bit_masks: boost/integer boost/integer/detail/bitfield_vector lib/integer/test lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-08-14 13:24:07


Author: bbartman
Date: 2010-08-14 13:24:05 EDT (Sat, 14 Aug 2010)
New Revision: 64802
URL: http://svn.boost.org/trac/boost/changeset/64802

Log:
working on implementing iterators for the bitfield_vector class
Added:
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_iterator_test.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp | 28 ++++++++++++++++++++++++----
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/iterator_base.hpp | 39 ++++++++++++++-------------------------
   sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2 | 1 +
   3 files changed, 39 insertions(+), 29 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 13:24:05 EDT (Sat, 14 Aug 2010)
@@ -21,16 +21,36 @@
 /** Iterators. */
 //@{
 template<typename T, std::size_t Width>
-struct bf_vector_iterator { };
+struct 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>
+ >
+{ };
 
 template<typename T, std::size_t Width>
-struct const_bf_vector_iterator { };
+struct 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>
+ >
+{ };
 
 template<typename T, std::size_t Width>
-struct bf_vector_reverse_iterator { };
+struct 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>
+ >
+{ };
 
 template<typename T, std::size_t Width>
-struct const_bf_vector_reverse_iterator { };
+struct 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>
+ >
+{ };
 //@}
 
 

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 13:24:05 EDT (Sat, 14 Aug 2010)
@@ -13,7 +13,10 @@
 #include <iostream>
 #include <boost/cstdint.hpp>
 
-namespace boost { namespace detail { namespace safe_bool_impl {
+namespace boost { namespace detail {
+
+namespace safe_bool_impl {
+
 class safe_bool_base {
 protected:
     typedef void (safe_bool_base::* bool_type )() const;
@@ -28,7 +31,7 @@
 };
 
 template <typename T>
-struct safe_bool_impl
+struct safe_bool
     :safe_bool_base
 {
 operator bool_type() const {
@@ -36,17 +39,17 @@
         ? &safe_bool_base::this_type_does_not_support_comparisons : 0;
 }
 protected:
- ~safe_bool_impl() {}
+ ~safe_bool() {}
 };
 
 template <typename T, typename U>
-void operator==(safe_bool_impl<T> const & lhs,safe_bool_impl<U> const& rhs) {
+void operator==(safe_bool<T> const & lhs,safe_bool<U> const& rhs) {
     lhs.this_type_does_not_support_comparisons();
     return false;
 }
 
 template <typename T,typename U>
-void operator!=(safe_bool_impl<T> const& lhs, safe_bool_impl<U> const& rhs) {
+void operator!=(safe_bool<T> const& lhs, safe_bool<U> const& rhs) {
     lhs.this_type_does_not_support_comparisons();
     return false;
 }
@@ -147,34 +150,20 @@
         // Comment for the following line of code.
         // In the case that previous_offset%8 is actually less then 8
         // will construct a size_t with 1 and left shift it 3 making it
- // positive 8. This is done to avoid branching inside of a
- // decrement operation and this only works if the value is true
- // otherwise the value is zero which is the behavior I want.
+ // positive 8. This is done to avoid branching inside of
+ // 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);
     }
     
     void next() {
- unsigned int next_offset;
- next_offset = _bit_offset + Width;
- _ptr += (next_offset / 8);
- _bit_offset = next_offset % 8;
+ advance(1);
     }
 
     void previous() {
- typedef typename make_signed<std::size_t>::type signed_size_t;
- signed_size_t previous_offset = signed_size_t(_bit_offset);
- previous_offset -= signed_size_t(Width);
- _ptr -= std::size_t((previous_offset%8)<0)+((previous_offset / 8)*-1);
-
- // Comment for the following line of code.
- // In the case that previous_offset%8 is actually less then 8
- // will construct a size_t with 1 and left shift it 3 making it
- // positive 8. This is done to avoid branching inside of a
- // decrement operation 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);
+ advance(-1);
     }
 
     std::ptrdiff_t distance(_self const& rhs) const {

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2 (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2 2010-08-14 13:24:05 EDT (Sat, 14 Aug 2010)
@@ -78,5 +78,6 @@
         [ run bitfield_vector_testing/member_impl_test.cpp ]
         [ run bitfield_vector_testing/mask_creator_test.cpp ]
         [ run bitfield_vector_testing/iterator_base_test.cpp ]
+ [ run bitfield_vector_testing/bitfield_vector_iterator_test.cpp ]
     ;
 

Added: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_iterator_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_iterator_test.cpp 2010-08-14 13:24:05 EDT (Sat, 14 Aug 2010)
@@ -0,0 +1,12 @@
+// Copyright 2010 Brian Bartman.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+#include <boost/integer/bitfield_vector.hpp>
+#include "test_utility.hpp"
+
+int main() {
+ 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