diff options
author | crupest <crupest@outlook.com> | 2023-10-15 00:07:24 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-10-15 00:07:24 +0800 |
commit | c34035b9491c201eca226a2e065fd9753d706433 (patch) | |
tree | 5a4e422990621cafbb1dca72f03db32ace24c677 | |
parent | 856df14d749014f11a583ade2fee988b076754cc (diff) | |
download | cru-c34035b9491c201eca226a2e065fd9753d706433.tar.gz cru-c34035b9491c201eca226a2e065fd9753d706433.tar.bz2 cru-c34035b9491c201eca226a2e065fd9753d706433.zip |
Improve bitmask.
Bool conversion -> explicit
std::hash support
-rw-r--r-- | include/cru/common/Bitmask.h | 15 | ||||
-rw-r--r-- | include/cru/ui/helper/ShortcutHub.h | 8 | ||||
-rw-r--r-- | test/common/platform/unix/UnixFileStreamTest.cpp | 2 |
3 files changed, 17 insertions, 8 deletions
diff --git a/include/cru/common/Bitmask.h b/include/cru/common/Bitmask.h index bd6a8309..b1e8495e 100644 --- a/include/cru/common/Bitmask.h +++ b/include/cru/common/Bitmask.h @@ -1,6 +1,8 @@ #pragma once #include "Base.h" +#include <functional> + namespace cru { template <typename Tag, typename TUnderlying = unsigned> struct Bitmask final { @@ -35,8 +37,19 @@ struct Bitmask final { bool operator!=(Bitmask rhs) const { return this->value != rhs.value; } explicit operator TUnderlying() const { return value; } - operator bool() const { return value != 0; } + explicit operator bool() const { return value != 0; } TUnderlying value; }; } // namespace cru + +namespace std { +template <typename Tag, typename TUnderlying> +struct hash<cru::Bitmask<Tag, TUnderlying>> { + using Bitmask = cru::Bitmask<Tag, TUnderlying>; + + std::size_t operator()(Bitmask bitmask) const { + return std::hash<TUnderlying>{}(bitmask.value); + } +}; +} // namespace std diff --git a/include/cru/ui/helper/ShortcutHub.h b/include/cru/ui/helper/ShortcutHub.h index 28c41234..fe3b2a72 100644 --- a/include/cru/ui/helper/ShortcutHub.h +++ b/include/cru/ui/helper/ShortcutHub.h @@ -1,18 +1,14 @@ #pragma once #include "../Base.h" -#include "../events/UiEvents.h" +#include "../events/KeyEventArgs.h" #include "cru/common/Base.h" #include "cru/common/Event.h" #include "cru/platform/gui/Keyboard.h" #include <cstddef> #include <functional> -#include <memory> #include <optional> -#include <string> -#include <string_view> -#include <type_traits> #include <unordered_map> #include <vector> @@ -74,7 +70,7 @@ struct hash<cru::ui::helper::ShortcutKeyBind> { std::size_t operator()(const cru::ui::helper::ShortcutKeyBind& value) const { std::size_t result = 0; cru::hash_combine(result, static_cast<int>(value.GetKey())); - cru::hash_combine(result, static_cast<int>(value.GetModifier())); + cru::hash_combine(result, value.GetModifier()); return result; } }; diff --git a/test/common/platform/unix/UnixFileStreamTest.cpp b/test/common/platform/unix/UnixFileStreamTest.cpp index c27e485b..d5aebeeb 100644 --- a/test/common/platform/unix/UnixFileStreamTest.cpp +++ b/test/common/platform/unix/UnixFileStreamTest.cpp @@ -20,7 +20,7 @@ TEST_CASE("UnixFileStream Work", "[stream]") { file.Write("abc", 3); file.Close(); - UnixFileStream file2(temp_file_path.c_str(), OpenFileFlags::Read); + UnixFileStream file2(temp_file_path.c_str(), O_RDONLY); auto buffer = std::make_unique<std::byte[]>(3); file2.Read(buffer.get(), 3); REQUIRE(std::string_view(reinterpret_cast<const char*>(buffer.get()), 3) == |