Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64231 - in sandbox/SOC/2010/bit_masks/boost: bitfield integer integer/detail/bft
From: bbartmanboost_at_[hidden]
Date: 2010-07-21 15:33:26


Author: bbartman
Date: 2010-07-21 15:33:23 EDT (Wed, 21 Jul 2010)
New Revision: 64231
URL: http://svn.boost.org/trac/boost/changeset/64231

Log:
working on implementing and modifing code so that I can have a simplifid version of the proxy reference policy classes
Added:
   sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield_orignal.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield.hpp | 57 ---------------------------------------
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_tuple.hpp | 27 ++----------------
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_packing_policy.hpp | 7 ----
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/proxy_reference_policy.hpp | 13 ++++++++
   4 files changed, 18 insertions(+), 86 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-21 15:33:23 EDT (Wed, 21 Jul 2010)
@@ -12,7 +12,7 @@
 
 #ifndef BOOST_INTEGER_BITFIELD__HPP
 #define BOOST_INTEGER_BITFIELD__HPP
-#include <boost/integer/detail/bft/pointer_parsing_meta_functions.hpp>
+
 #include <cstddef>
 #include <boost/static_assert.hpp>
 #include <boost/mpl/void.hpp>
@@ -418,61 +418,6 @@
             ((1 << bitfield<STORAGE_TYPE,F,L,VALUE_TYPE,REFERENCE_TYPE>::WIDTH) - 1)
 
     );
-
-
-template <
- typename STORAGE_TYPE,
- std::size_t F,
- std::size_t L,
- typename VALUE_TYPE,
- typename REFERENCE_TYPE,
- typename MASK,
- typename POLICY
->
-class bitfield <
- STORAGE_TYPE,
- F,
- L,
- VALUE_TYPE,
- REFERENCE_TYPE,
- ::boost::detail::pointer_member::pointer_member_info<MASK,POLICY> >
-{
- typedef bitfield <
- STORAGE_TYPE,
- F,
- L,
- VALUE_TYPE,
- REFERENCE_TYPE,
- ::boost::detail::pointer_member::pointer_member_info< MASK, POLICY >
- > _self;
-public:
-
- typedef STORAGE_TYPE storage_type;
- typedef VALUE_TYPE value_type;
- typedef REFERENCE_TYPE reference_type;
-
- typedef MASK get_mask;
-
- typedef POLICY field_policy;
-
- /** constructor over the storage type. */
- explicit bitfield(storage_type& field) :_field(field) { }
-
- /** Copy Constructor. TODO: figure out if i need this or not. */
- bitfield(_self const& x) :_field( x._field ) { }
-
- /** Set function. */
- void set( value_type x) {
- _field = field_policy::template apply<storage_type>::set(_field, x);
- }
-
- value_type get() const {
- return field_policy::template apply<storage_type>::get(_field);
- }
-private:
- storage_type& _field;
-};
-
 }}
 #endif
 

