|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r61952 - in sandbox/SOC/2010/bit_masks/boost/integer: . details
From: bbartmanboost_at_[hidden]
Date: 2010-05-13 12:08:55
Author: bbartman
Date: 2010-05-13 12:08:54 EDT (Thu, 13 May 2010)
New Revision: 61952
URL: http://svn.boost.org/trac/boost/changeset/61952
Log:
working on associating preconditions with bit mask stuff
Text files modified:
sandbox/SOC/2010/bit_masks/boost/integer/bit_mask.hpp | 17 ++++++++--
sandbox/SOC/2010/bit_masks/boost/integer/details/bit_mask_impl.hpp | 61 ++++++---------------------------------
2 files changed, 23 insertions(+), 55 deletions(-)
Modified: sandbox/SOC/2010/bit_masks/boost/integer/bit_mask.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bit_mask.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bit_mask.hpp 2010-05-13 12:08:54 EDT (Thu, 13 May 2010)
@@ -12,7 +12,7 @@
// boost dependencies.
-
+#include <boost/integer/high_low_bits.hpp>
#include <boost/integer/details/bit_mask_impl.hpp>
namespace boost {
@@ -21,13 +21,22 @@
/** bit_mask.
* Mask which creates a mask give type, offset and width of the mask
*/
-template <typename T, typename Offset, typename Width>
+template <typename T, unsigned int Offset, unsigned int Width = 1 >
struct bit_mask
-{ };
+ :details::bit_mask_preconditions<T, Offset, Width>,
+ integral_constant<T, (low_bits<T,Width>::value << Offset) >
+{
+ typedef bit_mask<T, Offset, Width> type;
+};
+/** Integral Mask.
+ * This integral Mask is defined similar to an integral constant.
+ */
template <typename T, T Value>
struct integral_mask
-{ };
+{
+
+};
} // namespace boost
Modified: sandbox/SOC/2010/bit_masks/boost/integer/details/bit_mask_impl.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/details/bit_mask_impl.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/details/bit_mask_impl.hpp 2010-05-13 12:08:54 EDT (Thu, 13 May 2010)
@@ -7,35 +7,16 @@
#ifndef BOOST_BIT_MASK_IMPL_HPP
#define BOOST_BIT_MASK_IMPL_HPP
-#include <boost/mpl/integral_c.hpp>
#include <boost/type_traits.hpp>
#include <boost/mpl/bitwise.hpp>
#include <boost/static_assert.hpp>
+#include <boost/integer/bit_width.hpp>
namespace boost { namespace details {
-/** Type which is used during specialization to infer that a template patameter
- * has not been used in the initilization of bit_mask_impl.
- */
-struct unused_type { };
-
-/** Forward Declaration for the bit_mask_impl.
- * This is being used for specifying default parameters so they can be used in
- * specializations to see how may parameters bit_mask_impl was called with.
- * If I had variadic templates this would be less of an issue.
- */
-template < typename MaskedType,
- typename MaskOffsetInBits = unused_type ,
- typename MaskWidth = unused_type >
-struct bit_mask_impl;
-
-
-
-/** Houses the structure for creating simple masks as well as
- * implements the preconditions for a simple_bit_mask.
- *
+/** Preconditions for bit_mask impl
* Pre-Conditions
*
* 1. The width of the masked section must not be longer then the
@@ -47,45 +28,23 @@
*
* 4. The type which is being masked must satisfy the is_integral type trait.
*/
-template < typename MaskedType,
- typename MaskOffsetInBits,
- typename MaskWidth >
-struct bit_mask_impl {
-
+template <typename T, unsigned int Offset, unsigned int Width>
+struct bit_mask_preconditions {
// precondition 1.
- BOOST_STATIC_ASSERT(( (MaskOffsetInBits::value + MaskWidth::value)
- < (sizeof(MaskedType) * 8) ));
+ BOOST_STATIC_ASSERT(( (Offset + Width) < ( bit_width<T>::value - 1) ));
+
// precondition 2.
- BOOST_STATIC_ASSERT(( MaskOffsetInBits::value >= 0 ));
+ // this is always true because the offset is specified as an unsigned integer.
+ // BOOST_STATIC_ASSERT(( >= 0 ));
// precondition 3.
- BOOST_STATIC_ASSERT(( MaskWidth::value > 0 ));
+ BOOST_STATIC_ASSERT(( Width > 0 ));
// precondition 4.
- BOOST_STATIC_ASSERT(( is_integral<MaskedType>::value ));
-
-
- // this is supposed to make decalring a static constant easy, I think...
- // BOOST_STATIC_CONSTANT( MaskedType, value = ( ) );
-
- // type typedef
- typedef bit_mask_impl< MaskedType,
- MaskOffsetInBits,
- MaskWidth
- > type;
-
- typedef MaskedType mask_type;
- typedef MaskOffsetInBits bit_offset;
- typedef MaskWidth mask_width;
+ BOOST_STATIC_ASSERT(( is_integral<T>::value ));
};
-
-/** bit_mask_impl specialization over an mpl type. */
-template < typename MaskedType, typename IntegralType, IntegralType IntegralValue>
-struct bit_mask_impl< MaskedType, mpl::integral_c<IntegralType, IntegralValue>, unused_type>
-{ };
-
} // end of details namespace.
} // end of boost namespace.
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