11#ifndef BNO08X_DETAIL_HPP
12#define BNO08X_DETAIL_HPP
19namespace bno08x::detail {
25void LiteralOutOfRange() noexcept;
33consteval std::uint8_t operator""_u8(
unsigned long long v) noexcept {
37 return static_cast<std::uint8_t
>(v);
45consteval std::uint16_t
operator""_u16(
unsigned long long v)
noexcept {
49 return static_cast<std::uint16_t
>(v);
58consteval std::uint32_t
operator""_u32(
unsigned long long v)
noexcept {
59 if (v > 0xFFFF'FFFFULL) {
62 return static_cast<std::uint32_t
>(v);
78template <
typename Port,
typename Sig>
79 requires std::is_class_v<Port> && std::is_function_v<Sig>
83template <
typename Port,
typename R,
typename... Args>
84 requires std::is_class_v<Port>
85struct ExactHook<Port, R(Args...) noexcept> {
87 static void Take(R (Port::*hook)(Args...) noexcept) noexcept;
89 static void Take(R (Port::*hook)(Args...) const noexcept) noexcept;
94concept ClassType = std::is_class_v<T>;
99inline constexpr bool kAlwaysFalse =
false;
103concept Enumeration = std::is_enum_v<E>;
109template <Enumeration E>
110[[nodiscard]]
constexpr std::underlying_type_t<E> ToUnderlying(E e)
noexcept {
111 return static_cast<std::underlying_type_t<E>
>(e);
118template <Enumeration E>
125template <Enumeration E>
126[[nodiscard]]
constexpr bool IsEnumerator(E e)
noexcept {
127 return static_cast<uint32_t
>(ToUnderlying(e)) <=
128 static_cast<uint32_t
>(ToUnderlying(EnumLast<E>::kValue));
136template <
typename Reg, u
int32_t Shift, u
int32_t W
idth>
137 requires std::unsigned_integral<Reg> && (Width > 0U) && (Width < 32U) &&
138 ((Shift + Width) <=
static_cast<uint32_t
>(std::numeric_limits<Reg>::digits))
141 static constexpr uint32_t kMax = (uint32_t{1} << Width) - 1U;
143 static constexpr Reg kMask =
static_cast<Reg
>(kMax << Shift);
146 [[nodiscard]]
static constexpr Reg Insert(Reg reg, uint32_t value)
noexcept {
147 return static_cast<Reg
>((
static_cast<uint32_t
>(reg) & ~
static_cast<uint32_t
>(kMask)) |
148 ((value & kMax) << Shift));
151 [[nodiscard]]
static constexpr uint32_t Extract(Reg reg)
noexcept {
152 return (
static_cast<uint32_t
>(reg) >> Shift) & kMax;