Added: sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield_orignal.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bit_masks/boost/bitfield/bitfield_orignal.hpp 2010-07-21 15:33:23 EDT (Wed, 21 Jul 2010)
@@ -0,0 +1,220 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Emile Cormier 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008-2009.
+// 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)
+//
+// See http://www.boost.org/libs/integer for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTEGER_BITFIELD_POLICY_HPP
+#define BOOST_INTEGER_BITFIELD_POLICY_HPP
+
+#include <cstddef>
+#include <boost/static_assert.hpp>
+
+#include <cassert>
+#include <limits>
+// #include <netinet/in.h>
+
+namespace boost { namespace integer {
+
+
+ //-----------------------------------------------------------------------------
+ template <class, std::size_t, std::size_t, class, class> class bitfield_policy;
+
+ #if 0
+ template <class R, class V>
+ class bitfield_bit_proxy {
+ public:
+ bitfield_bit_proxy& operator=(bool state) {
+ field_ &= ~mask_;
+ if (state) field_ |= mask_;
+ return *this;
+ }
+
+ operator bool() const {
+ return (field_ & mask_) != 0;
+ }
+
+ bool operator~() const {return !(static_cast<bool>(*this));}
+
+ private:
+ R field_;
+ V mask_;
+
+ bitfield_bit_proxy(R f, V mask) : field_(f), mask_(mask) {
+ std::cout << "field_=" << std::hex << field_ << std::endl;
+ std::cout << "mask_=" << mask_ << std::endl;
+ }
+
+ template <class, std::size_t, std::size_t, class, class> friend class bitfield;
+ };
+
+ template <typename T> struct reference_traits;
+
+ template <typename T> struct reference_traits<const T&> {
+ typedef T value_type;
+ };
+ template <typename T> struct reference_traits<T&> {
+ typedef T value_type;
+ };
+
+ template <typename C> struct reference_traits {
+ typedef typename C::value_type value_type;
+ };
+ #endif
+
+ namespace detail { namespace policy {
+ template <bool is_signed, typename value_type
+ , typename storage_type, unsigned int WIDTH, unsigned int SIGN_MASK>
+ struct bitfield_complete_signed;
+
+ template <typename value_type, typename storage_type, unsigned int WIDTH, unsigned int SIGN_MASK>
+ struct bitfield_complete_signed<true, value_type, storage_type, WIDTH, SIGN_MASK> {
+ static value_type convert(storage_type val) {
+ if( (val>>(WIDTH-1))!=0) {
+ return (val | SIGN_MASK);
+ } else {
+ return val;
+ }
+ }
+ };
+
+ template <typename value_type, typename storage_type, unsigned int WIDTH, unsigned int SIGN_MASK>
+ struct bitfield_complete_signed<false, value_type, storage_type, WIDTH, SIGN_MASK> {
+ static value_type convert(storage_type val) {
+ return val;
+ }
+ };
+ }}
+
+ //------------------------------------------------------------------------------
+ /*!
+ Used to easily manipulate groups of bits the same way as does C bitfields,
+ but in a portable manner.
+ \par Example declaration:
+ \code
+ struct Rgb565
+ {
+ typedef volatile uint16_t storage_type;
+ storage_type storage;
+ typedef volatile uint16_t value_type;
+ BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, red, 0, 4);
+ BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, green, 5, 10);
+ BOOST_BITFIELD_DCL(storage_type, storage, unsigned char, blue, 11,15);
+ };
+ \endcode
+ \par Example usage:
+ \code
+ Rgb565 r;
+ r.storage= 0xffff;
+
+ // Write to a bitfield. Note that parenthesis are needed around the bitfield so
+ r.red() = 23;
+
+ // Read from a bitfield
+ Rgb565::value_type b = r.blue();
+
+ // Access a bit within a bit field
+ bool bit = r.blue()[3];
+ \endcode
+ \note Bitfields within the same word may overlap.
+ \param STORAGE_TYPE Unsigned integer type of the word occupied by the bitfield
+ \param F Position of the first bit (0 is the least significant bit)
+ \param L Position of the last bit (0 is the least significant bit)
+ \param VALUE_TYPE Value type of the bitfield itself
+ \param REFERENCE_TYPE Reference type of the word occupied by the bitfield
+ */
+
+
+ /* concept ReferenceType {
+ * typedef value_type;
+ * operator value_type();
+ * ReferenceType operator=(ReferenceType rhs);
+ * ReferenceType(ReferenceType rhs);
+ * };
+ * */
+
+ template <typename STORAGE_TYPE, std::size_t F, std::size_t L,
+ typename VALUE_TYPE = typename bitfield_value_type<STORAGE_TYPE>::type,
+ typename REFERENCE_TYPE = VALUE_TYPE&>
+ class bitfield_policy {
+ typedef bitfield_policy<STORAGE_TYPE, F, L, VALUE_TYPE, REFERENCE_TYPE> this_type;
+ public:
+ //! storage type of the bitfield support
+ typedef STORAGE_TYPE storage_type;
+ //! Value type of the bitfield itself
+ typedef VALUE_TYPE value_type;
+ //! Reference type of the bitfield itself
+ typedef REFERENCE_TYPE reference_type;
+
+ private:
+
+ // the storage type must be unsigned
+ // BOOST_STATIC_ASSERT( std::numeric_limits<storage_type>::is_signed==false );
+ // first and last index must be on the range corresponding to the storage_type
+ // BOOST_STATIC_ASSERT( F < 8*sizeof(storage_type) );
+ // BOOST_STATIC_ASSERT( L < 8*sizeof(storage_type) );
+ // BOOST_STATIC_ASSERT( F <= L );
+ // The bitfield width can be stored on the value_type
+ // BOOST_STATIC_ASSERT( (L - F + 1) <= 8*sizeof(value_type) );
+
+ static storage_type value_to_storage(value_type val) {
+ storage_type res =val;
+ return ((res & VAL_MASK) << LASTD);
+ }
+
+ static value_type storage_to_value(storage_type field) {
+ storage_type val = (field & FIELD_MASK) >> LASTD;
+ return detail::policy::bitfield_complete_signed<
+ std::numeric_limits<value_type>::is_signed,
+ value_type,
+ storage_type,
+ WIDTH,
+ SIGN_MASK
+ >::convert(val);
+ }
+
+ //! private because a reference is nedeed
+ bitfield_policy();
+
+ public:
+
+
+ //! Useful constants
+ static const std::size_t FIRST = F; //!< Position of the first bit
+ static const std::size_t LAST = L; //!< Position of the last bit
+ static const std::size_t STS = 8 * sizeof(storage_type);
+ static const std::size_t LASTD = STS-LAST-1;
+ static const std::size_t WIDTH = LAST - FIRST + 1; //!< Width in bits of the bitfield
+ static const storage_type VAL_MASK = (1 << WIDTH) - 1; //!< Mask applied against assigned values
+ static const storage_type FIELD_MASK = (VAL_MASK << LASTD); //!< Mask of the field's bit positions
+ static const storage_type SIGN_MASK = ~VAL_MASK; //!< Sign mask applied against assigned values
+
+
+ //! explicit constructor from a reference
+ explicit bitfield_policy(storage_type& field)
+ :field_(field)
+ { }
+
+ //! setter from a value type
+ void set(value_type val) {
+ field_ = (field_ & ~FIELD_MASK) | value_to_storage(val);
+ }
+
+
+ //! Returns the bitfield value.
+ value_type get() const {
+ return storage_to_value(field_);
+ }
+
+ private:
+ storage_type& field_;
+ };
+}}
+#endif
+

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-07-21 15:33:23 EDT (Wed, 21 Jul 2010)
@@ -69,8 +69,9 @@
             const storage_type,
             storage_type
