$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r63287 - in sandbox/SOC/2010/bit_masks: boost/integer boost/integer/details boost/integer/details/bft lib/integer/test lib/integer/test/bft_testing
From: bbartmanboost_at_[hidden]
Date: 2010-06-24 12:11:16
Author: bbartman
Date: 2010-06-24 12:11:15 EDT (Thu, 24 Jun 2010)
New Revision: 63287
URL: http://svn.boost.org/trac/boost/changeset/63287
Log:
completed work on the bit_align template which works
Text files modified: 
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp             |     1                                         
   sandbox/SOC/2010/bit_masks/boost/integer/details/align.hpp              |    22 ++++++++++++                            
   sandbox/SOC/2010/bit_masks/boost/integer/details/bft/arg_parse_impl.hpp |    63 +++++++++++++++++++++++++++++++++++     
   sandbox/SOC/2010/bit_masks/lib/integer/test/Jamfile.v2                  |     1                                         
   sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/align_test.cpp  |    72 ++++++++++++++++++++++++++++++++++++++++
   5 files changed, 158 insertions(+), 1 deletions(-)
Modified: sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp	(original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp	2010-06-24 12:11:15 EDT (Thu, 24 Jun 2010)
@@ -327,7 +327,6 @@
     typedef typename _base::field_vector            members;
     typedef typename _base::storage_type            storage_type;
     typedef typename _base::offset                  bits_used;
-
     
     /** Proxy type returned by get functions.
      *  This serves as the go between things within this class.
Modified: sandbox/SOC/2010/bit_masks/boost/integer/details/align.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/details/align.hpp	(original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/details/align.hpp	2010-06-24 12:11:15 EDT (Thu, 24 Jun 2010)
@@ -0,0 +1,22 @@
+//  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)
+
+
+#ifndef BOOST_BITFIELD_TUPLE_ALIGNED_HPP
+#define BOOST_BITFIELD_TUPLE_ALIGNED_HPP
+#include <cstddef>
+
+namespace boost {
+
+
+/** Allows the alignment to be set to the next bit which has the same alignment
+ *  as the as AlignTo specifies relative to the current offset in bits.
+ */
+template <std::size_t AlignTo>
+struct bit_align;
+
+} // end boost
+
+#endif
Modified: sandbox/SOC/2010/bit_masks/boost/integer/details/bft/arg_parse_impl.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/details/bft/arg_parse_impl.hpp	(original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/details/bft/arg_parse_impl.hpp	2010-06-24 12:11:15 EDT (Thu, 24 Jun 2010)
@@ -11,10 +11,15 @@
 #include <boost/mpl/push_back.hpp>
 #include <boost/mpl/plus.hpp>
 #include <boost/mpl/if.hpp>
+#include <boost/mpl/arithmetic.hpp>
 #include <boost/mpl/find_if.hpp>
+
 #include <boost/integer/details/bft/name_lookup.hpp>
 #include <boost/integer/details/bit_flag.hpp>
 #include <boost/integer/details/filler.hpp>
+#include <boost/integer/details/align.hpp>
+
+
 
 namespace boost { namespace details {
 
@@ -268,6 +273,64 @@
 
 
 
+/* Specialization for filler. */
+template <  std::size_t AlignTo,
+            typename StoragePolicy,
+            typename FieldVector,
+            typename Offset
+>
+struct bft_arg_parse_impl <
+    bit_align<
+        AlignTo
+    >,
+    StoragePolicy,
+    FieldVector,
+    Offset >
+{
+    typedef bit_align<AlignTo> param;
+    typedef FieldVector     field_vector;
+    typedef StoragePolicy   storage_policy;
+
+
+    // computing the position of the next bit which is aligned
+    // to the current value of AlignTo.
+    
+    // if the modulus result is 0 then we are aligned to the current position.
+    // If its not then we actually have to adjust the position and move to the 
+    // next bit position which is aligned to to AlignTo's value
+
+    typedef mpl::size_t<AlignTo> align_to;
+    typedef typename mpl::modulus<
+        Offset,
+        align_to
+    >::type                 mod_result;
+
+    typedef typename mpl::if_c< mod_result::value == 0, // then
+        Offset,
+        // else
+        typename mpl::plus<
+            Offset,
+            typename mpl::minus<
+                align_to,
+                mod_result
+            >::type            
+        >::type
+    >::type                             offset;
+
+    typedef bft_arg_parse_impl<param,storage_policy,field_vector,offset> type;
+
+    template <typename NextParam>
+    struct process {
+        typedef bft_arg_parse_impl<
+            NextParam,
+            storage_policy,
+            field_vector,
+            offset
+        > type;
+    };
+};
+
+
 
 }} // end boost::details
 
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-06-24 12:11:15 EDT (Thu, 24 Jun 2010)
@@ -43,5 +43,6 @@
         [ run bft_testing/filler_test.cpp ]
         [ run bft_testing/template_expansion_marco_test.cpp ]
         [ run bft_testing/variadic_sequence_testing.cpp ]
+        [ run bft_testing/align_test.cpp ]
     ;
 
Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/align_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/align_test.cpp	(original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/align_test.cpp	2010-06-24 12:11:15 EDT (Thu, 24 Jun 2010)
@@ -0,0 +1,72 @@
+//  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_tuple.hpp>
+#include <boost/assert.hpp>
+
+
+using namespace boost;
+
+struct red;
+struct green;
+struct pink;
+struct blue;
+struct salmon;
+
+
+
+
+int main() {
+
+    // test case where alignment set the next bit to 32.
+    {
+        typedef bitfield_tuple<
+            member<char,red,4>,
+            member<unsigned char, green,5>,
+            storage<std::size_t>,
+            filler<3>,
+            member<int, salmon, 16>,
+            flag<blue>,
+            bit_align<32>
+        >                                       test_tuple_1;
+        test_tuple_1 temp;
+        BOOST_ASSERT(( test_tuple_1::bits_used::value == 32 ));
+    }
+
+    // test case where alignment is 32 and bit align attempts to set it to 32
+    {
+        typedef bitfield_tuple<
+            storage<std::size_t>,
+            bit_align<32>
+        >                                       test_tuple_2;
+        test_tuple_2 temp;
+        BOOST_ASSERT(( test_tuple_2::bits_used::value == 0 ));
+    }
+
+    // test case where user has a field that extends past the first 8 bits
+    // and they would like to align to the next 8 bit boundry.
+    {
+        typedef bitfield_tuple<
+            storage<std::size_t>,
+            member<int,red,9>,
+            bit_align<8>
+        >                                       test_tuple_3;
+        test_tuple_3 temp;
+        BOOST_ASSERT(( test_tuple_3::bits_used::value == 16));
+    }
+
+    // test case calling align 2x times in a row doesn't do anything.
+    {
+        typedef bitfield_tuple<
+            bit_align<32>,
+            bit_align<32>,
+            storage<unsigned int>
+        >                                       test_tuple_4;
+        test_tuple_4 temp;
+        BOOST_ASSERT(( test_tuple_4::bits_used::value == 0 ));
+    }
+    return 0;
+}