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 141 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 191 of file libxr_cb.hpp.

191: cb_block_(&empty_cb_block_) {}
CallbackBlockHeader< Args... > * cb_block_
回调块指针 / Pointer to the callback block
Definition libxr_cb.hpp:249

◆ 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 202 of file libxr_cb.hpp.

203 : cb_block_(std::exchange(other.cb_block_, &empty_cb_block_))
204 {
205 }

◆ 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 244 of file libxr_cb.hpp.

245 : cb_block_((cb_block != nullptr) ? cb_block : &empty_cb_block_)
246 {
247 }

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

Definition at line 159 of file libxr_cb.hpp.

160 {
161 using FunctionType = typename CallbackBlock<BoundArgType, Args...>::FunctionType;
162 auto cb_block =
163 new CallbackBlock<BoundArgType, Args...>(static_cast<FunctionType>(fun),
164 std::move(arg));
165 return Callback(cb_block);
166 }
Callback()
默认构造函数,创建空回调对象 / Default constructor creating an empty callback
Definition libxr_cb.hpp:191

◆ 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

Definition at line 179 of file libxr_cb.hpp.

180 {
181 using FunctionType = typename CallbackBlock<BoundArgType, Args...>::FunctionType;
182 auto cb_block =
183 new GuardedCallbackBlock<BoundArgType, Args...>(static_cast<FunctionType>(fun),
184 std::move(arg));
185 return Callback(cb_block);
186 }

◆ 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 235 of file libxr_cb.hpp.

235{ return cb_block_ == &empty_cb_block_; }

◆ FunctionDefault()

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

Definition at line 143 of file libxr_cb.hpp.

143{}

◆ 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 214 of file libxr_cb.hpp.

215 {
216 if (this != &other)
217 {
218 cb_block_ = std::exchange(other.cb_block_, &empty_cb_block_);
219 }
220 return *this;
221 }

◆ Run()

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

Definition at line 224 of file libxr_cb.hpp.

225 {
226 cb_block_->run_fun_(cb_block_, in_isr, std::forward<PassArgs>(args)...);
227 }

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 249 of file libxr_cb.hpp.

◆ empty_cb_block_

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

Definition at line 144 of file libxr_cb.hpp.

144{&FunctionDefault};

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