libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
libxr_assert.hpp
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <cstring>
6#include <utility>
7
8#include "libxr_cb.hpp"
9#include "libxr_def.hpp"
10
11namespace LibXR
12{
23class Assert
24{
25 public:
27
35 {
36 libxr_fatal_error_callback_ = std::move(cb);
37 }
38
39#ifdef LIBXR_DEBUG_BUILD
58 template <SizeLimitMode mode>
59 static void SizeLimitCheck(size_t limit, size_t size)
60 {
61 if constexpr (mode == SizeLimitMode::EQUAL)
62 {
63 ASSERT(limit == size);
64 }
65 else if constexpr (mode == SizeLimitMode::MORE)
66 {
67 ASSERT(limit <= size);
68 }
69 else if constexpr (mode == SizeLimitMode::LESS)
70 {
71 ASSERT(limit >= size);
72 }
73 }
74#else
86 template <SizeLimitMode mode>
87 static void SizeLimitCheck(size_t limit, size_t size)
88 {
89 UNUSED(limit);
90 UNUSED(size);
91 }
92#endif
93
99 static inline Callback libxr_fatal_error_callback_; // NOLINT
100};
101} // namespace LibXR
运行时错误检查的断言工具类。 Provides assertion mechanisms for runtime error checking.
static void RegisterFatalErrorCallback(Callback cb)
注册致命错误的回调函数。 Register a fatal error callback.
static void SizeLimitCheck(size_t limit, size_t size)
在非调试模式下的占位大小检查函数(无实际作用)。 Dummy size limit check for non-debug builds.
static Callback libxr_fatal_error_callback_
已注册的致命错误回调函数。 Registered fatal error callback.
通用回调包装,支持动态参数传递 / Generic callback wrapper supporting dynamic argument passing
Definition libxr_cb.hpp:142
LibXR 命名空间
Definition ch32_can.hpp:14
@ LESS
尺寸必须小于 | Size must be less
@ EQUAL
尺寸必须相等 | Size must be equal
@ MORE
尺寸必须大于 | Size must be more