Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64163 - in sandbox/SOC/2010/bit_masks/boost: bitfield integer/detail/bft
From: bbartmanboost_at_[hidden]
Date: 2010-07-19 15:11:50


Author: bbartman
Date: 2010-07-19 15:11:49 EDT (Mon, 19 Jul 2010)
New Revision: 64163
URL: http://svn.boost.org/trac/boost/changeset/64163

Log:
refactored into a policy for the packing and unpacking of pointer data.

Text files modified:
   sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield.hpp | 8 +-
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp | 85 ++++++++++++++++++++++++++++++++++++++-
   2 files changed, 85 insertions(+), 8 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield.hpp 2010-07-19 15:11:49 EDT (Mon, 19 Jul 2010)
@@ -443,7 +443,7 @@
         L,
         VALUE_TYPE,
         REFERENCE_TYPE,
- ::boost::detail::pointer_member::pointer_member_info<MASK,POLICY>
+ ::boost::detail::pointer_member::pointer_member_info< MASK, POLICY >
> _self;
 public:
 
@@ -452,7 +452,7 @@
     typedef REFERENCE_TYPE reference_type;
 
     typedef MASK get_mask;
- typedef integral_constant< typename MASK::value_type, ~MASK::value > set_mask;
+
     typedef POLICY field_policy;
 
     /** constructor over the storage type. */
@@ -463,11 +463,11 @@
 
     /** Set function. */
     void set( value_type x) {
- _field = (_field & set_mask::value) | (typename get_mask::value_type(x) & get_mask::value);
+ _field = field_policy::template apply<storage_type>::set(_field, x);
     }
 
     value_type get() const {
- return value_type(_field & get_mask::value);
+ return field_policy::template apply<storage_type>::get(_field);
     }
 private:
     storage_type& _field;

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-19 15:11:49 EDT (Mon, 19 Jul 2010)
@@ -16,6 +16,11 @@
 
 } // end bit_shift
 
+
+/** Only specilization exist for no shift and shift right however
+ * that doesn't mean that in the future this can't be adapted for preform
+ * left shift on the pointer.
+ */
 template <
     typename Mask,
     typename ValueType,
@@ -23,19 +28,91 @@
     typename Width,
     typename IsAligned,
     typename DirectionShifted
+>
+struct pointer_packing_policy;
+
+/** Non-shifted policy. */
+template <
+ typename Mask,
+ typename ValueType,
+ typename Offset,
+ typename Width
+>
+struct pointer_packing_policy<
+ Mask,
+ ValueType,
+ Offset,
+ Width,
+ mpl::true_,
+ bit_shift::none
>
-struct pointer_packing_policy {
+ {
+
+ /** Masks for retrieving the value and setting the value of the storage.*/
+ //@{
+ typedef Mask get_mask;
+ typedef integral_constant<
+ typename get_mask::value_type,
+ ~get_mask::value
+ > set_mask;
+ //@}
+
+ typedef Offset offset;
+ typedef Width width;
+ typedef ValueType value_type;
+
+ template <typename StorageType>
+ struct apply {
+ typedef StorageType storage_type;
+
+ 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(
+ (storage & set_mask::value)
+ |
+ (typename get_mask::value_type(ptr) & get_mask::value)
+ );
+ }
+ };
 
+};
+
+/** Specilization for when the pointer is shifted left. */
+template <
+ typename Mask,
+ typename ValueType,
+ typename Offset,
+ typename Width,
+ std::size_t ShiftAmount
+>
+struct pointer_packing_policy<
+ Mask,
+ ValueType,
+ Offset,
+ Width,
+ mpl::false_,
+ bit_shift::right<ShiftAmount>
+>
+{
+ typedef Mask mask;
     typedef Offset offset;
     typedef Width width;
     typedef ValueType value_type;
- typedef IsAligned is_aligned;
- typedef DirectionShifted shift_direction;
+
     template <typename StorageType>
     struct apply {
         typedef StorageType storage_type;
 
- // static value_type get(storage_type const& )
+ static value_type get(storage_type storage ) {
+ return value_type();
+ }
+
+ static storage_type set(storage_type storage, value_type ptr) {
+ return storage_type();
+ }
     };
 
 };


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