Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61951 - in sandbox/SOC/2010/bit_masks: boost/integer boost/integer/details lib/integer/test
From: bbartmanboost_at_[hidden]
Date: 2010-05-13 11:19:06


Author: bbartman
Date: 2010-05-13 11:19:06 EDT (Thu, 13 May 2010)
New Revision: 61951
URL: http://svn.boost.org/trac/boost/changeset/61951

Log:
completed most of my work for the high bits and low bits all thats left is testing for it
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bit_width.hpp | 2 +-
   sandbox/SOC/2010/bit_masks/boost/integer/details/high_low_impl.hpp | 32 ++++++++++++++++++++++++++++++++
   sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp | 19 +++++++++++++++----
   sandbox/SOC/2010/bit_masks/lib/integer/test/high_bit_mask_test.cpp | 15 ++++++++++++---
   4 files changed, 60 insertions(+), 8 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/bit_width.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bit_width.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bit_width.hpp 2010-05-13 11:19:06 EDT (Thu, 13 May 2010)
@@ -7,7 +7,7 @@
 #ifndef BOOST_INTEGRAL_BIT_WIDTH_HPP
 #define BOOST_INTEGRAL_BIT_WIDTH_HPP
 #include <boost/type_traits.hpp>
-#include <boost/integer/details/high_low_impl.hpp>
+
 
 
 namespace boost {

Modified: sandbox/SOC/2010/bit_masks/boost/integer/details/high_low_impl.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/details/high_low_impl.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/details/high_low_impl.hpp 2010-05-13 11:19:06 EDT (Thu, 13 May 2010)
@@ -0,0 +1,32 @@
+// (C) Copyright Brian Bartman 2010.
+// 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 for updates, documentation, and revision history.
+
+
+#include <boost/static_assert.hpp>
+#include <boost/integer/bit_width.hpp>
+
+namespace boost { namespace details {
+
+/** Preconditions for low_bits metafunction.
+ * Precondition:
+ * 1. The width must not be greater then the size in bits of type T.
+ */
+template <typename T, unsigned int Width>
+struct low_bits_preconditions {
+ BOOST_STATIC_ASSERT(( bit_width<T>::value >= Width ));
+};
+
+/** Preconditions for high_bits metafunction.
+ * Precondition:
+ * 1. The width must not be greater then the size in bits of type T.
+ */
+template <typename T, unsigned int Width>
+struct high_bits_preconditions {
+ BOOST_STATIC_ASSERT(( bit_width<T>::value >= Width ));
+};
+
+
+} } // namespace boost::details

Modified: sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp 2010-05-13 11:19:06 EDT (Thu, 13 May 2010)
@@ -8,8 +8,8 @@
 #ifndef BOOST_HIGH_LOW_BIT_HPP
 #define BOOST_HIGH_LOW_BIT_HPP
 
-#include <boost/mpl/integral_c.hpp>
 #include <boost/type_traits.hpp>
+#include <boost/integer/details/high_low_impl.hpp>
 
 namespace boost {
 
@@ -19,12 +19,23 @@
  */
 template <typename T, unsigned int Width>
 struct low_bits
- :integral_constant<T, ~(~T(0) << Width) >
-{
-
+ :details::low_bits_preconditions<T,Width>,
+ integral_constant<T, ~(~T(0) << Width) >
+{
     typedef low_bits<T,Width> type;
 };
 
+/** Creates a mask of the supplied width in side type T, from the lower portion
+ * of the integer starting from the right most bit moving towards the left.
+ */
+template <typename T, unsigned int Width>
+struct high_bits
+ :details::high_bits_preconditions<T,Width>,
+ integral_constant<T, ~(~T(0) >> Width) >
+{
+ typedef high_bits<T,Width> type;
+};
+
 
 
 } // namespace boost

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/high_bit_mask_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/high_bit_mask_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/high_bit_mask_test.cpp 2010-05-13 11:19:06 EDT (Thu, 13 May 2010)
@@ -1,7 +1,16 @@
-
-
+#include <boost/assert.hpp>
+#include <boost/type_traits.hpp>
 #include <boost/integer/high_low_bits.hpp>
 
-int main() {
+// tesitng for bit width.
+using namespace boost;
+
+int main() {
+ {
+ typedef high_bits<unsigned int, 3> hb;
+ BOOST_ASSERT(( hb::value == 3758096384 ));
+ BOOST_ASSERT(( is_same<hb::value_type, unsigned int>::value ));
+ BOOST_ASSERT(( is_same<hb::type, hb>::value ));
+ }
     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