mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
macro.hpp
Go to the documentation of this file.
1
#pragma once
14
#define MAL_TOOLKIT_DECLARE_ENUM_BIT_OPERATORS_EX(ENUM_TYPE, ENUM_TYPE_UNDERLYING) \
15
inline ENUM_TYPE operator|(ENUM_TYPE a, ENUM_TYPE b) \
16
{ \
17
return static_cast<ENUM_TYPE>(static_cast<ENUM_TYPE_UNDERLYING>(a) | static_cast<ENUM_TYPE_UNDERLYING>(b)); \
18
} \
19
inline ENUM_TYPE operator&(ENUM_TYPE a, ENUM_TYPE b) \
20
{ \
21
return static_cast<ENUM_TYPE>(static_cast<ENUM_TYPE_UNDERLYING>(a) & static_cast<ENUM_TYPE_UNDERLYING>(b)); \
22
} \
23
inline ENUM_TYPE operator^(ENUM_TYPE a, ENUM_TYPE b) \
24
{ \
25
return static_cast<ENUM_TYPE>(static_cast<ENUM_TYPE_UNDERLYING>(a) ^ static_cast<ENUM_TYPE_UNDERLYING>(b)); \
26
} \
27
inline ENUM_TYPE operator~(ENUM_TYPE a) { return static_cast<ENUM_TYPE>(~static_cast<ENUM_TYPE_UNDERLYING>(a)); } \
28
inline ENUM_TYPE &operator|=(ENUM_TYPE &a, ENUM_TYPE b) { return a = a | b; } \
29
inline ENUM_TYPE &operator&=(ENUM_TYPE &a, ENUM_TYPE b) { return a = a & b; } \
30
inline ENUM_TYPE &operator^=(ENUM_TYPE &a, ENUM_TYPE b) { return a = a ^ b; } \
31
inline bool operator!(ENUM_TYPE a) { return !static_cast<ENUM_TYPE_UNDERLYING>(a); } \
32
template <std::integral T> \
33
inline ENUM_TYPE operator|(ENUM_TYPE a, T b) \
34
{ \
35
return a | static_cast<ENUM_TYPE>(b); \
36
} \
37
template <std::integral T> \
38
inline ENUM_TYPE operator&(ENUM_TYPE a, T b) \
39
{ \
40
return a & static_cast<ENUM_TYPE>(b); \
41
} \
42
template <std::integral T> \
43
inline ENUM_TYPE operator^(ENUM_TYPE a, T b) \
44
{ \
45
return a ^ static_cast<ENUM_TYPE>(b); \
46
} \
47
template <std::integral T> \
48
inline ENUM_TYPE &operator|=(ENUM_TYPE &a, T b) \
49
{ \
50
return a = a | b; \
51
} \
52
template <std::integral T> \
53
inline ENUM_TYPE &operator&=(ENUM_TYPE &a, T b) \
54
{ \
55
return a = a & b; \
56
} \
57
template <std::integral T> \
58
inline ENUM_TYPE &operator^=(ENUM_TYPE &a, T b) \
59
{ \
60
return a = a ^ b; \
61
} \
62
template <std::integral T> \
63
inline ENUM_TYPE operator|(T a, ENUM_TYPE b) \
64
{ \
65
return static_cast<ENUM_TYPE>(a) | b; \
66
} \
67
template <std::integral T> \
68
inline ENUM_TYPE operator&(T a, ENUM_TYPE b) \
69
{ \
70
return static_cast<ENUM_TYPE>(a) & b; \
71
} \
72
template <std::integral T> \
73
inline ENUM_TYPE operator^(T a, ENUM_TYPE b) \
74
{ \
75
return static_cast<ENUM_TYPE>(a) ^ b; \
76
}
82
#define MAL_TOOLKIT_DECLARE_ENUM_BIT_OPERATORS(ENUM_TYPE) \
83
MAL_TOOLKIT_DECLARE_ENUM_BIT_OPERATORS_EX(ENUM_TYPE, std::underlying_type_t<ENUM_TYPE>)
84
90
#define MAL_TOOLKIT_DECLARE_ENUM_BIT_FUNCTIONS(ENUM_TYPE) \
91
template <typename T> \
92
inline bool HasFlag(ENUM_TYPE a, T b) \
93
{ \
94
return (a & b) == b; \
95
} \
96
template <typename T> \
97
inline bool HasAnyFlag(ENUM_TYPE a, T b) \
98
{ \
99
return (a & b) != 0; \
100
} \
101
template <typename T> \
102
inline bool HasAllFlags(ENUM_TYPE a, T b) \
103
{ \
104
return (a & b) == a; \
105
} \
106
template <typename T> \
107
inline ENUM_TYPE SetFlag(ENUM_TYPE a, T b) \
108
{ \
109
return a | b; \
110
} \
111
template <typename T> \
112
inline ENUM_TYPE ClearFlag(ENUM_TYPE a, T b) \
113
{ \
114
return a & ~b; \
115
} \
116
template <typename T> \
117
inline ENUM_TYPE FlipFlag(ENUM_TYPE a, T b) \
118
{ \
119
return a ^ b; \
120
}
121
127
#define MAL_TOOLKIT_DECLARE_ENUM_BIT_OPERATORS_AND_FUNCTIONS(ENUM_TYPE) \
128
MAL_TOOLKIT_DECLARE_ENUM_BIT_OPERATORS(ENUM_TYPE) \
129
MAL_TOOLKIT_DECLARE_ENUM_BIT_FUNCTIONS(ENUM_TYPE)
third_party
mal-toolkit
mal-toolkit
mal-toolkit
macro.hpp
Generated on Sun Jul 14 2024 00:02:52 for mal-packet-weaver by
1.11.0