HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
win32_error_intf.hpp
1// Copyright Take Vos 2024.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../macros.hpp"
8#include <Windows.h>
9#include <errhandlingapi.h>
10#include <system_error>
11
12hi_export_module(hikogui.win32 : win32_error_intf);
13
14hi_export namespace hi { inline namespace v1 {
15
16enum class win32_error : uint32_t {
17 success = ERROR_SUCCESS,
18 file_not_found = ERROR_FILE_NOT_FOUND,
19 more_data = ERROR_MORE_DATA,
20 invalid_data = ERROR_INVALID_DATA,
21 insufficient_buffer = ERROR_INSUFFICIENT_BUFFER,
22 status_pending = STATUS_PENDING,
23 not_supported = ERROR_NOT_SUPPORTED,
24 invalid_parameter = ERROR_INVALID_PARAMETER,
25};
26
27}} // namespace hi::v1
28
29hi_export template<>
30struct std::is_error_code_enum<hi::win32_error> : std::true_type {};
31
32hi_export namespace hi { inline namespace v1 {
33
35 char const *name() const noexcept override
36 {
37 return "win32";
38 }
39
40 std::string message(int code) const override;
41
42 bool equivalent(int code, std::error_condition const & condition) const noexcept override
43 {
44 switch (static_cast<hi::win32_error>(code)) {
45 case hi::win32_error::file_not_found:
46 return condition == std::errc::no_such_file_or_directory;
47 case hi::win32_error::more_data:
48 return condition == std::errc::message_size;
49 case hi::win32_error::invalid_data:
50 return condition == std::errc::bad_message;
51 case hi::win32_error::status_pending:
52 return condition == std::errc::interrupted;
53 case hi::win32_error::insufficient_buffer:
54 return condition == std::errc::no_buffer_space;
55 case hi::win32_error::not_supported:
56 return condition == std::errc::not_supported;
57 case hi::win32_error::invalid_parameter:
58 return condition == std::errc::invalid_argument;
59 default:
60 return false;
61 };
62 }
63};
64
65inline auto global_win32_error_category = win32_error_category{};
66
67[[nodiscard]] inline std::error_code make_error_code(win32_error code) noexcept
68{
69 return {static_cast<int>(code), global_win32_error_category};
70}
71
72[[nodiscard]] inline win32_error win32_GetLastError() noexcept
73{
74 return static_cast<win32_error>(::GetLastError());
75}
76
77}}
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition win32_error_intf.hpp:34