Core/Flags: Rename EnableFlagsOperators to EnumAsFlags

This commit is contained in:
Lynix
2016-12-12 15:07:16 +01:00
parent bc073de94a
commit e9061a6cf8
5 changed files with 28 additions and 25 deletions

View File

@@ -91,9 +91,10 @@ namespace Nz
};
template<>
struct EnableFlagsOperators<OpenMode>
struct EnumAsFlags<OpenMode>
{
static constexpr bool value = true;
static constexpr int max = OpenMode_Max;
};
using OpenModeFlags = Flags<OpenMode>;
@@ -194,9 +195,10 @@ namespace Nz
};
template<>
struct EnableFlagsOperators<StreamOption>
struct EnumAsFlags<StreamOption>
{
static constexpr bool value = true;
static constexpr int max = StreamOption_Max;
};
using StreamOptionFlags = Flags<StreamOption>;

View File

@@ -12,6 +12,13 @@
namespace Nz
{
// From: https://www.justsoftwaresolutions.co.uk/cplusplus/using-enum-classes-as-bitfields.html
template<typename E>
struct EnumAsFlags
{
static constexpr bool value = false;
};
template<typename E>
class Flags
{
@@ -40,19 +47,13 @@ namespace Nz
private:
UInt32 m_value;
};
// From: https://www.justsoftwaresolutions.co.uk/cplusplus/using-enum-classes-as-bitfields.html
template<typename E>
struct EnableFlagsOperators
{
static constexpr bool value = false;
};
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator~(E lhs);
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator|(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator&(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator^(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs);
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator|(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator&(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator^(E lhs, E rhs);
}
#include <Nazara/Core/Flags.inl>

View File

@@ -219,7 +219,7 @@ namespace Nz
* Returns a Flags object with all state enabled except for the enum one.
*/
template<typename E>
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator~(E lhs)
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs)
{
return ~Flags<E>(lhs);
}
@@ -234,7 +234,7 @@ namespace Nz
* Returns a Flags object with combined states from the two enumeration values.
*/
template<typename E>
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator|(E lhs, E rhs)
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator|(E lhs, E rhs)
{
return Flags<E>(lhs) | rhs;
}
@@ -250,7 +250,7 @@ namespace Nz
* In this case, only one flag will be enabled if both enumeration values are the same.
*/
template<typename E>
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator&(E lhs, E rhs)
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator&(E lhs, E rhs)
{
return Flags<E>(lhs) & rhs;
}
@@ -266,7 +266,7 @@ namespace Nz
* In this case, two flags will be enabled if both the enumeration values are different.
*/
template<typename E>
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator^(E lhs, E rhs)
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator^(E lhs, E rhs)
{
return Flags<E>(lhs) ^ rhs;
}