Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62364 - sandbox/SOC/2010/bits_and_ints/boost/integer/detail
From: muriloufg_at_[hidden]
Date: 2010-05-31 19:24:41


Author: murilov
Date: 2010-05-31 19:24:41 EDT (Mon, 31 May 2010)
New Revision: 62364
URL: http://svn.boost.org/trac/boost/changeset/62364

Log:
(Miscommited) Function bit_reversal, static_bit_reversal template and some utilities declared in integer/detail/utils.hpp done.
Added:
   sandbox/SOC/2010/bits_and_ints/boost/integer/detail/static_bit_reversal.hpp (contents, props changed)
   sandbox/SOC/2010/bits_and_ints/boost/integer/detail/static_sign_extend.hpp (contents, props changed)
   sandbox/SOC/2010/bits_and_ints/boost/integer/detail/utils.hpp (contents, props changed)

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/detail/static_bit_reversal.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/detail/static_bit_reversal.hpp 2010-05-31 19:24:41 EDT (Mon, 31 May 2010)
@@ -0,0 +1,53 @@
+// Boost integer/detail/static_bit_reversal.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 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.
+
+#ifndef BOOST_STATIC_BIT_REVERSAL_INCLUDED
+#define BOOST_STATIC_BIT_REVERSAL_INCLUDED
+
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits.hpp>
+#include "utils.hpp" // is_bit_set<>
+
+/*
+ * Reverses the bits in data in compile-time
+ * For example if binary representation of data is:
+ * 00000000000010001010101000001111
+ * static_bit_reversal<type, data>::value is:
+ * 11110000010101010000000000000000
+ */
+
+namespace boost
+{
+
+// Base container
+template <typename T, T val>
+struct static_bit_reversal_base
+{
+ BOOST_STATIC_CONSTANT(T, value = val);
+};
+
+// @TODO: shift template parameter
+// must not be changeable by user
+template <typename T, T val, std::size_t shift = sizeof(T) * 8>
+struct static_bit_reversal :
+ public static_bit_reversal_base<T,
+ ((is_bit_set<T, val, (sizeof(T) * 8 - shift)>::value << (shift - 1))
+ + static_bit_reversal<T, val, shift - 1>::value)
+ >
+{};
+
+// Base case
+template <typename T, T val>
+struct static_bit_reversal<T, val, 0> :
+ static_bit_reversal_base<T, T(0)> {};
+
+
+} // boost
+
+#endif
\ No newline at end of file

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/detail/static_sign_extend.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/detail/static_sign_extend.hpp 2010-05-31 19:24:41 EDT (Mon, 31 May 2010)
@@ -0,0 +1,32 @@
+// Boost integer/detail/static_sign_extend.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 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.
+
+#ifndef BOOST_STATIC_SIGN_EXTEND_INCLUDED
+#define BOOST_STATIC_SIGN_EXTEND_INCLUDED
+
+#include <boost/cstdint.hpp> // for intmax_t
+
+namespace boost
+{
+
+// Compile-time version of sign_extend
+template<typename IntegralType, Raw raw, unsigned B>
+struct static_sign_extend
+{
+ typedef IntegralType T;
+private:
+ BOOST_STATIC_CONSTANT(T, shift = (T(1) << (B - 1)));
+ BOOST_STATIC_CONSTANT(T, m = ((T(1) << B) - 1));
+public:
+ BOOST_STATIC_CONSTANT(Raw, value = ((raw & m) ^ shift) - shift);
+}; // boost::static_sign_extend
+
+} // boost
+
+#endif
\ No newline at end of file

Added: sandbox/SOC/2010/bits_and_ints/boost/integer/detail/utils.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/detail/utils.hpp 2010-05-31 19:24:41 EDT (Mon, 31 May 2010)
@@ -0,0 +1,56 @@
+// Boost integer/detail/utils.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 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.
+
+#ifndef BOOST_INTEGER_UTILS_INCLUDED
+#define BOOST_INTEGER_UTILS_INCLUDED
+
+/*
+ * Some utilities to handle integers.
+ */
+namespace boost
+{
+
+// Sets the bit `pos' in data
+template <typename T, T data, unsigned char pos>
+struct set_bit
+{
+ BOOST_STATIC_CONSTANT(T, value = data | (T(1) << pos));
+}; // set_bit
+
+// Clear the bit `pos' in data
+template <typename T, T data, unsigned char pos>
+struct clear_bit
+{
+ BOOST_STATIC_CONSTANT(T, value = data & ~(T(1) << pos));
+}; // clear_bit
+
+// If the bit `pos' is 1 then it will be 0 if not the bit will be 1
+template <typename T, T data, unsigned char pos>
+struct flip_bit
+{
+ BOOST_STATIC_CONSTANT(T, value = data ^ (T(1) << pos));
+}; // flip_bit
+
+// Test if the bit in `pos' positon is set or not
+template <typename T, T data, unsigned char pos>
+struct is_bit_set
+{
+ BOOST_STATIC_CONSTANT(T, value = ((data >> pos) & T(1)) != T(0));
+}; // is_bit_set
+
+// Changes the value of bit in `pos' position
+template <typename T, T data, unsigned char pos, bool state>
+struct modify_bit
+{
+ BOOST_STATIC_CONSTANT(T, value = ((data & ~(T(1) << pos)) | (-state & (T(1) << pos))));
+}; // modify_bit
+
+} // boost
+
+#endif
\ No newline at end of file


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