diff options
Diffstat (limited to 'src/common/common_funcs.h')
-rw-r--r-- | src/common/common_funcs.h | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 052254678d..367b6bf6e7 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -53,11 +53,49 @@ __declspec(dllimport) void __stdcall DebugBreak(void); // Call directly after the command or use the error num. // This function might change the error code. // Defined in Misc.cpp. -std::string GetLastErrorMsg(); +[[nodiscard]] std::string GetLastErrorMsg(); + +#define DECLARE_ENUM_FLAG_OPERATORS(type) \ + [[nodiscard]] constexpr type operator|(type a, type b) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \ + } \ + [[nodiscard]] constexpr type operator&(type a, type b) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ + } \ + [[nodiscard]] constexpr type operator^(type a, type b) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<type>(static_cast<T>(a) ^ static_cast<T>(b)); \ + } \ + constexpr type& operator|=(type& a, type b) noexcept { \ + a = a | b; \ + return a; \ + } \ + constexpr type& operator&=(type& a, type b) noexcept { \ + a = a & b; \ + return a; \ + } \ + constexpr type& operator^=(type& a, type b) noexcept { \ + a = a ^ b; \ + return a; \ + } \ + [[nodiscard]] constexpr type operator~(type key) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<type>(~static_cast<T>(key)); \ + } \ + [[nodiscard]] constexpr bool True(type key) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<T>(key) != 0; \ + } \ + [[nodiscard]] constexpr bool False(type key) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<T>(key) == 0; \ + } namespace Common { -constexpr u32 MakeMagic(char a, char b, char c, char d) { +[[nodiscard]] constexpr u32 MakeMagic(char a, char b, char c, char d) { return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; } |