Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64329 - in sandbox/SOC/2010/bit_masks: boost/integer/bitfield_tuple boost/integer/detail/bft lib/integer/test/bft_testing
From: bbartmanboost_at_[hidden]
Date: 2010-07-25 11:32:44


Author: bbartman
Date: 2010-07-25 11:32:43 EDT (Sun, 25 Jul 2010)
New Revision: 64329
URL: http://svn.boost.org/trac/boost/changeset/64329

Log:
testing implementation for custom member
Added:
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/policy_creation_detail.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple/custom.hpp | 3
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp | 3
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/custom_packing_policy.hpp | 22 ++--
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp | 183 ---------------------------------------
   sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/custom_member_test.cpp | 38 +++----
   5 files changed, 34 insertions(+), 215 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple/custom.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple/custom.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple/custom.hpp 2010-07-25 11:32:43 EDT (Sun, 25 Jul 2010)
@@ -7,6 +7,7 @@
 #ifndef BOOST_CUSTOM_FIELD_HPP
 #define BOOST_CUSTOM_FIELD_HPP
 #include <cstddef>
+#include <boost/integer/detail/bft/custom_packing_policy.hpp>
 
 namespace boost { namespace bitfields {
 
@@ -24,7 +25,7 @@
         typename,
         typename,
         typename
- > class Policy
+ > class Policy = detail::custom_packing_policy
>
 struct custom;
 

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/arg_parse_impl.hpp 2010-07-25 11:32:43 EDT (Sun, 25 Jul 2010)
@@ -32,9 +32,8 @@
 #include <boost/integer/detail/bft/pointer_packing_policy.hpp>
 
 
-namespace boost { namespace detail {
-
 
+namespace boost { namespace detail {
 
 /** This is the empty which prevents the user from supply things which are
  * not enclosed within either a member template or a storage template.

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/custom_packing_policy.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/custom_packing_policy.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/custom_packing_policy.hpp 2010-07-25 11:32:43 EDT (Sun, 25 Jul 2010)
@@ -6,13 +6,9 @@
 
 #ifndef BOOST_BITFIELD_TUPLE_CUSTOM_PACKING_POLICY_HPP
 #define BOOST_BITFIELD_TUPLE_CUSTOM_PACKING_POLICY_HPP
-#include <cstddef>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/type_traits/make_unsigned.hpp>
-#include <boost/integer/detail/bft/mask_shift_indicators.hpp>
-
-namespace boost { namespace detial {
+#include <boost/integer/detail/bft/policy_creation_detail.hpp>
 
+namespace boost { namespace detail {
 
 template <
     typename Mask,
@@ -25,11 +21,15 @@
     typedef ValueType value_type;
     
     template <typename StorageType>
- struct apply {
- typedef StorageType storage_type;
- static value_type get(storage_type storage);
- static storage_type set(storage_type storage, value_type ptr);
- };
+ struct apply
+ : policy_detail::deduce_policy<
+ Mask,
+ ValueType,
+ Offset,
+ Width,
+ StorageType
+ >::type
+ { };
 };
 
 }} // end boost::detail

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp 2010-07-25 11:32:43 EDT (Sun, 25 Jul 2010)
@@ -6,188 +6,10 @@
 
 #ifndef BOOST_BITFIELD_TUPLE_POINTER_PACKING_POLICY_HPP
 #define BOOST_BITFIELD_TUPLE_POINTER_PACKING_POLICY_HPP
-#include <cstddef>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/type_traits/make_unsigned.hpp>
-#include <boost/integer/detail/bft/mask_shift_indicators.hpp>
+#include <boost/integer/detail/bft/policy_creation_detail.hpp>
 
 namespace boost { namespace detail {
 
-// detial's relating to the set and get functions.
-namespace policy_detail {
-
-template <
- typename Mask,
- typename ValueType,
- typename StorageType,
- typename Shift
->
-struct apply_impl;
-
-template <
- typename Mask,
- typename ValueType,
- typename StorageType
->
-struct apply_impl <Mask,ValueType,StorageType,bit_shift::none > {
-
- typedef ValueType value_type;
- typedef StorageType storage_type;
-
- typedef Mask get_mask;
-
- typedef integral_constant<
- storage_type,
- ~storage_type( get_mask::value )
- > set_mask;
-
-
-
- static value_type get(storage_type storage) {
- return value_type( storage & get_mask::value );
- }
-
- static storage_type set(storage_type storage, value_type ptr) {
- return storage_type(
- (set_mask::value & storage)
- |
- (get_mask::value & typename get_mask::value_type(ptr))
- );
- }
-};
-
-template <
- typename Mask,
- typename ValueType,
- typename StorageType,
- std::size_t Shift
->
-struct apply_impl <Mask,ValueType,StorageType,bit_shift::right<Shift> > {
-
- typedef ValueType value_type;
- typedef StorageType storage_type;
-
- typedef Mask get_from_ptr_mask;
- typedef typename mpl::shift_right<
- integral_constant<
- storage_type,
- Mask::value
- >,
- mpl::size_t<Shift>
- >::type get_mask;
-
- typedef integral_constant<
- storage_type,
- ~get_mask::value
- > set_mask;
-
-
- static value_type get(storage_type storage) {
- return value_type( (get_mask::value & storage) << Shift);
- }
-
- static storage_type set(storage_type storage, value_type ptr) {
- return storage_type(
- (storage & set_mask::value)
- |
- ((storage_type(ptr) & get_from_ptr_mask::value) >> Shift )
- );
- }
-};
-
-template <
- typename Mask,
- typename ValueType,
- typename StorageType,
- std::size_t Shift
->
-struct apply_impl <Mask,ValueType,StorageType,bit_shift::left<Shift> > {
-
- typedef ValueType value_type;
- typedef StorageType storage_type;
- typedef Mask get_from_ptr_mask;
- typedef typename mpl::shift_left<
- integral_constant<
- storage_type,
- Mask::value
- >,
- mpl::size_t<Shift>
- >::type get_mask;
-
-
- typedef integral_constant<
- storage_type,
- ~get_mask::value
- > set_mask;
-
- static value_type get(storage_type storage) {
- return value_type( (storage & get_mask::value) >> Shift );
- }
-
- static storage_type set(storage_type storage, value_type ptr) {
- return storage_type(
- (storage & set_mask::value)
- |
- ((storage_type(ptr) & get_from_ptr_mask::value) << Shift )
- );
- }
-};
-
-
-
-
-template<
- typename Mask,
- typename ValueType,
- typename Offset,
- typename Width,
- typename StorageType
->
-struct deduce_policy {
-
- // getting front storage.
- typedef typename pointer_member::count_leading_zeros<
- Mask>::type front_storage_space;
-
- typedef typename pointer_member::count_trailing_zeros<
- Mask>::type back_storage_space;
-
- // getting the basic information for calculating the shift on
- // a mask
- typedef typename mpl::minus<
- mpl::int_< bit_width<StorageType>::value >,
- mpl::int_<
- mpl::plus<
- Offset,
- Width,
- back_storage_space
- >::type::value
- >
- >::type mask_shift_value;
-
- typedef typename mpl::if_<
- mpl::less<
- mask_shift_value,
- mpl::int_<0>
- >,
- // less then.
- bit_shift::right<
- mpl::minus<mpl::int_<0>, mask_shift_value >::type::value
- >,
- typename mpl::if_<
- mpl::equal_to< mpl::int_<0>, mask_shift_value>,
- // equal to so no shift
- bit_shift::none,
- // greater then so go right.
- bit_shift::left< mask_shift_value::value >
- >::type
- >::type mask_shift;
-
- typedef apply_impl<Mask,ValueType,StorageType,mask_shift> type;
-};
-
-} // end policy_detail
-
 template <
     typename Mask,
     typename ValueType,
@@ -197,7 +19,6 @@
 struct pointer_packing_policy {
     typedef Mask mask;
     typedef ValueType value_type;
-
 
     template <typename StorageType>
     struct apply
@@ -211,5 +32,5 @@
     { };
 };
 
-}} // end boost::detial
+}} // end boost::detail
 #endif

Added: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/policy_creation_detail.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/policy_creation_detail.hpp 2010-07-25 11:32:43 EDT (Sun, 25 Jul 2010)
@@ -0,0 +1,192 @@
+// 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_POLICY_CREATION_DETAIL_HPP
+#define BOOST_BITFIELD_TUPLE_POLICY_CREATION_DETAIL_HPP
+#include <cstddef>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/make_unsigned.hpp>
+#include <boost/integer/detail/bft/arg_parsing_meta_functions.hpp>
+#include <boost/integer/detail/bft/mask_shift_indicators.hpp>
+
+namespace boost { namespace detail {
+
+// detial's relating to the set and get functions.
+namespace policy_detail {
+
+template <
+ typename Mask,
+ typename ValueType,
+ typename StorageType,
+ typename Shift
+>
+struct apply_impl;
+
+template <
+ typename Mask,
+ typename ValueType,
+ typename StorageType
+>
+struct apply_impl <Mask,ValueType,StorageType,bit_shift::none > {
+
+ typedef ValueType value_type;
+ typedef StorageType storage_type;
+
+ typedef Mask get_mask;
+
+ typedef integral_constant<
+ storage_type,
+ ~storage_type( get_mask::value )
+ > set_mask;
+
+
+
+ static value_type get(storage_type storage) {
+ return value_type( storage & get_mask::value );
+ }
+
+ static storage_type set(storage_type storage, value_type ptr) {
+ return storage_type(
+ (set_mask::value & storage)
+ |
+ (get_mask::value & typename get_mask::value_type(ptr))
+ );
+ }
+};
+
+template <
+ typename Mask,
+ typename ValueType,
+ typename StorageType,
+ std::size_t Shift
+>
+struct apply_impl <Mask,ValueType,StorageType,bit_shift::right<Shift> > {
+
+ typedef ValueType value_type;
+ typedef StorageType storage_type;
+
+ typedef Mask get_from_ptr_mask;
+ typedef typename mpl::shift_right<
+ integral_constant<
+ storage_type,
+ Mask::value
+ >,
+ mpl::size_t<Shift>
+ >::type get_mask;
+
+ typedef integral_constant<
+ storage_type,
+ ~get_mask::value
+ > set_mask;
+
+
+ static value_type get(storage_type storage) {
+ return value_type( (get_mask::value & storage) << Shift);
+ }
+
+ static storage_type set(storage_type storage, value_type ptr) {
+ return storage_type(
+ (storage & set_mask::value)
+ |
+ ((storage_type(ptr) & get_from_ptr_mask::value) >> Shift )
+ );
+ }
+};
+
+template <
+ typename Mask,
+ typename ValueType,
+ typename StorageType,
+ std::size_t Shift
+>
+struct apply_impl <Mask,ValueType,StorageType,bit_shift::left<Shift> > {
+
+ typedef ValueType value_type;
+ typedef StorageType storage_type;
+ typedef Mask get_from_ptr_mask;
+ typedef typename mpl::shift_left<
+ integral_constant<
+ storage_type,
+ Mask::value
+ >,
+ mpl::size_t<Shift>
+ >::type get_mask;
+
+
+ typedef integral_constant<
+ storage_type,
+ ~get_mask::value
+ > set_mask;
+
+ static value_type get(storage_type storage) {
+ return value_type( (storage & get_mask::value) >> Shift );
+ }
+
+ static storage_type set(storage_type storage, value_type ptr) {
+ return storage_type(
+ (storage & set_mask::value)
+ |
+ ((storage_type(ptr) & get_from_ptr_mask::value) << Shift )
+ );
+ }
+};
+
+
+
+
+template<
+ typename Mask,
+ typename ValueType,
+ typename Offset,
+ typename Width,
+ typename StorageType
+>
+struct deduce_policy {
+
+ // getting front storage.
+ typedef typename pointer_member::count_leading_zeros<
+ Mask>::type front_storage_space;
+
+ typedef typename pointer_member::count_trailing_zeros<
+ Mask>::type back_storage_space;
+
+ // getting the basic information for calculating the shift on
+ // a mask
+ typedef typename mpl::minus<
+ mpl::int_< bit_width<StorageType>::value >,
+ mpl::int_<
+ mpl::plus<
+ Offset,
+ Width,
+ back_storage_space
+ >::type::value
+ >
+ >::type mask_shift_value;
+
+ typedef typename mpl::if_<
+ mpl::less<
+ mask_shift_value,
+ mpl::int_<0>
+ >,
+ // less then.
+ bit_shift::right<
+ mpl::minus<mpl::int_<0>, mask_shift_value >::type::value
+ >,
+ typename mpl::if_<
+ mpl::equal_to< mpl::int_<0>, mask_shift_value>,
+ // equal to so no shift
+ bit_shift::none,
+ // greater then so go right.
+ bit_shift::left< mask_shift_value::value >
+ >::type
+ >::type mask_shift;
+
+ typedef apply_impl<Mask,ValueType,StorageType,mask_shift> type;
+};
+
+}}} // end policy_detail
+
+#endif

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/custom_member_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/custom_member_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/custom_member_test.cpp 2010-07-25 11:32:43 EDT (Sun, 25 Jul 2010)
@@ -10,25 +10,12 @@
 using namespace boost;
 using namespace boost::bitfields;
 
-template <
- typename Mask,
- typename ValueType,
- typename Offset,
- typename Width
->
-struct custom_packing_policy {
- typedef Mask mask;
- typedef ValueType value_type;
-
- template <typename StorageType>
- struct apply {
- typedef StorageType storage_type;
- static value_type get(storage_type storage);
- static storage_type set(storage_type storage, value_type ptr);
- };
-};
-
 struct cust;
+struct i1;
+struct i2;
+
+struct b1;
+struct b2;
 
 int main() {
     {
@@ -36,12 +23,23 @@
             custom<
                 unsigned int,
                 cust,
- bits_mask<unsigned int, 3, 20>,
- custom_packing_policy
+ bits_mask<unsigned int, 8,16>
>
> custom_t1;
 
         custom_t1 t1;
+ unsigned int i = 0x00ffff00;
+ t1.get<cust>() = i;
+ BOOST_TEST(t1.get<cust>() == i);
+ }
+ {
+ typedef bitfield_tuple<
+ custom<
+ unsigned int,
+ cust,
+ bits_mask<unsigned int, 8,16>
+ >
+ > custom_t1;
     }
     return 0;
 }


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