libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Callback< Args > Class Template Reference

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

#include <libxr_cb.hpp>

Collaboration diagram for LibXR::Callback< Args >:
[legend]

Public Member Functions

 Callback ()
 默认构造函数,创建空回调对象 / Default constructor creating an empty callback
 
 Callback (const Callback &)=default
 
Callbackoperator= (const Callback &)=default
 
 Callback (Callback &&other) noexcept
 移动构造函数,转移回调对象的所有权 / Move constructor transferring callback ownership
 
Callbackoperator= (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
 

Private Member Functions

 Callback (CallbackBlockHeader< Args... > *cb_block)
 私有构造函数,仅用于内部创建回调实例 / Private constructor used internally to create callback instances
 

Static Private Member Functions

static void FunctionDefault (void *, bool, Args...)
 

Private Attributes

CallbackBlockHeader< Args... > * cb_block_
 回调块指针 / Pointer to the callback block
 

Static Private Attributes

static CallbackBlockHeader< Args... > empty_cb_block_ = {&FunctionDefault}
 

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/3]

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_) {}
CallbackBlockHeader< Args... > * cb_block_
回调块指针 / Pointer to the callback block
Definition libxr_cb.hpp:259

◆ Callback() [2/3]

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 }

◆ Callback() [3/3]

template<typename... Args>
LibXR::Callback< Args >::Callback ( CallbackBlockHeader< Args... > * cb_block)
inlineexplicitprivate

私有构造函数,仅用于内部创建回调实例 / Private constructor used internally to create callback instances

Parameters
cb_block回调块对象指针 / Pointer to the callback block

Definition at line 254 of file libxr_cb.hpp.

255 : cb_block_((cb_block != nullptr) ? cb_block : &empty_cb_block_)
256 {
257 }

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_; }

◆ FunctionDefault()

template<typename... Args>
static void LibXR::Callback< Args >::FunctionDefault ( void * ,
bool ,
Args...  )
inlinestaticprivate

Definition at line 144 of file libxr_cb.hpp.

144{}

◆ 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 }

Field Documentation

◆ cb_block_

template<typename... Args>
CallbackBlockHeader<Args...>* LibXR::Callback< Args >::cb_block_
private
Initial value:
=
&empty_cb_block_

回调块指针 / Pointer to the callback block

Definition at line 259 of file libxr_cb.hpp.

◆ empty_cb_block_

template<typename... Args>
CallbackBlockHeader<Args...> LibXR::Callback< Args >::empty_cb_block_ = {&FunctionDefault}
inlinestaticprivate

Definition at line 145 of file libxr_cb.hpp.

145{&FunctionDefault};

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