os/ossrv/ossrv_pub/boost_apis/boost/integer/integer_mask.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
//  Boost integer/integer_mask.hpp header file  ------------------------------//
sl@0
     2
sl@0
     3
//  (C) Copyright Daryle Walker 2001.
sl@0
     4
//  Distributed under the Boost Software License, Version 1.0. (See
sl@0
     5
//  accompanying file LICENSE_1_0.txt or copy at
sl@0
     6
//  http://www.boost.org/LICENSE_1_0.txt)
sl@0
     7
sl@0
     8
//  See http://www.boost.org for updates, documentation, and revision history. 
sl@0
     9
sl@0
    10
#ifndef BOOST_INTEGER_INTEGER_MASK_HPP
sl@0
    11
#define BOOST_INTEGER_INTEGER_MASK_HPP
sl@0
    12
sl@0
    13
#include <boost/integer_fwd.hpp>  // self include
sl@0
    14
sl@0
    15
#include <boost/config.hpp>   // for BOOST_STATIC_CONSTANT
sl@0
    16
#include <boost/integer.hpp>  // for boost::uint_t
sl@0
    17
sl@0
    18
#include <climits>  // for UCHAR_MAX, etc.
sl@0
    19
#include <cstddef>  // for std::size_t
sl@0
    20
sl@0
    21
#include <boost/limits.hpp>  // for std::numeric_limits
sl@0
    22
sl@0
    23
sl@0
    24
namespace boost
sl@0
    25
{
sl@0
    26
sl@0
    27
sl@0
    28
//  Specified single-bit mask class declaration  -----------------------------//
sl@0
    29
//  (Lowest bit starts counting at 0.)
sl@0
    30
sl@0
    31
template < std::size_t Bit >
sl@0
    32
struct high_bit_mask_t
sl@0
    33
{
sl@0
    34
    typedef typename uint_t<(Bit + 1)>::least  least;
sl@0
    35
    typedef typename uint_t<(Bit + 1)>::fast   fast;
sl@0
    36
sl@0
    37
    BOOST_STATIC_CONSTANT( least, high_bit = (least( 1u ) << Bit) );
sl@0
    38
    BOOST_STATIC_CONSTANT( fast, high_bit_fast = (fast( 1u ) << Bit) );
sl@0
    39
sl@0
    40
    BOOST_STATIC_CONSTANT( std::size_t, bit_position = Bit );
sl@0
    41
sl@0
    42
};  // boost::high_bit_mask_t
sl@0
    43
sl@0
    44
sl@0
    45
//  Specified bit-block mask class declaration  ------------------------------//
sl@0
    46
//  Makes masks for the lowest N bits
sl@0
    47
//  (Specializations are needed when N fills up a type.)
sl@0
    48
sl@0
    49
template < std::size_t Bits >
sl@0
    50
struct low_bits_mask_t
sl@0
    51
{
sl@0
    52
    typedef typename uint_t<Bits>::least  least;
sl@0
    53
    typedef typename uint_t<Bits>::fast   fast;
sl@0
    54
sl@0
    55
    BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
sl@0
    56
    BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
sl@0
    57
sl@0
    58
    BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits );
sl@0
    59
sl@0
    60
};  // boost::low_bits_mask_t
sl@0
    61
sl@0
    62
sl@0
    63
#define BOOST_LOW_BITS_MASK_SPECIALIZE( Type )                                  \
sl@0
    64
  template <  >  struct low_bits_mask_t< std::numeric_limits<Type>::digits >  { \
sl@0
    65
      typedef std::numeric_limits<Type>           limits_type;                  \
sl@0
    66
      typedef uint_t<limits_type::digits>::least  least;                        \
sl@0
    67
      typedef uint_t<limits_type::digits>::fast   fast;                         \
sl@0
    68
      BOOST_STATIC_CONSTANT( least, sig_bits = (~( least(0u) )) );              \
sl@0
    69
      BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );            \
sl@0
    70
      BOOST_STATIC_CONSTANT( std::size_t, bit_count = limits_type::digits );    \
sl@0
    71
  }
sl@0
    72
sl@0
    73
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned char );
sl@0
    74
sl@0
    75
#if USHRT_MAX > UCHAR_MAX
sl@0
    76
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned short );
sl@0
    77
#endif
sl@0
    78
sl@0
    79
#if UINT_MAX > USHRT_MAX
sl@0
    80
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned int );
sl@0
    81
#endif
sl@0
    82
sl@0
    83
#if ULONG_MAX > UINT_MAX
sl@0
    84
BOOST_LOW_BITS_MASK_SPECIALIZE( unsigned long );
sl@0
    85
#endif
sl@0
    86
sl@0
    87
#undef BOOST_LOW_BITS_MASK_SPECIALIZE
sl@0
    88
sl@0
    89
sl@0
    90
}  // namespace boost
sl@0
    91
sl@0
    92
sl@0
    93
#endif  // BOOST_INTEGER_INTEGER_MASK_HPP