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
7#include "libxr_cb.hpp"
8#include "libxr_def.hpp"
9
24void libxr_fatal_error(const char *file, uint32_t line, bool in_isr);
25
26namespace LibXR
27{
38class Assert
39{
40 public:
42
50 static void RegisterFatalErrorCallback(const Callback &cb);
51
59 static void RegisterFatalErrorCallback(Callback &&cb);
60
61#ifdef LIBXR_DEBUG_BUILD
80 template <SizeLimitMode mode>
81 static void SizeLimitCheck(size_t limit, size_t size)
82 {
83 if constexpr (mode == SizeLimitMode::EQUAL)
84 {
85 ASSERT(limit == size);
86 }
87 else if constexpr (mode == SizeLimitMode::MORE)
88 {
89 ASSERT(limit <= size);
90 }
91 else if constexpr (mode == SizeLimitMode::LESS)
92 {
93 ASSERT(limit >= size);
94 }
95 }
96#else
108 template <SizeLimitMode mode>
109 static void SizeLimitCheck(size_t limit, size_t size)
110 {
111 UNUSED(limit);
112 UNUSED(size);
113 }
114#endif
115
121 static inline Callback libxr_fatal_error_callback_; // NOLINT
122};
123} // 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 Callback libxr_fatal_error_callback_
已注册的致命错误回调函数。 Registered fatal error callback.
static void RegisterFatalErrorCallback(const Callback &cb)
注册致命错误的回调函数(左值引用版本)。 Register a fatal error callback (lvalue reference version).
提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
Definition libxr_cb.hpp:124
LibXR 命名空间
Definition ch32_gpio.hpp:9