Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64663 - in sandbox/SOC/2010/bit_masks: boost/integer/detail/bitfield_vector lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-08-07 12:34:26


Author: bbartman
Date: 2010-08-07 12:34:24 EDT (Sat, 07 Aug 2010)
New Revision: 64663
URL: http://svn.boost.org/trac/boost/changeset/64663

Log:
working on creating tools for creating masks at compile time for the bitfield_vector
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/mask_creator.hpp | 86 +++++++++++++++++++++++++++++++++++++++
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/mask_creator_test.cpp | 32 +++++++++++++
   2 files changed, 114 insertions(+), 4 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/mask_creator.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/mask_creator.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bitfield_vector/mask_creator.hpp 2010-08-07 12:34:24 EDT (Sat, 07 Aug 2010)
@@ -5,7 +5,7 @@
 
 #ifndef BOOST_BITFIELD_VECTOR_MASK_CREATOR_HPP
 #define BOOST_BITFIELD_VECTOR_MASK_CREATOR_HPP
-
+#include "bitfield_vector_base.hpp"
 #include <boost/mpl/size_t.hpp>
 #include <boost/mpl/arithmetic.hpp>
 #include <boost/mpl/if.hpp>
@@ -15,6 +15,10 @@
 #include <boost/mpl/size_t.hpp>
 #include <boost/mpl/greater.hpp>
 #include <boost/mpl/insert.hpp>
+#include <boost/mpl/has_key.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/integral_c.hpp>
+#include <boost/integer/high_bits_mask.hpp>
 #include <cstddef>
 
 namespace boost { namespace detail {
@@ -57,10 +61,69 @@
>::type type;
 };
 
+
+
+template <
+ std::size_t Offset,
+ std::size_t Width,
+ std::size_t Index = Offset,
+ storage_t Mask = 0,
+ bool = true
+>
+struct calc_first_byte_helper {
+ typedef mpl::integral_c<storage_t,Mask> type;
+};
+
+template <
+ std::size_t Offset,
+ std::size_t Width,
+ std::size_t Index,
+ storage_t Mask
+>
+struct calc_first_byte_helper< Offset, Width, Index, Mask, true >
+ :calc_first_byte_helper<
+ Offset,
+ Width,
+ Index + 1,
+ storage_t(Mask | (0x80 >> Index)),
+ bool((Index + 1) < (Offset + Width))
+ &&
+ bool((Index + 1) < 8)
+ >
+
+{ };
+
+template <std::size_t Offset, std::size_t Width>
+struct calc_first_byte {
+ typedef typename calc_first_byte_helper<Offset,Width>::type type;
+};
+
+
+template<std::size_t Offset, std::size_t Width>
+struct calc_last_byte {
+ typedef typename mpl::if_c<
+ bool(mask_size<mpl::size_t<Offset>,mpl::size_t<Width> >::type::value == 1 ),
+ mpl::size_t<0>,
+ typename mpl::if_c<
+ (((Offset + Width)%8) == 0),
+ mpl::integral_c<storage_t,0xFF>,
+ mpl::integral_c<storage_t,( 0xFF << (8-((Offset+Width)%8)))>
+ >::type
+ >::type type;
+};
+
+template<std::size_t Offset, std::size_t Width>
+struct calc_last_left_shift {
+
+};
+
 /** This is responsible for storing information about a perticular
  * mask but not the mask it self.
  */
-template <std::size_t Offset, std::size_t Width>
+template <
+ std::size_t Offset,
+ std::size_t Width
+>
 struct mask_info {
     BOOST_STATIC_CONSTANT(std::size_t, offset = Offset);
     BOOST_STATIC_CONSTANT(std::size_t, width = Width );
@@ -70,6 +133,10 @@
             mpl::size_t<Width>
>::type::value)
     );
+ BOOST_STATIC_CONSTANT(storage_t,
+ first_value = (calc_first_byte<offset,width>::type::value));
+ // BOOST_STATIC_CONSTANT( std::size_t,);
+ // BOOST_STATIC_CONSTANT( storage_t, (last_value = LastIndexValue);
 };
 
 
@@ -110,5 +177,20 @@
 };
 
 
+
+/** This will create some structure which will allow for quick retrieval of a
+ * all masks for a perticular width.
+ */
+template <std::size_t Width>
+struct create_masks {
+ typedef typename determine_vaild_offsets<Width>::type indices;
+/*
+ typedef typename mpl::if_<
+ has_key<indices,mpl::size_t<0> >::type,
+*/
+
+};
+
+
 }} // end booss::detail
 #endif

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/mask_creator_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/mask_creator_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/mask_creator_test.cpp 2010-08-07 12:34:24 EDT (Sat, 07 Aug 2010)
@@ -8,7 +8,14 @@
 #include <boost/detail/lightweight_test.hpp>
 #include <boost/mpl/for_each.hpp>
 #include <iostream>
-#include <boost/mpl/has_key.hpp>
+#include <iomanip>
+
+#define BOOST_PRINT_ON_TEST_FAILURE(P1, P2) \
+ if(P1 != P2 ) { \
+ std::cout << #P1 << ": " << std::hex << std::size_t(P1) << std::endl; \
+ std::cout << #P2 << ": " << std::hex << std::size_t(P2) << std::endl; \
+ }\
+ BOOST_TEST( P1 == P2);
 
 struct print_set {
     template<typename T>
@@ -40,7 +47,7 @@
         BOOST_TEST( test_3::value == 7 );
     }
 
- // testing mask info type.
+ // Testing for generation of all valid offsets for a perticular width
     {
         using namespace boost;
         typedef determine_vaild_offsets<3>::type t1;
@@ -85,5 +92,26 @@
         BOOST_TEST(( mpl::has_key<t4,mpl::size_t<7> >::type::value ));
 
     }
+
+ // testing calc_first_byte
+ {
+ BOOST_PRINT_ON_TEST_FAILURE((calc_first_byte<7,3>::type::value), 0x1 );
+ BOOST_PRINT_ON_TEST_FAILURE((calc_first_byte<2,3>::type::value), 0x38);
+ BOOST_PRINT_ON_TEST_FAILURE((calc_first_byte<6,3>::type::value), 0x3 );
+ BOOST_PRINT_ON_TEST_FAILURE((calc_first_byte<0,3>::type::value), 0xE0);
+ BOOST_PRINT_ON_TEST_FAILURE((calc_first_byte<6,50>::type::value), 0x3 );
+ BOOST_PRINT_ON_TEST_FAILURE((calc_first_byte<0,50>::type::value), 0xFF);
+ }
+
+ // testing calc_last_byte
+ {
+
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_byte<7,3>::type::value), 0xC0 );
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_byte<2,3>::type::value), 0x0);
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_byte<6,3>::type::value), 0x80);
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_byte<0,3>::type::value), 0x0);
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_byte<6,50>::type::value), 0xFF );
+ BOOST_PRINT_ON_TEST_FAILURE((calc_last_byte<0,50>::type::value), 0xC0);
+ }
     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