From cdacc014f3c269f07c166499e0618bd879b412a5 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 20 Nov 2015 15:11:23 -1000 Subject: [PATCH] Added handy bitwise enum enabler macro --- include/Athena/Global.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/Athena/Global.hpp b/include/Athena/Global.hpp index 304f189..322fb0f 100644 --- a/include/Athena/Global.hpp +++ b/include/Athena/Global.hpp @@ -69,6 +69,35 @@ typedef struct stat64 stat64_t; #define ROUND_UP_32(val) (((val) + 31) & ~31) #define ROUND_UP_16(val) (((val) + 15) & ~15) +#define ENABLE_BITWISE_ENUM(type)\ +inline type operator|(type a, type b)\ +{\ + using T = std::underlying_type_t;\ + return type(static_cast(a) | static_cast(b));\ +}\ +inline type operator&(type a, type b)\ +{\ + using T = std::underlying_type_t;\ + return type(static_cast(a) & static_cast(b));\ +}\ +inline type& operator|=(type& a, const type& b)\ +{\ + using T = std::underlying_type_t;\ + a = type(static_cast(a) | static_cast(b));\ + return a;\ +}\ +inline type& operator&=(type& a, const type& b)\ +{\ + using T = std::underlying_type_t;\ + a = type(static_cast(a) & static_cast(b));\ + return a;\ +}\ +inline type operator~(const type& key)\ +{\ + using T = std::underlying_type_t;\ + return type(~static_cast(key));\ +} + namespace Athena { namespace error