blob: e5dce4ad6f843e07c99d0eff67f28691c5828c0d [file] [log] [blame]
Jeff Thompson86b6d642013-10-17 15:01:56 -07001// ndnboost/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// NDNBOOST_BITMASK( foo );
10//
11// void f( foo arg );
12// ...
13// f( a | c );
14
15#ifndef NDNBOOST_BITMASK_HPP
16#define NDNBOOST_BITMASK_HPP
17
18#include <ndnboost/cstdint.hpp>
19
20#define NDNBOOST_BITMASK(Bitmask) \
21 \
22 inline Bitmask operator| (Bitmask x , Bitmask y ) \
23 { return static_cast<Bitmask>( static_cast<ndnboost::int_least32_t>(x) \
24 | static_cast<ndnboost::int_least32_t>(y)); } \
25 \
26 inline Bitmask operator& (Bitmask x , Bitmask y ) \
27 { return static_cast<Bitmask>( static_cast<ndnboost::int_least32_t>(x) \
28 & static_cast<ndnboost::int_least32_t>(y)); } \
29 \
30 inline Bitmask operator^ (Bitmask x , Bitmask y ) \
31 { return static_cast<Bitmask>( static_cast<ndnboost::int_least32_t>(x) \
32 ^ static_cast<ndnboost::int_least32_t>(y)); } \
33 \
34 inline Bitmask operator~ (Bitmask x ) \
35 { return static_cast<Bitmask>(~static_cast<ndnboost::int_least32_t>(x)); } \
36 \
37 inline Bitmask & operator&=(Bitmask & x , Bitmask y) \
38 { x = x & y ; return 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#endif // NDNBOOST_BITMASK_HPP
47