Core/Flags: Allow explicit operator conversion to any integer type of the same size (or greater size) than the internal size
This commit is contained in:
parent
1b80ad5f02
commit
54faabcc33
|
|
@ -17,7 +17,10 @@ Nazara Engine:
|
||||||
- Fix BoundingVolume::Lerp() with Extend_Null
|
- Fix BoundingVolume::Lerp() with Extend_Null
|
||||||
- Simplification of methods Matrix4::SetRotation() and Quaternion::MakeRotationBetween()
|
- Simplification of methods Matrix4::SetRotation() and Quaternion::MakeRotationBetween()
|
||||||
- Fix mouve moved event generated on X11 platform when doing Mouse::SetPosition()
|
- Fix mouve moved event generated on X11 platform when doing Mouse::SetPosition()
|
||||||
- ⚠️ Reworked Flags class, replaced EnumAsFlags<E>::value by IsEnumFlag<E>::value, EnumAsFlags<E> 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)
|
- Fix String movement constructor, which was leaving a null shared string (which was not reusable)
|
||||||
|
|
||||||
Nazara Development Kit:
|
Nazara Development Kit:
|
||||||
|
|
|
||||||
|
|
@ -39,17 +39,17 @@ namespace Nz
|
||||||
|
|
||||||
static constexpr std::size_t MaxValue = static_cast<std::size_t>(EnumAsFlags<E>::max);
|
static constexpr std::size_t MaxValue = static_cast<std::size_t>(EnumAsFlags<E>::max);
|
||||||
|
|
||||||
using BitField16 = typename std::conditional<(MaxValue > 8), UInt16, UInt8>::type;
|
using BitField16 = std::conditional_t<(MaxValue > 8), UInt16, UInt8>;
|
||||||
using BitField32 = typename std::conditional<(MaxValue > 16), UInt32, BitField16>::type;
|
using BitField32 = std::conditional_t<(MaxValue > 16), UInt32, BitField16>;
|
||||||
|
|
||||||
public:
|
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(BitField value = 0);
|
||||||
constexpr Flags(E enumVal);
|
constexpr Flags(E enumVal);
|
||||||
|
|
||||||
explicit constexpr operator bool() const;
|
explicit constexpr operator bool() const;
|
||||||
explicit constexpr operator BitField() const;
|
template<typename T, typename = std::enable_if_t<std::is_integral<T>::value && sizeof(T) >= sizeof(BitField)>> explicit constexpr operator T() const;
|
||||||
|
|
||||||
constexpr Flags operator~() const;
|
constexpr Flags operator~() const;
|
||||||
constexpr Flags operator&(const Flags& rhs) const;
|
constexpr Flags operator&(const Flags& rhs) const;
|
||||||
|
|
|
||||||
|
|
@ -52,13 +52,14 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Converts to a bitfield
|
* \brief Converts to an integer
|
||||||
* \return Enabled flags as a bitfield.
|
* \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<typename E>
|
template<typename E>
|
||||||
constexpr Flags<E>::operator BitField() const
|
template<typename T, typename>
|
||||||
|
constexpr Flags<E>::operator T() const
|
||||||
{
|
{
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue