PCAL9555 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
pcal9555_detail.hpp
Go to the documentation of this file.
1
10#ifndef PCAL9555_DETAIL_HPP
11#define PCAL9555_DETAIL_HPP
12
13#include <concepts>
14#include <cstdint>
15#include <type_traits>
16
17namespace pcal9555::detail {
18
32template <typename Port, typename Sig>
33 requires std::is_class_v<Port> && std::is_function_v<Sig>
34struct ExactHook;
35
37template <typename Port, typename R, typename... Args>
38 requires std::is_class_v<Port>
39struct ExactHook<Port, R(Args...) noexcept> {
41 static void Take(R (Port::*hook)(Args...) noexcept) noexcept;
43 static void Take(R (Port::*hook)(Args...) const noexcept) noexcept;
44};
45
47template <typename T>
48concept ClassType = std::is_class_v<T>;
49
52template <ClassType>
53inline constexpr bool kAlwaysFalse = false;
54
56template <typename E>
57concept Enumeration = std::is_enum_v<E>;
58
63template <Enumeration E>
64[[nodiscard]] constexpr std::underlying_type_t<E> ToUnderlying(E e) noexcept {
65 return static_cast<std::underlying_type_t<E>>(e);
66}
67
73template <Enumeration E>
74[[nodiscard]] constexpr bool IsEnumerator(E e, E last) noexcept {
75 return static_cast<uint32_t>(ToUnderlying(e)) <= static_cast<uint32_t>(ToUnderlying(last));
76}
77
80inline void LiteralOutOfRange() noexcept {}
81
86consteval uint8_t operator""_u8(unsigned long long value) noexcept {
87 if (value > 0xFFULL) {
88 LiteralOutOfRange();
89 }
90 return static_cast<uint8_t>(value);
91}
92
94consteval uint16_t operator""_u16(unsigned long long value) noexcept {
95 if (value > 0xFFFFULL) {
96 LiteralOutOfRange();
97 }
98 return static_cast<uint16_t>(value);
99}
100
105consteval uint32_t operator""_u32(unsigned long long value) noexcept {
106 if (value > 0xFFFF'FFFFULL) {
107 LiteralOutOfRange();
108 }
109 return static_cast<uint32_t>(value);
110}
111
112} // namespace pcal9555::detail
113
114#endif // PCAL9555_DETAIL_HPP