Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/boost/integer/integer_mask.hpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

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