libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::Callback< Args > Class Template Reference

通用回调包装,支持动态参数传递 / Generic callback wrapper supporting dynamic argument passing More...

#include <libxr_cb.hpp>

Public Member Functions

 Callback ()
 默认构造函数,创建空回调对象 / Default constructor creating an empty callback
 
 Callback (const Callback &)=default
 
Callback & operator= (const Callback &)=default
 
 Callback (Callback &&other) noexcept
 移动构造函数,转移回调对象的所有权 / Move constructor transferring callback ownership
 
Callback & operator= (Callback &&other) noexcept
 移动赋值运算符,转移回调对象的所有权 / Move assignment operator transferring callback ownership
 
template<typename... PassArgs>
void Run (bool in_isr, PassArgs &&... args) const
 
bool Empty () const
 检查回调是否为空 / Check whether the callback is empty
 

Static Public Member Functions

template<typename BoundArgType , typename CallableType >
requires CallbackFunctionCompatible<CallableType, BoundArgType, Args...>
static Callback Create (CallableType fun, BoundArgType arg)
 创建回调对象并绑定回调函数与参数 / Create a callback instance with bound function and argument
 
template<typename BoundArgType , typename CallableType >
requires CallbackFunctionCompatible<CallableType, BoundArgType, Args...>
static Callback CreateGuarded (CallableType fun, BoundArgType arg)
 创建带防重入保护的回调 / Create a guarded callback
 

Detailed Description

template<typename... Args>
class LibXR::Callback< Args >

通用回调包装,支持动态参数传递 / Generic callback wrapper supporting dynamic argument passing

Template Parameters
Args额外的参数类型列表 / Additional argument types

Definition at line 142 of file libxr_cb.hpp.

Constructor & Destructor Documentation

◆ Callback() [1/2]

template<typename... Args>
LibXR::Callback< Args >::Callback ( )
inline

默认构造函数,创建空回调对象 / Default constructor creating an empty callback

Definition at line 201 of file libxr_cb.hpp.

201: cb_block_(&empty_cb_block_) {}

◆ Callback() [2/2]

template<typename... Args>
LibXR::Callback< Args >::Callback ( Callback< Args > && other)
inlinenoexcept

移动构造函数,转移回调对象的所有权 / Move constructor transferring callback ownership

Parameters
other另一个 Callback 实例 / Another Callback instance

Definition at line 212 of file libxr_cb.hpp.

213 : cb_block_(std::exchange(other.cb_block_, &empty_cb_block_))
214 {
215 }

Member Function Documentation

◆ Create()

template<typename... Args>
template<typename BoundArgType , typename CallableType >
requires CallbackFunctionCompatible<CallableType, BoundArgType, Args...>
static Callback LibXR::Callback< Args >::Create ( CallableType fun,
BoundArgType arg )
inlinestaticnodiscard

创建回调对象并绑定回调函数与参数 / Create a callback instance with bound function and argument

Template Parameters
BoundArgType绑定参数类型 / Bound argument type
CallableType回调可调用对象类型 / Callback callable type
Parameters
fun需要绑定的回调函数 / Callback function to bind
arg绑定的参数值 / Bound argument value
Returns
Callback 实例 / Created Callback instance
Note
预期用法是初始化阶段创建并长期持有; 运行时高频创建/销毁不属于设计目标。 Intended usage is initialization-time creation with long-lived retention; runtime churn-style create/destroy patterns are outside the intended model.

Definition at line 166 of file libxr_cb.hpp.

167 {
168 using FunctionType = typename CallbackBlock<BoundArgType, Args...>::FunctionType;
169 auto cb_block = new CallbackBlock<BoundArgType, Args...>(
170 static_cast<FunctionType>(fun), std::move(arg));
171 return Callback(cb_block);
172 }
Callback()
默认构造函数,创建空回调对象 / Default constructor creating an empty callback
Definition libxr_cb.hpp:201

◆ CreateGuarded()

template<typename... Args>
template<typename BoundArgType , typename CallableType >
requires CallbackFunctionCompatible<CallableType, BoundArgType, Args...>
static Callback LibXR::Callback< Args >::CreateGuarded ( CallableType fun,
BoundArgType arg )
inlinestaticnodiscard

创建带防重入保护的回调 / Create a guarded callback

Template Parameters
BoundArgType绑定参数类型 / Bound argument type
CallableType回调可调用对象类型 / Callback callable type
Parameters
fun需要绑定的回调函数 / Callback function to bind
arg绑定的参数值 / Bound argument value
Returns
Callback 实例 / Created Callback instance
Note
该 guarded callback 预期用于单条逻辑回调链上的递归压平, 不承担任意多上下文串行化。 Guarded callbacks are meant for self-recursive flattening on one logical callback chain, not arbitrary multi-context serialization.

Definition at line 190 of file libxr_cb.hpp.

191 {
192 using FunctionType = typename CallbackBlock<BoundArgType, Args...>::FunctionType;
193 auto cb_block = new GuardedCallbackBlock<BoundArgType, Args...>(
194 static_cast<FunctionType>(fun), std::move(arg));
195 return Callback(cb_block);
196 }

◆ Empty()

template<typename... Args>
bool LibXR::Callback< Args >::Empty ( ) const
inline

检查回调是否为空 / Check whether the callback is empty

Returns
true 回调为空 / Callback is empty
false 回调非空 / Callback is not empty

Definition at line 245 of file libxr_cb.hpp.

245{ return cb_block_ == &empty_cb_block_; }

◆ operator=()

template<typename... Args>
Callback & LibXR::Callback< Args >::operator= ( Callback< Args > && other)
inlinenoexcept

移动赋值运算符,转移回调对象的所有权 / Move assignment operator transferring callback ownership

Parameters
other另一个 Callback 实例 / Another Callback instance
Returns
当前对象引用 / Reference to the current object

Definition at line 224 of file libxr_cb.hpp.

225 {
226 if (this != &other)
227 {
228 cb_block_ = std::exchange(other.cb_block_, &empty_cb_block_);
229 }
230 return *this;
231 }

◆ Run()

template<typename... Args>
template<typename... PassArgs>
void LibXR::Callback< Args >::Run ( bool in_isr,
PassArgs &&... args ) const
inline

Definition at line 234 of file libxr_cb.hpp.

235 {
236 cb_block_->run_fun_(cb_block_, in_isr, std::forward<PassArgs>(args)...);
237 }

The documentation for this class was generated from the following file: