From eca0d90d98b629329b4d55c6a25c8ae00f3c18e3 Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Fri, 17 Jan 2025 16:30:16 +0800 Subject: [PATCH] feat(miscellaneous): add enum class bitwise operation macro tools --- .../Source/Public/Miscellaneous/BitwiseEnum.h | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Redcraft.Utility/Source/Public/Miscellaneous/BitwiseEnum.h diff --git a/Redcraft.Utility/Source/Public/Miscellaneous/BitwiseEnum.h b/Redcraft.Utility/Source/Public/Miscellaneous/BitwiseEnum.h new file mode 100644 index 0000000..7d6a072 --- /dev/null +++ b/Redcraft.Utility/Source/Public/Miscellaneous/BitwiseEnum.h @@ -0,0 +1,32 @@ +#pragma once + +#include "CoreTypes.h" +#include "TypeTraits/TypeTraits.h" + +NAMESPACE_REDCRAFT_BEGIN +NAMESPACE_MODULE_BEGIN(Redcraft) +NAMESPACE_MODULE_BEGIN(Utility) + +#define ENABLE_ENUM_CLASS_BITWISE_OPERATIONS(Enum) \ + NODISCARD FORCEINLINE constexpr Enum operator| (Enum LHS, Enum RHS) { return static_cast(static_cast>(LHS) | static_cast>(RHS)); } \ + NODISCARD FORCEINLINE constexpr Enum operator& (Enum LHS, Enum RHS) { return static_cast(static_cast>(LHS) & static_cast>(RHS)); } \ + NODISCARD FORCEINLINE constexpr Enum operator^ (Enum LHS, Enum RHS) { return static_cast(static_cast>(LHS) ^ static_cast>(RHS)); } \ + FORCEINLINE constexpr Enum& operator|=(Enum& LHS, Enum RHS) { LHS = LHS | RHS; return LHS; } \ + FORCEINLINE constexpr Enum& operator&=(Enum& LHS, Enum RHS) { LHS = LHS & RHS; return LHS; } \ + FORCEINLINE constexpr Enum& operator^=(Enum& LHS, Enum RHS) { LHS = LHS ^ RHS; return LHS; } \ + NODISCARD FORCEINLINE constexpr bool operator! (Enum E ) { return !static_cast>(E); } \ + NODISCARD FORCEINLINE constexpr Enum operator~ (Enum E ) { return static_cast(~static_cast>(E)); } + +#define FRIEND_ENUM_CLASS_BITWISE_OPERATIONS(Enum) \ + friend constexpr Enum operator| (Enum , Enum); \ + friend constexpr Enum operator& (Enum , Enum); \ + friend constexpr Enum operator^ (Enum , Enum); \ + friend constexpr Enum& operator|=(Enum&, Enum); \ + friend constexpr Enum& operator&=(Enum&, Enum); \ + friend constexpr Enum& operator^=(Enum&, Enum); \ + friend constexpr bool operator! (Enum ); \ + friend constexpr Enum operator~ (Enum ); + +NAMESPACE_MODULE_END(Utility) +NAMESPACE_MODULE_END(Redcraft) +NAMESPACE_REDCRAFT_END