1 // Boost integer/integer_mask.hpp header file ------------------------------//
\r
3 // (C) Copyright Daryle Walker 2001.
\r
4 // Distributed under the Boost Software License, Version 1.0. (See
\r
5 // accompanying file LICENSE_1_0.txt or copy at
\r
6 // http://www.boost.org/LICENSE_1_0.txt)
\r
8 // See http://www.boost.org for updates, documentation, and revision history.
\r
10 #ifndef BOOST_INTEGER_INTEGER_MASK_HPP
\r
11 #define BOOST_INTEGER_INTEGER_MASK_HPP
\r
13 #include <boost/integer_fwd.hpp> // self include
\r
15 #include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
\r
16 #include <boost/integer.hpp> // for boost::uint_t
\r
18 #include <climits> // for UCHAR_MAX, etc.
\r
19 #include <cstddef> // for std::size_t
\r
21 #include <boost/limits.hpp> // for std::numeric_limits
\r
28 // Specified single-bit mask class declaration -----------------------------//
\r
29 // (Lowest bit starts counting at 0.)
\r
31 template < std::size_t Bit >
\r
32 struct high_bit_mask_t
\r
34 typedef typename uint_t<(Bit + 1)>::least least;
\r
35 typedef typename uint_t<(Bit + 1)>::fast fast;
\r
37 BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) );
\r
38 BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) );
\r
40 BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit );
\r
42 }; // boost::high_bit_mask_t
\r
45 // Specified bit-block mask class declaration ------------------------------//
\r
46 // Makes masks for the lowest N bits
\r
47 // (Specializations are needed when N fills up a type.)
\r
49 template < std::size_t Bits >
\r
50 struct low_bits_mask_t
\r
52 typedef typename uint_t<Bits>::least least;
\r
53 typedef typename uint_t<Bits>::fast fast;
\r
55 BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
\r
56 BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
\r
58 BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits );
\r
60 }; // boost::low_bits_mask_t
\r
63 #define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \
\r
64 template < > struct low_bits_mask_t< std::numeric_limits<Type>::digits > { \
\r
65 typedef std::numeric_limits<Type> limits_type; \
\r
66 typedef uint_t<limits_type::digits>::least least; \
\r
67 typedef uint_t<limits_type::digits>::fast fast; \
\r
68 BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) ); \
\r
69 BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) ); \
\r
70 BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits ); \
\r
74 #pragma warning(push)
\r
75 #pragma warning(disable:4245) // 'initializing' : conversion from 'int' to 'const boost::low_bits_mask_t<8>::least', signed/unsigned mismatch
\r
78 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char );
\r
80 #if USHRT_MAX > UCHAR_MAX
\r
81 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short );
\r
84 #if UINT_MAX > USHRT_MAX
\r
85 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int );
\r
88 #if ULONG_MAX > UINT_MAX
\r
89 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long );
\r
93 #pragma warning(pop)
\r
96 #undef BOOST_LOW_BITS_MASK_SPECIALIZE
\r
99 } // namespace boost
\r
102 #endif // BOOST_INTEGER_INTEGER_MASK_HPP
\r