-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarty_flag_ops.h
95 lines (91 loc) · 8.34 KB
/
marty_flag_ops.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#include <type_traits>
//----------------------------------------------------------------------------
// https://stackoverflow.com/questions/1448396/how-to-use-enums-as-flags-in-c
#define MARTY_CPP_MAKE_ENUM_FLAGS(TEnum) \
inline \
bool enum_is_flags(TEnum) \
{ \
return true; \
} \
\
inline constexpr bool operator==(TEnum a, std::underlying_type<TEnum>::type b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
return static_cast<TUnder>(a) == b; \
} \
inline constexpr bool operator==(std::underlying_type<TEnum>::type a, TEnum b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
return a == static_cast<TUnder>(b); \
} \
inline constexpr bool operator!=(TEnum a, std::underlying_type<TEnum>::type b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
return static_cast<TUnder>(a) != b; \
} \
inline constexpr bool operator!=(std::underlying_type<TEnum>::type a, TEnum b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
return a != static_cast<TUnder>(b); \
} \
inline constexpr TEnum operator<<(TEnum a, unsigned b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
return static_cast<TEnum>(static_cast<TUnder>(a) << b); \
} \
inline constexpr TEnum operator>>(TEnum a, unsigned b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
return static_cast<TEnum>(static_cast<TUnder>(a) >> b); \
} \
inline constexpr TEnum operator~(TEnum a) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
return static_cast<TEnum>(~static_cast<TUnder>(a)); \
} \
inline constexpr TEnum operator|(TEnum a, TEnum b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
return static_cast<TEnum>(static_cast<TUnder>(a) | static_cast<TUnder>(b)); \
} \
inline constexpr TEnum operator&(TEnum a, TEnum b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
return static_cast<TEnum>(static_cast<TUnder>(a) & static_cast<TUnder>(b)); \
} \
inline constexpr TEnum operator^(TEnum a, TEnum b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
return static_cast<TEnum>(static_cast<TUnder>(a) ^ static_cast<TUnder>(b)); \
} \
inline constexpr TEnum& operator<<=(TEnum& a, unsigned b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
a = static_cast<TEnum>(static_cast<TUnder>(a) << b ); \
return a; \
} \
inline constexpr TEnum& operator>>=(TEnum& a, unsigned b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
a = static_cast<TEnum>(static_cast<TUnder>(a) >> b ); \
return a; \
} \
inline constexpr TEnum& operator|=(TEnum& a, TEnum b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
a = static_cast<TEnum>(static_cast<TUnder>(a) | static_cast<TUnder>(b)); \
return a; \
} \
inline constexpr TEnum& operator&=(TEnum& a, TEnum b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
a = static_cast<TEnum>(static_cast<TUnder>(a) & static_cast<TUnder>(b)); \
return a; \
} \
inline constexpr TEnum& operator^=(TEnum& a, TEnum b) \
{ \
using TUnder = typename std::underlying_type<TEnum>::type; \
a = static_cast<TEnum>(static_cast<TUnder>(a) ^ static_cast<TUnder>(b)); \
return a; \
}