提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
More...
|
| | Callback () |
| | 默认构造函数,创建空回调对象。 Default constructor, creating an empty callback instance.
|
| |
|
| Callback (const Callback &)=default |
| |
|
Callback & | operator= (const Callback &)=default |
| |
| | Callback (Callback &&other) noexcept |
| | 移动构造函数,转移回调对象的所有权。 Move constructor, transferring ownership of the callback object.
|
| |
| Callback & | operator= (Callback &&other) noexcept |
| | 移动赋值运算符,转移回调对象的所有权。 Move assignment operator, transferring ownership of the callback object.
|
| |
| template<typename... PassArgs> |
| void | Run (bool in_isr, PassArgs &&...args) const |
| | 执行回调函数,并传递参数。 Executes the callback function, passing the arguments.
|
| |
| bool | Empty () const |
| | 检查回调是否为空。 Checks if the callback is empty.
|
| |
template<typename... Args>
class LibXR::Callback< Args >
提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
- Template Parameters
-
| Args | 额外的参数类型列表。 Additional argument types. |
Definition at line 123 of file libxr_cb.hpp.
template<typename... Args>
template<typename FunType , typename ArgType >
创建一个新的回调对象,并绑定回调函数和参数。 Creates a new callback instance, binding a function and an argument.
- Template Parameters
-
| FunType | 回调函数类型。 Type of the callback function. |
| ArgType | 绑定的参数类型。 Type of the bound argument. |
- Parameters
-
| fun | 需要绑定的回调函数。 The callback function to bind. |
| arg | 绑定的参数值。 The bound argument value. |
- Returns
- 生成的 Callback 实例。 The created Callback instance.
- Note
- 包含动态内存分配。 Contains dynamic memory allocation.
Definition at line 145 of file libxr_cb.hpp.
146 {
147 void (*fun_ptr)(bool, ArgType, Args...) = fun;
148 auto cb_block = new CallbackBlock<ArgType, Args...>(fun_ptr, arg);
149
150 auto cb_fun = [](bool in_isr, void *cb_block, Args... args)
151 {
152 auto *cb = static_cast<CallbackBlock<ArgType, Args...> *>(cb_block);
153 cb->Call(in_isr, std::forward<Args>(args)...);
154 };
155
157 }
Callback()
默认构造函数,创建空回调对象。 Default constructor, creating an empty callback instance.