Overview   API Reference  

integer_mask.hpp

00001 //  Boost integer/integer_mask.hpp header file  ------------------------------//
00002 
00003 //  (C) Copyright Daryle Walker 2001.
00004 //  Distributed under the Boost Software License, Version 1.0. (See
00005 //  accompanying file LICENSE_1_0.txt or copy at
00006 //  http://www.boost.org/LICENSE_1_0.txt)
00007 
00008 //  See http://www.boost.org for updates, documentation, and revision history. 
00009 
00010 #ifndef BOOST_INTEGER_INTEGER_MASK_HPP
00011 #define BOOST_INTEGER_INTEGER_MASK_HPP
00012 
00013 #include <boost/integer_fwd.hpp>  // self include
00014 
00015 #include <boost/config.hpp>   // for BOOST_STATIC_CONSTANT
00016 #include <boost/integer.hpp>  // for boost::uint_t
00017 
00018 #include <climits>  // for UCHAR_MAX, etc.
00019 #include <cstddef>  // for std::size_t
00020 
00021 #include <boost/limits.hpp>  // for std::numeric_limits
00022 
00023 
00024 namespace boost
00025 {
00026 
00027 
00028 //  Specified single-bit mask class declaration  -----------------------------//
00029 //  (Lowest bit starts counting at 0.)
00030 
00031 template < std::size_t Bit >
00032 struct high_bit_mask_t
00033 {
00034     typedef typename uint_t<(Bit + 1)>::least  least;
00035     typedef typename uint_t<(Bit + 1)>::fast   fast;
00036 
00037     BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) );
00038     BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) );
00039 
00040     BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit );
00041 
00042 };  // boost::high_bit_mask_t
00043 
00044 
00045 //  Specified bit-block mask class declaration  ------------------------------//
00046 //  Makes masks for the lowest N bits
00047 //  (Specializations are needed when N fills up a type.)
00048 
00049 template < std::size_t Bits >
00050 struct low_bits_mask_t
00051 {
00052     typedef typename uint_t<Bits>::least  least;
00053     typedef typename uint_t<Bits>::fast   fast;
00054 
00055     BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
00056     BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
00057 
00058     BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits );
00059 
00060 };  // boost::low_bits_mask_t
00061 
00062 
00063 #define BOOST_LOW_BITS_MASK_SPECIALIZE( Type )                                  \
00064   template <  >  struct low_bits_mask_t< std::numeric_limits<Type>::digits >  { \
00065       typedef std::numeric_limits<Type>           limits_type;                  \
00066       typedef uint_t<limits_type::digits>::least  least;                        \
00067       typedef uint_t<limits_type::digits>::fast   fast;                         \
00068       BOOST_STATIC_CONSTANT( least, sig_bits = least(~( least(0u) )) );         \
00069       BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );            \
00070       BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits );    \
00071   }
00072 
00073 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char );
00074 
00075 #if USHRT_MAX > UCHAR_MAX
00076 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short );
00077 #endif
00078 
00079 #if UINT_MAX > USHRT_MAX
00080 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int );
00081 #endif
00082 
00083 #if ULONG_MAX > UINT_MAX
00084 BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long );
00085 #endif
00086 
00087 #undef BOOST_LOW_BITS_MASK_SPECIALIZE
00088 
00089 
00090 }  // namespace boost
00091 
00092 
00093 #endif  // BOOST_INTEGER_INTEGER_MASK_HPP

L4vmm Reference Manual, written by Mario Schwalbe  © 2006-2008