sl@0: // Boost integer/integer_mask.hpp header file ------------------------------// sl@0: sl@0: // (C) Copyright Daryle Walker 2001. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // See http://www.boost.org for updates, documentation, and revision history. sl@0: sl@0: #ifndef BOOST_INTEGER_INTEGER_MASK_HPP sl@0: #define BOOST_INTEGER_INTEGER_MASK_HPP sl@0: sl@0: #include // self include sl@0: sl@0: #include // for BOOST_STATIC_CONSTANT sl@0: #include // for boost::uint_t sl@0: sl@0: #include // for UCHAR_MAX, etc. sl@0: #include // for std::size_t sl@0: sl@0: #include // for std::numeric_limits sl@0: sl@0: sl@0: namespace boost sl@0: { sl@0: sl@0: sl@0: // Specified single-bit mask class declaration -----------------------------// sl@0: // (Lowest bit starts counting at 0.) sl@0: sl@0: template < std::size_t Bit > sl@0: struct high_bit_mask_t sl@0: { sl@0: typedef typename uint_t<(Bit + 1)>::least least; sl@0: typedef typename uint_t<(Bit + 1)>::fast fast; sl@0: sl@0: BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) ); sl@0: BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) ); sl@0: sl@0: BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit ); sl@0: sl@0: }; // boost::high_bit_mask_t sl@0: sl@0: sl@0: // Specified bit-block mask class declaration ------------------------------// sl@0: // Makes masks for the lowest N bits sl@0: // (Specializations are needed when N fills up a type.) sl@0: sl@0: template < std::size_t Bits > sl@0: struct low_bits_mask_t sl@0: { sl@0: typedef typename uint_t::least least; sl@0: typedef typename uint_t::fast fast; sl@0: sl@0: BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) ); sl@0: BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); sl@0: sl@0: BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits ); sl@0: sl@0: }; // boost::low_bits_mask_t sl@0: sl@0: sl@0: #define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \ sl@0: template < > struct low_bits_mask_t< std::numeric_limits::digits > { \ sl@0: typedef std::numeric_limits limits_type; \ sl@0: typedef uint_t::least least; \ sl@0: typedef uint_t::fast fast; \ sl@0: BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \ sl@0: BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \ sl@0: BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \ sl@0: } sl@0: sl@0: BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char ); sl@0: sl@0: #if USHRT_MAX > UCHAR_MAX sl@0: BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short ); sl@0: #endif sl@0: sl@0: #if UINT_MAX > USHRT_MAX sl@0: BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int ); sl@0: #endif sl@0: sl@0: #if ULONG_MAX > UINT_MAX sl@0: BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long ); sl@0: #endif sl@0: sl@0: #undef BOOST_LOW_BITS_MASK_SPECIALIZE sl@0: sl@0: sl@0: } // namespace boost sl@0: sl@0: sl@0: #endif // BOOST_INTEGER_INTEGER_MASK_HPP