Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64618 - in sandbox/SOC/2010/bit_masks: boost/integer/detail/bitfield_vector lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-08-05 13:04:28


Author: bbartman
Date: 2010-08-05 13:04:25 EDT (Thu, 05 Aug 2010)
New Revision: 64618
URL: http://svn.boost.org/trac/boost/changeset/64618

Log:
completed testing for mask creating utilities for the bitfield_vector's proxy_reference_type
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp | 9 ++
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp | 114 +++++++++++++++++++++++++++++++++++++++
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp | 92 ++++++++++++++++++++++++++++++++
   3 files changed, 212 insertions(+), 3 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_base.hpp 2010-08-05 13:04:25 EDT (Thu, 05 Aug 2010)
@@ -9,6 +9,13 @@
 
 namespace boost { namespace detail {
 
+
+/** Typedef's used through out the bitfield_vector.
+ *
+ */
+typedef unsigned char storage_t;
+typedef storage_t* storage_ptr_t;
+
 /** bitfield_vector_base
  * This a bitfield_vector's base class (if you can't tell by the name) and it
  * is used for dealing directly with the allocator's memory allocation
@@ -23,7 +30,7 @@
  */
 template <typename T, typename Allocator>
 struct bitfield_vector_base {
- typedef unsigned char storage_type;
+ typedef storage_t storage_type;
     typedef T value_type;
     typedef typename Allocator::template rebind<storage_type>::other
         rebound_alloc_type;

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp 2010-08-05 13:04:25 EDT (Thu, 05 Aug 2010)
@@ -11,6 +11,7 @@
 #include <boost/mpl/if.hpp>
 #include <boost/mpl/equal.hpp>
 #include <boost/type_traits/is_signed.hpp>
+#include <boost/assert.hpp>
 #include <iostream>
 #include <iomanip>
 #include <cstring>
@@ -131,6 +132,114 @@
 };
 
 
+
+/** Calculates the size of an array needed to store a particular mask inside of
+ * of char array.
+ */
+template <std::size_t Width>
+inline std::size_t get_mask_array_size(std::size_t offset) {
+ BOOST_ASSERT(( offset < 8));
+ std::size_t total_bits = Width + offset;
+ std::size_t ret = 0;
+ ret = total_bits / 8;
+ if(total_bits % 8) {
+ ret += 1;
+ }
+ return ret;
+}
+
+
+void print_mask_array(storage_ptr_t start,storage_ptr_t end) {
+ std::cout << "Value Of Mask Array: " ;
+ for(;start != end;++start) {
+ std::cout << std::hex << std::size_t(*start) << "|";
+ }
+ std::cout << std::endl;
+}
+/** Creates a mask the which is used to extract the information from within
+ * a the storage unsigned char array.
+ */
+template <std::size_t Width>
+inline storage_ptr_t
+make_field_mask(std::size_t offset, std::size_t mask_size) {
+ // std::cout << "Called: " << __FUNCTION__ << std::endl;
+ // I should consider using malloc for something like this shouldn't I.
+ // either way all I need to remember to do is make sure that it gets
+ // deleted.
+ storage_ptr_t mask_array = new storage_t[mask_size];
+ // print_mask_array(mask_array, mask_array + mask_size);
+ storage_ptr_t mask_ptr = mask_array;
+
+ // calculate bit_count for for statement
+ std::size_t bit_count = Width + offset;
+ storage_t mask = 0x80;
+ mask >>= offset;
+
+ // std::cout << "Value Of mask before loop: "
+ // << std::hex << std::size_t(mask) << std::endl;
+
+ // creating begining mask.
+ for(std::size_t index = offset;
+ index < bit_count && index <= 8;
+ ++index)
+ {
+ *mask_ptr |= mask;
+ mask >>= 1;
+ }
+
+ // std::cout << "Value Of mask after loop: "
+ // << std::hex << std::size_t(mask) << std::endl;
+
+ // print_mask_array(mask_array, mask_array + mask_size);
+
+ // This is a basic condition where if the mask has a size of 1 byte then
+ // it should simply be returned.
+ // this also denotes that the mask is not going to cross char boundries.
+ if(mask_size == 1) {
+ return mask_array;
+ }
+ // std::cout << "Mask greater then 1 byte" << std::endl;
+ // print_mask_array(mask_array, mask_array + mask_size);
+ // fill all but the last block with 0xff
+ storage_ptr_t end_mask_ptr = mask_ptr + mask_size - 1;
+ ++mask_ptr;
+ for(;mask_ptr < end_mask_ptr; ++mask_ptr) {
+ *mask_ptr = 0xff;
+ }
+ // std::cout << "Filled Mask with max byte values (if needed)" << std::endl;
+ // print_mask_array(mask_array, mask_array + mask_size);
+
+ // if both the offset + width is divisible by 8 then that means that
+ // the mask ends on a char boundry and the last byte needs to be set to 0
+ // and the array returned.
+ if(!((offset + Width)%8)) {
+ mask_ptr = mask_array +mask_size - 1;
+ *mask_ptr = 0xFF;
+ // std::cout << "Mask is on char boundry" << std::endl;
+ // print_mask_array(mask_array, mask_array + mask_size);
+ return mask_array;
+ }
+
+
+ // std::cout << "Mask has trailing bits to deal with" << std::endl;
+
+ // filling out the rest of the trailing bits.
+ mask = 0x80;
+
+ // calculate the number of trailing bits which need to be filled out.
+ std::size_t remaining_bits = (Width + offset) % 8;
+
+ // set the mask pointer to the last valid index inside of the array.
+ mask_ptr = mask_array + mask_size - 1;
+ for(std::size_t bit_index = 0; bit_index < remaining_bits; ++bit_index) {
+ *mask_ptr |= mask;
+ mask >>=1;
+ }
+ // print_mask_array(mask_array, mask_array + mask_size);
+ return mask_array;
+}
+
+
 template <typename RetType, std::size_t Width>
 class proxy_reference_type<RetType,Width,false> {
     typedef proxy_reference_type<RetType,Width,false> _self;
@@ -191,8 +300,6 @@
         std::cout << "trailing_zero's value: " << trailing_zeros << std::endl;
         std::cout << "bit_copy_ammount: " << bit_copy_ammount << std::endl;
         std::cout << "mask_byte_count: " << mask_byte_count << std::endl;
- // std::cout << "Pre-Mask creation Stats" << std::endl;
- // std::cout << "Pre-Mask creation Stats" << std::endl;
         for(std::size_t bit_index = _offset;bit_index <= bit_copy_ammount; ++bit_index){
             if( (bit_index%8) == 0) {
                 ++mask_byte_count;
@@ -252,6 +359,9 @@
     offset_type _offset;
 };
 
+
+
+
 }} // end boost::detail
 
 

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp 2010-08-05 13:04:25 EDT (Thu, 05 Aug 2010)
@@ -114,6 +114,97 @@
 
 #undef TEST_MACRO_COPY_ASSIGNMENT_OPERATOR
     }
+
+ // functions used for constructing the char_array mask.
+ // Testing: get_mask_array_size
+ {
+ std::size_t ret_value = 0;
+
+ ret_value = get_mask_array_size<3>(6);
+ BOOST_TEST(ret_value == 2);
+
+ ret_value = get_mask_array_size<4>(0);
+ BOOST_TEST(ret_value == 1);
+
+ ret_value = get_mask_array_size<50>(0);
+ BOOST_TEST(ret_value == 7);
+ }
+ // make_field_mask creates mask used to retrieve or set data.
+ {
+ storage_ptr_t manager_ptr;
+ storage_ptr_t ptr;
+ std::size_t size;
+
+ size = get_mask_array_size<3>(6);
+ manager_ptr = ptr = make_field_mask<3>(6, size);
+
+ BOOST_TEST(*ptr == 0x3);
+ ++ptr;
+ BOOST_TEST(*ptr == 0x80);
+ delete manager_ptr;
+
+ size = get_mask_array_size<3>(1);
+ manager_ptr = ptr = make_field_mask<3>(1, size);
+ BOOST_TEST( *ptr == 0x70 );
+ delete manager_ptr;
+
+ size = get_mask_array_size<4>(0);
+ manager_ptr = ptr = make_field_mask<4>(0, size);
+ BOOST_TEST( *ptr == 0xf0 );
+ delete manager_ptr;
+
+ size = get_mask_array_size<50>(0);
+ manager_ptr = ptr = make_field_mask<50>(0, size);
+ // 1
+ BOOST_TEST( *ptr == 0xFF );
+ // 2
+ ++ptr;
+ BOOST_TEST( *ptr == 0xFF );
+ // 3
+ ++ptr;
+ BOOST_TEST( *ptr == 0xFF );
+ // 4
+ ++ptr;
+ BOOST_TEST( *ptr == 0xFF );
+ // 5
+ ++ptr;
+ BOOST_TEST( *ptr == 0xFF );
+ // 6
+ ++ptr;
+ BOOST_TEST( *ptr == 0xFF );
+ // 7
+ ++ptr;
+ BOOST_TEST( *ptr == 0xC0 );
+
+ delete manager_ptr;
+
+ size = get_mask_array_size<50>(2);
+ manager_ptr = ptr = make_field_mask<50>(2, size);
+ // 1
+ BOOST_TEST( *ptr == 0x3F );
+ // 2
+ ++ptr;
+ BOOST_TEST( *ptr == 0xFF );
+ // 3
+ ++ptr;
+ BOOST_TEST( *ptr == 0xFF );
+ // 4
+ ++ptr;
+ BOOST_TEST( *ptr == 0xFF );
+ // 5
+ ++ptr;
+ BOOST_TEST( *ptr == 0xFF );
+ // 6
+ ++ptr;
+ BOOST_TEST( *ptr == 0xFF );
+ // 7
+ ++ptr;
+ BOOST_TEST( *ptr == 0xF0 );
+
+ delete manager_ptr;
+
+ }
+ /*
     // encoding and decoding tests.
     {
         typedef unsigned char storage_type;
@@ -148,6 +239,7 @@
 
         
     }
+*/
     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