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 <optional>
7
8#include "libxr_cb.hpp"
9#include "libxr_def.hpp"
10
25void libxr_fatal_error(const char *file, uint32_t line, bool in_isr);
26
27namespace LibXR
28{
39class Assert
40{
41 public:
52 static void RegisterFatalErrorCB(const Callback &cb)
53 {
55 }
56
65 template <typename T>
66 static void RegisterFatalErrorCB(T &&cb)
67 {
68 libxr_fatal_error_callback_ = std::forward<T>(cb);
69 }
70
71#ifdef LIBXR_DEBUG_BUILD
90 template <SizeLimitMode mode>
91 static void SizeLimitCheck(size_t limit, size_t size)
92 {
93 if constexpr (mode == SizeLimitMode::EQUAL)
94 {
95 ASSERT(limit == size);
96 }
97 else if constexpr (mode == SizeLimitMode::MORE)
98 {
99 ASSERT(limit <= size);
100 }
101 else if constexpr (mode == SizeLimitMode::LESS)
102 {
103 ASSERT(limit >= size);
104 }
105 }
106#else
118 template <SizeLimitMode mode>
119 static void SizeLimitCheck(size_t limit, size_t size)
120 {
121 UNUSED(limit);
122 UNUSED(size);
123 }
124#endif
125
132};
133} // namespace LibXR
运行时错误检查的断言工具类。 Provides assertion mechanisms for runtime error checking.
static void SizeLimitCheck(size_t limit, size_t size)
在非调试模式下的占位大小检查函数(无实际作用)。 Dummy size limit check for non-debug builds.
static void RegisterFatalErrorCB(const Callback &cb)
注册致命错误的回调函数。 Registers a fatal error callback.
static Callback libxr_fatal_error_callback_
已注册的致命错误回调函数。 Registered fatal error callback.
static void RegisterFatalErrorCB(T &&cb)
注册致命错误的回调函数。 Registers a fatal error callback
提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
Definition libxr_cb.hpp:125
LibXR 命名空间
Definition ch32_gpio.hpp:9