1// boost/detail/bitmask.hpp ------------------------------------------------//
2
3// Copyright Beman Dawes 2006
4
5// Distributed under the Boost Software License, Version 1.0
6// http://www.boost.org/LICENSE_1_0.txt
7
8// Usage: enum foo { a=1, b=2, c=4 };
9// BOOST_BITMASK( foo )
10//
11// void f( foo arg );
12// ...
13// f( a | c );
14//
15// See [bitmask.types] in the C++ standard for the formal specification
16
17#ifndef BOOST_BITMASK_HPP
18#define BOOST_BITMASK_HPP
19
20#include <boost/config.hpp>
21#include <boost/cstdint.hpp>
22
23#define BOOST_BITMASK(Bitmask) \
24 \
25 inline BOOST_CONSTEXPR Bitmask operator| (Bitmask x , Bitmask y ) \
26 { return static_cast<Bitmask>( static_cast<boost::int_least32_t>(x) \
27 | static_cast<boost::int_least32_t>(y)); } \
28 \
29 inline BOOST_CONSTEXPR Bitmask operator& (Bitmask x , Bitmask y ) \
30 { return static_cast<Bitmask>( static_cast<boost::int_least32_t>(x) \
31 & static_cast<boost::int_least32_t>(y)); } \
32 \
33 inline BOOST_CONSTEXPR Bitmask operator^ (Bitmask x , Bitmask y ) \
34 { return static_cast<Bitmask>( static_cast<boost::int_least32_t>(x) \
35 ^ static_cast<boost::int_least32_t>(y)); } \
36 \
37 inline BOOST_CONSTEXPR Bitmask operator~ (Bitmask x ) \
38 { return static_cast<Bitmask>(~static_cast<boost::int_least32_t>(x)); } \
39 \
40 inline Bitmask & operator&=(Bitmask& x , Bitmask y) \
41 { x = x & y ; return x ; } \
42 \
43 inline Bitmask & operator|=(Bitmask& x , Bitmask y) \
44 { x = x | y ; return x ; } \
45 \
46 inline Bitmask & operator^=(Bitmask& x , Bitmask y) \
47 { x = x ^ y ; return x ; } \
48 \
49 /* Boost extensions to [bitmask.types] */ \
50 \
51 inline BOOST_CONSTEXPR bool operator!(Bitmask x) \
52 { return !static_cast<int>(x); } \
53 \
54 inline BOOST_CONSTEXPR bool bitmask_set(Bitmask x) \
55 { return !!x; }
56
57#endif // BOOST_BITMASK_HPP
58
59