$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r64105 - in sandbox/SOC/2010/bit_masks: boost/integer/detail/bft lib/integer/test/bft_testing
From: bbartmanboost_at_[hidden]
Date: 2010-07-17 12:25:34
Author: bbartman
Date: 2010-07-17 12:25:34 EDT (Sat, 17 Jul 2010)
New Revision: 64105
URL: http://svn.boost.org/trac/boost/changeset/64105
Log:
completed initial work of creating metafunctions which will allow the arguments being parsed for bitfield_tuple to be able to handle operations specific to the new pointer member
Text files modified: 
   sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_parsing_meta_functions.hpp         |   113 ++++++++++++++++++++++++++++++++++++++++
   sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_parsing_meta_function_test.cpp |    26 ++++++++                                
   2 files changed, 138 insertions(+), 1 deletions(-)
Modified: sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_parsing_meta_functions.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_parsing_meta_functions.hpp	(original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/detail/bft/pointer_parsing_meta_functions.hpp	2010-07-17 12:25:34 EDT (Sat, 17 Jul 2010)
@@ -7,12 +7,125 @@
 #ifndef BOOST_BITFIELD_TUPLE_POINTER_PARSING_HELPERS_HPP
 #define BOOST_BITFIELD_TUPLE_POINTER_PARSING_HELPERS_HPP
 
+#include <boost/integer/bits_mask.hpp>
+#include <cstddef>
+#include <boost/mpl/size_t.hpp>
+#include <boost/type_traits/make_unsigned.hpp>
+
 /** This file contains metafunctions which are used to do complex operations
  *  on the Mask provided by the user.
  */
 namespace boost { namespace detail { namespace pointer_member {
 
 
+
+// this is ugly but I would like it for organizational purposes.
+namespace ptr_detail {
+
+// Count leading zeros helper
+// basically recurse until the true false condition is evaluated as false.
+template <
+    typename Mask,
+    typename IndexingMask = bits_mask<
+        typename make_unsigned<
+            typename Mask::value_type
+        >::type,
+        bit_width<
+            typename Mask::value_type
+        >::value - 1
+    >,
+    std::size_t ZeroCount = 0,
+    bool = true
+>
+struct clz_helper;
+
+/** Continued recursive case. */
+template <
+    typename Mask,
+    typename IndexingMask,
+    std::size_t ZeroCount
+>
+struct clz_helper<Mask,IndexingMask,ZeroCount,true>
+    :clz_helper<
+        Mask,
+        bits_mask<
+            typename IndexingMask::value_type,
+            IndexingMask::offset - 1
+        >,
+        ZeroCount + 1,
+        ((IndexingMask::value & Mask::value) == 0)
+          &&
+        (IndexingMask::offset >= 0)
+    >
+{ };
+
+/** Recursive Termination Case. */ 
+template <
+    typename Mask,
+    typename IndexingMask,
+    std::size_t ZeroCount
+>
+struct clz_helper<Mask,IndexingMask,ZeroCount,false> {
+    typedef mpl::size_t<ZeroCount - 1> type;
+};
+
+
+template <
+    typename Mask,
+    typename IndexingMask = bits_mask<
+        typename make_unsigned< typename Mask::value_type >::type,
+        0
+    >,
+    std::size_t ZeroCount = 0,
+    bool = true
+>
+struct ctz_helper;
+
+/** Recursive loop. */
+
+template <
+    typename Mask,
+    typename IndexingMask,
+    std::size_t ZeroCount
+>
+struct ctz_helper<Mask,IndexingMask,ZeroCount,true>
+    :ctz_helper<
+        Mask,
+        bits_mask<
+            typename IndexingMask::value_type,
+            IndexingMask::offset + 1
+        >,
+        ZeroCount + 1,
+        ((IndexingMask::value & Mask::value) == 0)
+          &&
+        (IndexingMask::offset < bit_width< typename Mask::value_type >::value)
+    >
+{ };
+
+/** Recursive tremination. */
+template <
+    typename Mask,
+    typename IndexingMask,
+    std::size_t ZeroCount
+>
+struct ctz_helper<Mask,IndexingMask,ZeroCount,false> {
+    typedef mpl::size_t<ZeroCount - 1 >  type;
+};
+
+
+
+} // end ptr_detail
+
+template <typename Mask>
+struct count_leading_zeros {
+    typedef typename ptr_detail::clz_helper<Mask>::type type;
+};
+
+
+template <typename Mask>
+struct count_trailing_zeros {
+    typedef typename ptr_detail::ctz_helper<Mask>::type type;
+};
 }}} // end boost::detail::pointer_member
 
 #endif
Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_parsing_meta_function_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_parsing_meta_function_test.cpp	(original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/pointer_parsing_meta_function_test.cpp	2010-07-17 12:25:34 EDT (Sat, 17 Jul 2010)
@@ -7,6 +7,30 @@
 #include <boost/detail/lightweight_test.hpp>
 #include <boost/type_traits/is_same.hpp>
 
+#include <iomanip>
+#include <iostream>
+using namespace ::boost::detail::pointer_member;
+
 int main() {
-    return 0;
+    // count leading zeros metafunction test.
+    {
+        // Testing to make sure that if there is a bit at the first position
+        // that 0 is correctly returned.
+        typedef count_leading_zeros< boost::bits_mask<unsigned int, 31> >::type test_t1;
+        BOOST_TEST((test_t1::value == 0 ));
+
+        // testing to make sure that the test passes if the last bit is 1.
+        typedef count_leading_zeros<boost::bits_mask<unsigned int,0> >::type test_t2;
+        BOOST_TEST( test_t2::value == 31 );
+    }
+
+    // count trailing zeros test.
+    {
+        typedef count_trailing_zeros<boost::bits_mask<unsigned int,31> >::type test_1;
+        BOOST_TEST( test_1::value == 31 );
+
+        typedef count_trailing_zeros<boost::bits_mask<unsigned int,0> >::type test_2;
+        BOOST_TEST( test_2::value == 0 );
+    }
+    return boost::report_errors();
 }