10#define XR_TO_STR(_arg) #_arg
11#define DEF2STR(_arg) XR_TO_STR(_arg)
17#define UNUSED(_x) ((void)(_x))
20#ifndef LIBXR_SINGLE_CORE
21#define LIBXR_SINGLE_CORE 0
25#define LIBXR_NOINLINE __declspec(noinline)
26#define LIBXR_PACKED_BEGIN __pragma(pack(push, 1))
27#define LIBXR_PACKED_END __pragma(pack(pop))
29#elif defined(__clang__) || defined(__GNUC__)
30#define LIBXR_NOINLINE __attribute__((noinline))
31#define LIBXR_PACKED_BEGIN _Pragma("pack(push, 1)")
32#define LIBXR_PACKED_END _Pragma("pack(pop)")
33#define LIBXR_PACKED __attribute__((packed))
35#warning "LibXR compiler compatibility macros fallback to no-op on unknown compiler"
37#define LIBXR_PACKED_BEGIN
38#define LIBXR_PACKED_END
45inline constexpr double PI = 3.14159265358979323846;
75template <
typename OwnerType,
typename MemberType>
82template <
typename LeftType,
typename RightType>
84 requires(
const LeftType& left,
const RightType& right) {
85 { left < right } -> std::convertible_to<bool>;
86 { left > right } -> std::convertible_to<bool>;
96template <
typename OwnerType,
typename MemberType>
98[[nodiscard]]
inline size_t OffsetOf(MemberType OwnerType::* member)
noexcept
100 return reinterpret_cast<size_t>(
101 &(
reinterpret_cast<const volatile OwnerType*
>(0)->*member));
112template <
typename OwnerType,
typename MemberType>
113 requires MemberObjectPointer<OwnerType, MemberType>
115 MemberType OwnerType::* member)
noexcept
117 return reinterpret_cast<OwnerType*
>(
reinterpret_cast<std::byte*
>(ptr) -
121template <
typename OwnerType,
typename MemberType>
122 requires MemberObjectPointer<OwnerType, MemberType>
123[[nodiscard]]
inline const OwnerType*
ContainerOf(
const MemberType* ptr,
124 MemberType OwnerType::* member)
noexcept
126 return reinterpret_cast<const OwnerType*
>(
reinterpret_cast<const std::byte*
>(ptr) -
182 size_t size)
noexcept
187 return limit == size;
189 return limit >= size;
191 return limit <= size;
203#ifdef DEV_ASSERT_FROM_CALLBACK
204#undef DEV_ASSERT_FROM_CALLBACK
211#ifdef REQUIRE_FROM_CALLBACK
212#undef REQUIRE_FROM_CALLBACK
219#ifdef ASSERT_FROM_CALLBACK
220#undef ASSERT_FROM_CALLBACK
228#ifdef LIBXR_DEBUG_BUILD
234 libxr_fatal_error(__FILE__, __LINE__, false); \
245#define ASSERT_FROM_CALLBACK(arg, in_isr) \
250 libxr_fatal_error(__FILE__, __LINE__, (in_isr)); \
254#define ASSERT(arg) (void(arg), (void)0)
255#define ASSERT_FROM_CALLBACK(arg, in_isr) \
268#ifdef LIBXR_DEV_ASSERT_BUILD
269#define DEV_ASSERT(arg) \
274 libxr_fatal_error(__FILE__, __LINE__, false); \
285#define DEV_ASSERT_FROM_CALLBACK(arg, in_isr) \
290 libxr_fatal_error(__FILE__, __LINE__, (in_isr)); \
294#define DEV_ASSERT(arg) (void(arg), (void)0)
295#define DEV_ASSERT_FROM_CALLBACK(arg, in_isr) \
308#define REQUIRE(arg) \
313 libxr_fatal_error(__FILE__, __LINE__, false); \
324#define REQUIRE_FROM_CALLBACK(arg, in_isr) \
329 libxr_fatal_error(__FILE__, __LINE__, (in_isr)); \
340extern "C" void libxr_fatal_error(
const char* file, uint32_t line,
bool in_isr);
353template <
typename LeftType,
typename RightType>
354 requires CommonOrdered<LeftType, RightType>
355constexpr auto max(LeftType a, RightType b) -> std::common_type_t<LeftType, RightType>
357 return (a > b) ? a : b;
369template <
typename LeftType,
typename RightType>
370 requires CommonOrdered<LeftType, RightType>
371constexpr auto min(LeftType a, RightType b) -> std::common_type_t<LeftType, RightType>
373 return (a < b) ? a : b;
@ SIZE_ERR
尺寸错误 | Size error
@ CHECK_ERR
校验错误 | Check error
@ INIT_ERR
初始化错误 | Initialization error
@ OUT_OF_RANGE
超出范围 | Out of range
@ STATE_ERR
状态错误 | State error
@ NOT_FOUND
未找到 | Not found
@ NO_MEM
内存不足 | Insufficient memory
@ NO_RESPONSE
无响应 | No response
@ PTR_NULL
空指针 | Null pointer
@ NO_BUFF
缓冲区不足 | Insufficient buffer
@ NOT_SUPPORT
不支持 | Not supported
@ FAILED
操作失败 | Operation failed
@ OK
操作成功 | Operation successful
@ ARG_ERR
参数错误 | Argument error
constexpr double STANDARD_GRAVITY
标准重力加速度(m/s²) / Standard gravitational acceleration (m/s²)
@ LESS
尺寸必须小于等于 | Size must be less than or equal
@ EQUAL
尺寸必须相等 | Size must be equal
@ NONE
无限制 | No restriction
@ MORE
尺寸必须大于等于 | Size must be greater than or equal
constexpr size_t CONCURRENCY_ALIGNMENT
并发结构对齐粒度(用于降低多核伪共享) / Alignment policy used by concurrency-oriented structures
constexpr auto min(LeftType a, RightType b) -> std::common_type_t< LeftType, RightType >
计算两个数的最小值
constexpr size_t CACHE_LINE_SIZE
兼容旧代码的缓存行别名 / Backward-compatible cache-line alias for existing code
constexpr double TWO_PI
2PI 常量 / 2PI constant
constexpr size_t HW_CACHE_LINE_SIZE
真实硬件缓存行大小(用于 DMA / cache coherency) / Hardware cache-line size used for DMA/cache-coherency boundarie...
constexpr bool SizeLimitCheck(SizeLimitMode mode, size_t limit, size_t size) noexcept
尺寸约束的纯判断函数
size_t OffsetOf(MemberType OwnerType::*member) noexcept
计算成员在宿主对象中的偏移量
OwnerType * ContainerOf(MemberType *ptr, MemberType OwnerType::*member) noexcept
通过成员指针恢复其所属对象指针
constexpr size_t ALIGN_SIZE
平台自然对齐大小 / Native platform alignment size
constexpr auto max(LeftType a, RightType b) -> std::common_type_t< LeftType, RightType >
计算两个数的最大值
constexpr double PI
PI 常量 / PI constant.