diff --git a/ChangeLog.md b/ChangeLog.md index f252271fe..031898cee 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -17,7 +17,10 @@ Nazara Engine: - Fix BoundingVolume::Lerp() with Extend_Null - Simplification of methods Matrix4::SetRotation() and Quaternion::MakeRotationBetween() - Fix mouve moved event generated on X11 platform when doing Mouse::SetPosition() -- ⚠️ Reworked Flags class, replaced EnumAsFlags::value by IsEnumFlag::value, EnumAsFlags no longer need to contains a `value` field. The `max` field can also be of the same type as the enum. +- EnumAsFlags specialization no longer require a `value` field to enable flags operators +- EnumAsFlags specialization `max` field can be of the same type as the enum +- Flags class now use an UInt8 or UInt16 to store the value if possible. +- Flags class is now explicitly convertible to any integer type of the same size (or greater size) than the internal size. - Fix String movement constructor, which was leaving a null shared string (which was not reusable) Nazara Development Kit: diff --git a/include/Nazara/Core/Flags.hpp b/include/Nazara/Core/Flags.hpp index b2f4ca864..3e9bbe3e8 100644 --- a/include/Nazara/Core/Flags.hpp +++ b/include/Nazara/Core/Flags.hpp @@ -39,17 +39,17 @@ namespace Nz static constexpr std::size_t MaxValue = static_cast(EnumAsFlags::max); - using BitField16 = typename std::conditional<(MaxValue > 8), UInt16, UInt8>::type; - using BitField32 = typename std::conditional<(MaxValue > 16), UInt32, BitField16>::type; + using BitField16 = std::conditional_t<(MaxValue > 8), UInt16, UInt8>; + using BitField32 = std::conditional_t<(MaxValue > 16), UInt32, BitField16>; public: - using BitField = typename std::conditional<(MaxValue > 32), UInt64, BitField32>::type; + using BitField = std::conditional_t<(MaxValue > 32), UInt64, BitField32>; constexpr Flags(BitField value = 0); constexpr Flags(E enumVal); explicit constexpr operator bool() const; - explicit constexpr operator BitField() const; + template::value && sizeof(T) >= sizeof(BitField)>> explicit constexpr operator T() const; constexpr Flags operator~() const; constexpr Flags operator&(const Flags& rhs) const; diff --git a/include/Nazara/Core/Flags.inl b/include/Nazara/Core/Flags.inl index 6c24c2883..d69170c51 100644 --- a/include/Nazara/Core/Flags.inl +++ b/include/Nazara/Core/Flags.inl @@ -52,13 +52,14 @@ namespace Nz } /*! - * \brief Converts to a bitfield - * \return Enabled flags as a bitfield. + * \brief Converts to an integer + * \return Enabled flags as a integer * - * This will convert to a bitfield value. + * This will only works if the integer type is large enough to store all flags states */ template - constexpr Flags::operator BitField() const + template + constexpr Flags::operator T() const { return m_value; }