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

提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing. More...

#include <libxr_cb.hpp>

Public Member Functions

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

Static Public Member Functions

template<typename FunType , typename ArgType >
static Callback Create (FunType fun, ArgType arg)
 创建一个新的回调对象,并绑定回调函数和参数。 Creates a new callback instance, binding a function and an argument.
 

Private Member Functions

 Callback (void *cb_block, void(*cb_fun)(bool, void *, Args...))
 私有构造函数,仅用于内部创建回调实例。 Private constructor, used internally for creating callback instances.
 

Private Attributes

voidcb_block_
 存储回调块的指针。 Pointer to the callback block.
 
void(* cb_fun_ )(bool, void *, Args...)
 存储回调执行的函数指针。 Pointer to the callback execution function.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Callback() [1/3]

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

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

Definition at line 160 of file libxr_cb.hpp.

160: cb_block_(nullptr), cb_fun_(nullptr) {}
void * cb_block_
存储回调块的指针。 Pointer to the callback block.
Definition libxr_cb.hpp:230
void(* cb_fun_)(bool, void *, Args...)
存储回调执行的函数指针。 Pointer to the callback execution function.
Definition libxr_cb.hpp:231

◆ Callback() [2/3]

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

移动构造函数,转移回调对象的所有权。 Move constructor, transferring ownership of the callback object.

Parameters
other另一个 Callback 实例。 Another instance of Callback.

Definition at line 172 of file libxr_cb.hpp.

173 : cb_block_(std::exchange(other.cb_block_, nullptr)),
174 cb_fun_(std::exchange(other.cb_fun_, nullptr))
175 {
176 }
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

◆ Callback() [3/3]

template<typename... Args>
LibXR::Callback< Args >::Callback ( void cb_block,
void(*)(bool, void *, Args...)  cb_fun 
)
inlineprivate

私有构造函数,仅用于内部创建回调实例。 Private constructor, used internally for creating callback instances.

Parameters
cb_block绑定的回调块对象。 The bound callback block object.
cb_fun处理回调调用的函数指针。 Function pointer for handling callback invocation.

Definition at line 225 of file libxr_cb.hpp.

227 {
228 }

Member Function Documentation

◆ Create()

template<typename... Args>
static Callback LibXR::Callback< Args >::Create ( FunType  fun,
ArgType  arg 
)
inlinestatic

创建一个新的回调对象,并绑定回调函数和参数。 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.

Definition at line 142 of file libxr_cb.hpp.

143 {
144 void (*fun_ptr)(bool, ArgType, Args...) = fun;
145 auto cb_block = new CallbackBlock<ArgType, Args...>(fun_ptr, arg);
146
147 auto cb_fun = [](bool in_isr, void *cb_block, Args... args)
148 {
149 auto *cb = static_cast<CallbackBlock<ArgType, Args...> *>(cb_block);
150 cb->Call(in_isr, std::forward<Args>(args)...);
151 };
152
153 return Callback(cb_block, cb_fun);
154 }
Callback()
默认构造函数,创建空回调对象。 Default constructor, creating an empty callback instance.
Definition libxr_cb.hpp:160

◆ operator=()

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

移动赋值运算符,转移回调对象的所有权。 Move assignment operator, transferring ownership of the callback object.

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

Definition at line 187 of file libxr_cb.hpp.

188 {
189 if (this != &other)
190 {
191 cb_block_ = std::exchange(other.cb_block_, nullptr);
192 cb_fun_ = std::exchange(other.cb_fun_, nullptr);
193 }
194 return *this;
195 }

◆ Run()

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

执行回调函数,并传递参数。 Executes the callback function, passing the arguments.

Parameters
in_isr指示是否在中断上下文中执行。 Indicates whether the call is executed within an ISR context.
args额外传递的参数。 Additional arguments to pass.

Definition at line 207 of file libxr_cb.hpp.

208 {
209 if (cb_fun_)
210 {
211 cb_fun_(in_isr, cb_block_, std::forward<PassArgs>(args)...);
212 }
213 }

Field Documentation

◆ cb_block_

template<typename... Args>
void* LibXR::Callback< Args >::cb_block_
private

存储回调块的指针。 Pointer to the callback block.

Definition at line 230 of file libxr_cb.hpp.

◆ cb_fun_

template<typename... Args>
void(* LibXR::Callback< Args >::cb_fun_) (bool, void *, Args...)
private

存储回调执行的函数指针。 Pointer to the callback execution function.

Definition at line 231 of file libxr_cb.hpp.


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