HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
network_event.hpp
1// Copyright Take Vos 2022.
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 "../cast.hpp"
8#include "../assert.hpp"
9#include <array>
10#include <cstddef>
11#include <cstdint>
12#include <bit>
13
14namespace hi::inline v1 {
15
16enum class network_event : uint16_t {
17 none = 0,
18 read = 0x0001,
19 write = 0x0002,
20 close = 0x0004,
21 connect = 0x0008,
22 accept = 0x0010,
23 out_of_band = 0x0020,
24 qos = 0x0040,
25 group_qos = 0x0080,
26 address_list_change = 0x0100,
27 routing_interface_changed = 0x0200
28};
29
30[[nodiscard]] constexpr network_event operator|(network_event const& lhs, network_event const& rhs) noexcept
31{
32 return static_cast<network_event>(to_underlying(lhs) | to_underlying(rhs));
33}
34
35[[nodiscard]] constexpr network_event operator&(network_event const& lhs, network_event const& rhs) noexcept
36{
37 return static_cast<network_event>(to_underlying(lhs) & to_underlying(rhs));
38}
39
40constexpr network_event& operator|=(network_event& lhs, network_event const& rhs) noexcept
41{
42 return lhs = lhs | rhs;
43}
44
45[[nodiscard]] constexpr bool any(network_event const& rhs) noexcept
46{
47 return static_cast<bool>(to_underlying(rhs));
48}
49
52[[nodiscard]] constexpr size_t bit(network_event const& rhs) noexcept
53{
54 hi_axiom(std::popcount(to_underlying(rhs)) == 1);
55 return std::countr_zero(to_underlying(rhs));
56}
57
58enum class network_error : uint8_t {
59 success = 0,
60 af_not_supported,
61 connection_refused,
62 network_unreachable,
63 no_buffers,
64 timeout,
65 network_down,
66 connection_reset,
67 connection_aborted
68};
69
70constexpr static size_t network_event_max = 10;
71
73public:
74 network_event events;
76
77 constexpr network_events() noexcept : events(network_event::none), errors{} {}
78};
79
80} // namespace hi::inline v1
constexpr alignment operator|(horizontal_alignment lhs, vertical_alignment rhs) noexcept
Combine vertical and horizontal alignment.
Definition alignment.hpp:200
Definition network_event.hpp:72