$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r64766 - in sandbox/SOC/2010/bit_masks: boost/integer/detail/bitfield_vector lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-08-12 14:01:39
Author: bbartman
Date: 2010-08-12 14:01:31 EDT (Thu, 12 Aug 2010)
New Revision: 64766
URL: http://svn.boost.org/trac/boost/changeset/64766
Log:
completed work for assignment with the siged specialization for proxy_reference_type
Text files modified: 
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/bitfield_vector_member_impl.hpp |    74 ++++++++++++++++++++++++++++++++++++--- 
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/proxy_reference_test.cpp    |    45 ++++++++----------------                
   2 files changed, 83 insertions(+), 36 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-12 14:01:31 EDT (Thu, 12 Aug 2010)
@@ -210,15 +210,78 @@
 
     /** value_type storage assignement operator.*/
     _self& operator=(value_type x) {
+        std::cout << "called assignment operator" << std::endl;
+        //std::cout << "x initial value: " << to_binary_2(x) <<std::endl;
+        unsigned_value_type x_adjusted = ((unsigned_value_type(x & sign_bit) >>
+                (bit_width<value_type>::value - width))
+            |
+        (low_bits_mask<value_type, std::size_t(width-1)>::value & x) );
+        //std::cout << "x new value: " << to_binary_2(x_new) <<std::endl;
 
-    }
+        if(_mask._size == 1) {
+            storage_t previous_values = *_ptr & ~_mask._first_byte;
+            storage_t new_value = low_bits_mask<value_type, width>::value &
+                x_adjusted;
+            new_value <<= _mask._last_shift;
+            previous_values |= new_value;
+            *_ptr = previous_values;
+            return *this;
+        }
+        
+        storage_t       to_be_stored = 0;
+        std::size_t     bits_in_mask = 0;
+        value_type      mask         = 0;
+        storage_ptr_t   byte_ptr     = _ptr;
+
+        if(_mask._size == 2) {
+            bits_in_mask = 8 - _mask._offset;
+            mask = (~(~value_type(0) << bits_in_mask))
+                << (width - bits_in_mask);
+            to_be_stored = storage_t((mask & 
+                x_adjusted)>>(width - bits_in_mask));
+            *byte_ptr = ((*byte_ptr) & (~_mask._first_byte)) | to_be_stored;
+            
+            ++byte_ptr;
+            bits_in_mask = width - bits_in_mask;
+            mask = ~(~value_type(0) << bits_in_mask);
+            to_be_stored = storage_t((mask & x_adjusted) << _mask._last_shift);
+            *byte_ptr = (*byte_ptr & ~_mask._last_byte) | to_be_stored;
+            return *this;
+        }
+        // calculate the offset of the first bit within x
+        // and creating a mask to extract the fist bits from within x
+        bits_in_mask = 8 - _mask._offset;
+        mask = _mask._first_byte;
+        mask <<= width - bits_in_mask;
 
+        *byte_ptr = (*byte_ptr & ~_mask._first_byte) | ((x_adjusted & mask )
+            >> (width - bits_in_mask));
+        ++byte_ptr;
+        mask = 0xFF;
+        mask <<= width - bits_in_mask - 8;
+        for(std::size_t index = 0; index < _mask._size - 2;++index) {
+            *byte_ptr = (mask & x_adjusted) >> (width - (bits_in_mask +
+                (8 * index))- 8);
+            mask >>= 8;
+            ++byte_ptr;
+        }
+        // now calculating the last bytes information, retrieving it and then
+        // storing the data within the array.
+        if(_mask._last_byte == 0xFF) {
+            *byte_ptr = _mask._last_byte & x_adjusted;
+        }else{
+            mask = _mask._last_byte >> _mask._last_shift;
+            *byte_ptr = (*byte_ptr & ~_mask._last_byte) |
+                    ((mask & x_adjusted) << (_mask._last_shift));
+        }
+        return *this;
+    }
+/*
     bool operator==(_self const& rhs);
     bool operator!=(_self const& rhs);
     bool operator<(_self const& rhs);
+*/
 
-
-    // private:
     /** Member variables. */
     storage_type*    _ptr;
     mask_detail     _mask;
@@ -371,13 +434,12 @@
         }
         return *this;
     }
-
+/*
     bool operator==(_self const& rhs);
     bool operator!=(_self const& rhs);
     bool operator<(_self const& rhs);
+*/
 
-
-// private:
     /** Member variables. */
     storage_type*   _ptr;
     mask_detail     _mask;
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-12 14:01:31 EDT (Thu, 12 Aug 2010)
@@ -555,7 +555,7 @@
     // begining testing of the proxy reference type specialization for
     // signed numbers.
     {
-        display_debug = true;
+        display_debug = false;
         if(display_debug) {
             std::cout << "=========================================" << std::endl;
             std::cout << " Signed type tests" << std::endl;
@@ -671,36 +671,21 @@
 
         ptr = storage;
         *ptr = 0x01 << 3;
-        BOOST_TEST(t4 == -562949953411312);
-        
-
-        // long long t = t4;
-        // std::cout << "hex value of ptr: " << std::hex << std::size_t(*ptr) << std::endl;
-        // std::cout << "t4: " << to_binary(t) << std::endl;
-        // std::cout << "Test type 7: " << std::dec << t << std::endl;
-        // std::cout << "binary of storage_sign_bit:  " << to_binary(test_type_7::stored_sign_bit) << std::endl;
-        
-        // 0000   00  0000 0000  0000 0000  0000 0000  0000 0000  0000 0000  0000 0000
-        //                                                    00  10 0111 1 0  0000 00
-    //  std::memset(ptr,0,10);
-        
-/*
-typedef proxy_reference_type<int, 3>                    test_type_6;
-typedef proxy_reference_type<char, 7>                   test_type_7;
-typedef proxy_reference_type<long, 7>                   test_type_8;
-typedef proxy_reference_type<long long, 17>             test_type_9;
-typedef proxy_reference_type<long long, 50>             test_type_10;
-typedef proxy_reference_type<short, 13>                 test_type_11;
-
-test_type_6;
-test_type_7;
-test_type_8;
-test_type_9;
-test_type_10;
-test_type_11
-*/
-        // BOOST_TEST(false);
+        BOOST_TEST(t4 == -562949953411312);        
+    }
 
+    // testing storage of signed types with proxy_reference_type
+    {
+        display_debug = true;
+        typedef unsigned char storage_type;
+        typedef storage_type* storage_ptr;        
+        storage_type storage[20];
+        storage_ptr ptr = storage;
+        std::memset(ptr,0,20);
+        test_type_6 t1(ptr,0);
+        t1 = -2;
+        BOOST_TEST(t1 == -2);
+    
     }
     return boost::report_errors();
 }