summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorGravatar bunnei2020-03-20 22:40:03 -0400
committerGravatar bunnei2020-04-17 00:59:27 -0400
commitb11b424a2df48c6e17968be1d6dd2b69c7c728db (patch)
treea28052da071b98bdf3533a576e56daa1d30d2a00 /src/common
parentprocess: SetupMainThread: Zero out argument on process start. (diff)
downloadyuzu-b11b424a2df48c6e17968be1d6dd2b69c7c728db.tar.gz
yuzu-b11b424a2df48c6e17968be1d6dd2b69c7c728db.tar.xz
yuzu-b11b424a2df48c6e17968be1d6dd2b69c7c728db.zip
common: common_funcs: Add a macro for defining enum flag operators.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/common_funcs.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index 052254678..88cf5250a 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -55,6 +55,38 @@ __declspec(dllimport) void __stdcall DebugBreak(void);
55// Defined in Misc.cpp. 55// Defined in Misc.cpp.
56std::string GetLastErrorMsg(); 56std::string GetLastErrorMsg();
57 57
58#define DECLARE_ENUM_FLAG_OPERATORS(type) \
59 constexpr type operator|(type a, type b) noexcept { \
60 using T = std::underlying_type_t<type>; \
61 return static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \
62 } \
63 constexpr type operator&(type a, type b) noexcept { \
64 using T = std::underlying_type_t<type>; \
65 return static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \
66 } \
67 constexpr type& operator|=(type& a, type b) noexcept { \
68 using T = std::underlying_type_t<type>; \
69 a = static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \
70 return a; \
71 } \
72 constexpr type& operator&=(type& a, type b) noexcept { \
73 using T = std::underlying_type_t<type>; \
74 a = static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \
75 return a; \
76 } \
77 constexpr type operator~(type key) noexcept { \
78 using T = std::underlying_type_t<type>; \
79 return static_cast<type>(~static_cast<T>(key)); \
80 } \
81 constexpr bool True(type key) noexcept { \
82 using T = std::underlying_type_t<type>; \
83 return static_cast<T>(key) != 0; \
84 } \
85 constexpr bool False(type key) noexcept { \
86 using T = std::underlying_type_t<type>; \
87 return static_cast<T>(key) == 0; \
88 }
89
58namespace Common { 90namespace Common {
59 91
60constexpr u32 MakeMagic(char a, char b, char c, char d) { 92constexpr u32 MakeMagic(char a, char b, char c, char d) {