>::type storage_t;
-
- // typedef typename Bitfield
+
+ // gets the policy used for storing and retrieveing data for this
+ // particular field.
         typedef typename detail::select_packing_policy<
             storage_t,
             typename BitfieldElement::offset,
@@ -78,27 +79,7 @@
             return_type,
             typename BitfieldElement::policy
>::type field_type;
-/* integer::bitfield<
- storage_t,
- BitfieldElement::offset::value,
- BitfieldElement::offset::value
- +
- BitfieldElement::field_width::value - 1,
- return_type,
- typename add_reference<return_type>::type,
- typename mpl::if_<
- is_same<
- typename BitfieldElement::mask,
- mpl::void_
- >,
- mpl::void_,
- detail::pointer_member::pointer_member_info<
- typename BitfieldElement::mask,
- typename BitfieldElement::policy
- >
- >::type
- > field_type;
-*/
+
 
         /** Reference constructor. */
         explicit bitfield_reference(storage_t& 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-21 15:33:23 EDT (Wed, 21 Jul 2010)
@@ -211,12 +211,7 @@
             ValueType,
             StorageType,
             sizeof(StorageType) == sizeof(typename mask::value_type)
- > {
-#if 0
-
-
-#endif
- };
+ > { };
 };
 
 

Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/proxy_reference_policy.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/proxy_reference_policy.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/proxy_reference_policy.hpp 2010-07-21 15:33:23 EDT (Wed, 21 Jul 2010)
@@ -7,6 +7,7 @@
 #ifndef BOOST_BITFIELD_TUPLE_PROXY_REFERENCE_POLICY_HPP
 #define BOOST_BITFIELD_TUPLE_PROXY_REFERENCE_POLICY_HPP
 #include <boost/type_traits/is_same.hpp>
+#include <boost/bitfield/bitfield_orignal.hpp>
 #include <boost/type_traits/is_pod.hpp>
 #include <boost/mpl/void.hpp>
 #include <boost/mpl/logical.hpp>
@@ -14,6 +15,11 @@
 
 namespace boost { namespace detail {
 
+/** Wraps up a policy so that it has a similar interface to that of bitfield.
+ * which basically means that since the policy itself only has static functions
+ * this is the thing of which copies are made and is also responsible for the
+ * keeping of a reference to the original data.
+ */
 template <
     typename StorageType,
     typename Policy
@@ -60,7 +66,11 @@
>,
         typename mpl::if_<
             is_pod<StorageType>,
- ::boost::integer::bitfield<
+ // this needs to be something else other then bitfield
+ // I believe that this should be the orignal version
+ // of bitfield because that will optimize better then
+ // the newer version.
+ ::boost::integer::bitfield_policy<
                     StorageType,
                     Offset::value,
                     Offset::value
@@ -68,6 +78,7 @@
                     Width::value - 1,
                     ValueType
>,
+
                 ::boost::integer::bitfield<
                     StorageType,
                     Offset::value,


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