diff --git a/ChangeLog.md b/ChangeLog.md index d29c5fbb9..28800ec0e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -100,6 +100,7 @@ Nazara Engine: - SubMesh class now has a OnSubMeshInvalidateAABB signal, triggered when a new AABB is set to the submesh - Mesh class now has a OnMeshInvalidateAABB signal, triggered when a mesh invalidates its AABB, which is also submesh updates its AABB - Model now invalidate properly their bounding volume when their mesh AABB is updated +- Added operator&/|/^ taking an enumeration value and a Flags object using the same enumeration type. Nazara Development Kit: - Added ImageWidget (#139) diff --git a/include/Nazara/Core/Flags.hpp b/include/Nazara/Core/Flags.hpp index c30959446..92c97de9e 100644 --- a/include/Nazara/Core/Flags.hpp +++ b/include/Nazara/Core/Flags.hpp @@ -73,12 +73,16 @@ namespace Nz BitField m_value; }; + template constexpr Flags operator&(E lhs, Flags rhs); + template constexpr Flags operator|(E lhs, Flags rhs); + template constexpr Flags operator^(E lhs, Flags rhs); + // Little hack to have them in both Nz and global scope namespace FlagsOperators { template constexpr std::enable_if_t::value, Flags> operator~(E lhs); - template constexpr std::enable_if_t::value, Flags> operator|(E lhs, E rhs); template constexpr std::enable_if_t::value, Flags> operator&(E lhs, E rhs); + template constexpr std::enable_if_t::value, Flags> operator|(E lhs, E rhs); template constexpr std::enable_if_t::value, Flags> operator^(E lhs, E rhs); } diff --git a/include/Nazara/Core/Flags.inl b/include/Nazara/Core/Flags.inl index 36bb32ea0..2b57a59a8 100644 --- a/include/Nazara/Core/Flags.inl +++ b/include/Nazara/Core/Flags.inl @@ -221,6 +221,51 @@ namespace Nz return 1U << static_cast(enumValue); } + /*! + * \brief Compare flag states + * \return Compared flags + * + * This will returns a copy of the Flags object compared with the enum state. + * + * \param lhs Enum to compare with flags. + * \param rhs Flags object. + */ + template + constexpr Flags operator&(E lhs, Flags rhs) + { + return rhs & lhs; + } + + /*! + * \brief Combine flag states + * \return Combined flags + * + * This will returns a copy of the Flags object combined with the enum state. + * + * \param lhs Enum to combine with flags. + * \param rhs Flags object. + */ + template + constexpr Flags operator|(E lhs, Flags rhs) + { + return rhs | lhs; + } + + /*! + * \brief XOR flag states + * \return XORed flags + * + * This will returns a copy of the Flags object XORed with the enum state. + * + * \param lhs Enum to XOR with flags. + * \param rhs Flags object. + */ + template + constexpr Flags operator^(E lhs, Flags rhs) + { + return rhs ^ lhs; + } + namespace FlagsOperators { @@ -238,21 +283,6 @@ namespace Nz return ~Flags(lhs); } - /*! - * \brief Override binary OR operator on enum to turns into a Flags object. - * \return A Flags object with combined enum states. - * - * \param lhs First enumeration value to combine. - * \param rhs Second enumeration value to combine. - * - * Returns a Flags object with combined states from the two enumeration values. - */ - template - constexpr std::enable_if_t::value, Flags> operator|(E lhs, E rhs) - { - return Flags(lhs) | rhs; - } - /*! * \brief Override binary AND operator on enum to turns into a Flags object. * \return A Flags object with compare enum states. @@ -269,6 +299,21 @@ namespace Nz return Flags(lhs) & rhs; } + /*! + * \brief Override binary OR operator on enum to turns into a Flags object. + * \return A Flags object with combined enum states. + * + * \param lhs First enumeration value to combine. + * \param rhs Second enumeration value to combine. + * + * Returns a Flags object with combined states from the two enumeration values. + */ + template + constexpr std::enable_if_t::value, Flags> operator|(E lhs, E rhs) + { + return Flags(lhs) | rhs; + } + /*! * \brief Override binary XOR operator on enum to turns into a Flags object. * \return A Flags object with XORed enum states.