summaryrefslogtreecommitdiff
path: root/src/common/common_funcs.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/common_funcs.h')
-rw-r--r--src/common/common_funcs.h42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index 052254678..367b6bf6e 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -53,11 +53,49 @@ __declspec(dllimport) void __stdcall DebugBreak(void);
53// Call directly after the command or use the error num. 53// Call directly after the command or use the error num.
54// This function might change the error code. 54// This function might change the error code.
55// Defined in Misc.cpp. 55// Defined in Misc.cpp.
56std::string GetLastErrorMsg(); 56[[nodiscard]] std::string GetLastErrorMsg();
57
58#define DECLARE_ENUM_FLAG_OPERATORS(type) \
59 [[nodiscard]] 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 [[nodiscard]] 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 [[nodiscard]] constexpr type operator^(type a, type b) noexcept { \
68 using T = std::underlying_type_t<type>; \
69 return static_cast<type>(static_cast<T>(a) ^ static_cast<T>(b)); \
70 } \
71 constexpr type& operator|=(type& a, type b) noexcept { \
72 a = a | b; \
73 return a; \
74 } \
75 constexpr type& operator&=(type& a, type b) noexcept { \
76 a = a & b; \
77 return a; \
78 } \
79 constexpr type& operator^=(type& a, type b) noexcept { \
80 a = a ^ b; \
81 return a; \
82 } \
83 [[nodiscard]] constexpr type operator~(type key) noexcept { \
84 using T = std::underlying_type_t<type>; \
85 return static_cast<type>(~static_cast<T>(key)); \
86 } \
87 [[nodiscard]] constexpr bool True(type key) noexcept { \
88 using T = std::underlying_type_t<type>; \
89 return static_cast<T>(key) != 0; \
90 } \
91 [[nodiscard]] constexpr bool False(type key) noexcept { \
92 using T = std::underlying_type_t<type>; \
93 return static_cast<T>(key) == 0; \
94 }
57 95
58namespace Common { 96namespace Common {
59 97
60constexpr u32 MakeMagic(char a, char b, char c, char d) { 98[[nodiscard]] constexpr u32 MakeMagic(char a, char b, char c, char d) {
61 return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; 99 return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24;
62} 100}
63 101