Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64620 - 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:53:21


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

Log:
refactored some of my mask creation implementation
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp | 63 +++++++++++++++++++--------------------
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp | 35 ++++++++++-----------
   2 files changed, 48 insertions(+), 50 deletions(-)

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:53:16 EDT (Thu, 05 Aug 2010)
@@ -132,6 +132,15 @@
 };
 
 
+/** Used for returning information about the mask used to apply the mask to
+ * another char array.
+ */
+struct mask_array_info {
+ std::size_t mask_size;
+ storage_ptr_t mask;
+ std::size_t last_left_shift;
+};
+
 
 /** Calculates the size of an array needed to store a particular mask inside of
  * of char array.
@@ -156,28 +165,31 @@
     }
     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;
+inline mask_array_info
+make_field_mask(std::size_t offset) {
+
     // 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;
+ std::size_t mask_size = get_mask_array_size<Width>(offset);
+ mask_array_info ret;
+ ret.mask_size = mask_size;
+ ret.mask = new storage_t[mask_size];
+ ret.last_left_shift = 0;
+
+ storage_ptr_t mask_ptr = ret.mask;
 
     // 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;
@@ -187,56 +199,43 @@
         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;
+ return ret;
     }
- // 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 = ret.mask + 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;
+ ret.last_left_shift = 8;
+ return ret;
     }
 
-
- // 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;
-
+ ret.last_left_shift = remaining_bits;
     // set the mask pointer to the last valid index inside of the array.
- mask_ptr = mask_array + mask_size - 1;
+ mask_ptr = ret.mask + mask_size - 1;
     for(std::size_t bit_index = 0; bit_index < remaining_bits; ++bit_index) {
         *mask_ptr |= mask;
- mask >>=1;
+ mask >>= 1;
     }
- // print_mask_array(mask_array, mask_array + mask_size);
- return mask_array;
+ return ret;
 }
 
 

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:53:16 EDT (Thu, 05 Aug 2010)
@@ -131,30 +131,28 @@
     }
     // make_field_mask creates mask used to retrieve or set data.
     {
- storage_ptr_t manager_ptr;
+ mask_array_info 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);
 
+ manager_ptr = make_field_mask<3>(6);
+ ptr = manager_ptr.mask;
         BOOST_TEST(*ptr == 0x3);
         ++ptr;
         BOOST_TEST(*ptr == 0x80);
- delete manager_ptr;
+ delete manager_ptr.mask;
 
- size = get_mask_array_size<3>(1);
- manager_ptr = ptr = make_field_mask<3>(1, size);
+ manager_ptr = make_field_mask<3>(1);
+ ptr = manager_ptr.mask;
         BOOST_TEST( *ptr == 0x70 );
- delete manager_ptr;
+ delete manager_ptr.mask;
 
- size = get_mask_array_size<4>(0);
- manager_ptr = ptr = make_field_mask<4>(0, size);
+ manager_ptr = make_field_mask<4>(0);
+ ptr = (manager_ptr.mask);
         BOOST_TEST( *ptr == 0xf0 );
- delete manager_ptr;
+ delete manager_ptr.mask;
 
- size = get_mask_array_size<50>(0);
- manager_ptr = ptr = make_field_mask<50>(0, size);
+ manager_ptr = make_field_mask<50>(0);
+ ptr = (manager_ptr.mask);
         // 1
         BOOST_TEST( *ptr == 0xFF );
         // 2
@@ -176,10 +174,11 @@
         ++ptr;
         BOOST_TEST( *ptr == 0xC0 );
 
- delete manager_ptr;
+ delete manager_ptr.mask;
+
 
- size = get_mask_array_size<50>(2);
- manager_ptr = ptr = make_field_mask<50>(2, size);
+ manager_ptr = make_field_mask<50>(2);
+ ptr = (manager_ptr.mask);
         // 1
         BOOST_TEST( *ptr == 0x3F );
         // 2
@@ -201,7 +200,7 @@
         ++ptr;
         BOOST_TEST( *ptr == 0xF0 );
 
- delete manager_ptr;
+ delete manager_ptr.mask;
 
     }
     /*


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