ResourceTraitsWin32.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include <windows.h>
  3. struct GenericHandleTraits {
  4. using HandleType = HANDLE;
  5. static inline const HandleType InvalidValue = NULL;
  6. [[nodiscard]]
  7. static bool IsValid(const HandleType& Handle) noexcept {
  8. return Handle != InvalidValue;
  9. }
  10. static void Releasor(const HandleType& Handle) noexcept {
  11. CloseHandle(Handle);
  12. }
  13. };
  14. struct FileHandleTraits {
  15. using HandleType = HANDLE;
  16. static inline const HandleType InvalidValue = INVALID_HANDLE_VALUE;
  17. [[nodiscard]]
  18. static bool IsValid(const HandleType& Handle) noexcept {
  19. return Handle != InvalidValue;
  20. }
  21. static void Releasor(const HandleType& Handle) noexcept {
  22. CloseHandle(Handle);
  23. }
  24. };
  25. struct MapViewHandleTraits {
  26. using HandleType = PVOID;
  27. static inline const HandleType InvalidValue = NULL;
  28. [[nodiscard]]
  29. static bool IsValid(const HandleType& Handle) noexcept {
  30. return Handle != InvalidValue;
  31. }
  32. static void Releasor(const HandleType& Handle) noexcept {
  33. UnmapViewOfFile(Handle);
  34. }
  35. };