diff --git a/ChangeLog.md b/ChangeLog.md index 031898cee..50300ff63 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -22,6 +22,7 @@ Nazara Engine: - 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) +- Add Flags::Test method, in order to test one or multiple flags at once. Nazara Development Kit: - Added ImageWidget (#139) diff --git a/include/Nazara/Core/Flags.hpp b/include/Nazara/Core/Flags.hpp index 3e9bbe3e8..86844b806 100644 --- a/include/Nazara/Core/Flags.hpp +++ b/include/Nazara/Core/Flags.hpp @@ -48,6 +48,8 @@ namespace Nz constexpr Flags(BitField value = 0); constexpr Flags(E enumVal); + constexpr bool Test(const Flags& flags) const; + explicit constexpr operator bool() const; template::value && sizeof(T) >= sizeof(BitField)>> explicit constexpr operator T() const; diff --git a/include/Nazara/Core/Flags.inl b/include/Nazara/Core/Flags.inl index d69170c51..36bb32ea0 100644 --- a/include/Nazara/Core/Flags.inl +++ b/include/Nazara/Core/Flags.inl @@ -40,7 +40,17 @@ namespace Nz } /*! - * \brief Tests a Flags + * \brief Tests if all flags from a Flags object are enabled + * \return True if all tested flags are enabled. + */ + template + constexpr bool Flags::Test(const Flags& flags) const + { + return (m_value & flags.m_value) == flags.m_value; + } + + /*! + * \brief Tests any flag * \return True if any flag is enabled. * * This will convert to a boolean value allowing to check if any flag is set.