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

提供一个回调函数的封装,实现参数绑定和回调执行。 Provides a wrapper for callback functions, enabling argument binding and invocation. More...

#include <libxr_cb.hpp>

Public Types

using FunctionType = void(*)(bool, ArgType, Args...)
 定义回调函数类型。 Defines the type of the callback function.
 

Public Member Functions

template<typename FunType , typename ArgT >
 CallbackBlock (FunType fun, ArgT &&arg)
 构造回调块,绑定回调函数和参数。 Constructs a callback block, binding a function and an argument.
 
void Call (bool in_isr, Args &&...args)
 调用回调函数,并传递额外参数。 Calls the callback function, passing additional arguments.
 
 CallbackBlock (const CallbackBlock &other)=delete
 
CallbackBlockoperator= (const CallbackBlock &other)=delete
 
 CallbackBlock (CallbackBlock &&other) noexcept
 移动构造函数,转移回调函数与参数。 Move constructor, transferring the callback function and argument.
 
CallbackBlockoperator= (CallbackBlock &&other) noexcept
 移动赋值运算符,转移回调函数与参数。 Move assignment operator, transferring the callback function and argument.
 

Private Attributes

void(* fun_ )(bool, ArgType, Args...)
 绑定的回调函数。 The bound callback function.
 
ArgType arg_
 绑定的参数。 The bound argument.
 
bool in_isr_ = false
 

Detailed Description

template<typename ArgType, typename... Args>
class LibXR::CallbackBlock< ArgType, Args >

提供一个回调函数的封装,实现参数绑定和回调执行。 Provides a wrapper for callback functions, enabling argument binding and invocation.

Template Parameters
ArgType绑定的第一个参数类型。 The type of the first bound argument.
Args额外的参数类型列表。 Additional argument types.

Definition at line 21 of file libxr_cb.hpp.

Member Typedef Documentation

◆ FunctionType

template<typename ArgType , typename... Args>
LibXR::CallbackBlock< ArgType, Args >::FunctionType

定义回调函数类型。 Defines the type of the callback function.

Definition at line 29 of file libxr_cb.hpp.

Constructor & Destructor Documentation

◆ CallbackBlock() [1/2]

template<typename ArgType , typename... Args>
template<typename FunType , typename ArgT >
LibXR::CallbackBlock< ArgType, Args >::CallbackBlock ( FunType  fun,
ArgT &&  arg 
)
inline

构造回调块,绑定回调函数和参数。 Constructs a callback block, binding a function and an argument.

Template Parameters
FunType函数类型。 The type of the function.
ArgT绑定的参数类型。 The type of the bound argument.
Parameters
fun需要调用的回调函数。 The callback function to be invoked.
arg绑定的参数值。 The bound argument value.

Definition at line 45 of file libxr_cb.hpp.

45 : fun_(fun), arg_(std::forward<ArgT>(arg))
46 {
47 }
ArgType arg_
绑定的参数。 The bound argument.
Definition libxr_cb.hpp:109
void(* fun_)(bool, ArgType, Args...)
绑定的回调函数。 The bound callback function.
Definition libxr_cb.hpp:107

◆ CallbackBlock() [2/2]

template<typename ArgType , typename... Args>
LibXR::CallbackBlock< ArgType, Args >::CallbackBlock ( CallbackBlock< ArgType, Args > &&  other)
inlinenoexcept

移动构造函数,转移回调函数与参数。 Move constructor, transferring the callback function and argument.

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

Definition at line 79 of file libxr_cb.hpp.

80 : fun_(std::exchange(other.fun_, nullptr)),
81 arg_(std::move(other.arg_)),
82 in_isr_(other.in_isr_)
83 {
84 }
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

Member Function Documentation

◆ Call()

template<typename ArgType , typename... Args>
void LibXR::CallbackBlock< ArgType, Args >::Call ( bool  in_isr,
Args &&...  args 
)
inline

调用回调函数,并传递额外参数。 Calls the callback function, passing additional arguments.

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

Definition at line 58 of file libxr_cb.hpp.

59 {
61 if (fun_)
62 {
63 fun_(in_isr, arg_, std::forward<Args>(args)...);
64 }
65 }

◆ operator=()

template<typename ArgType , typename... Args>
CallbackBlock & LibXR::CallbackBlock< ArgType, Args >::operator= ( CallbackBlock< ArgType, Args > &&  other)
inlinenoexcept

移动赋值运算符,转移回调函数与参数。 Move assignment operator, transferring the callback function and argument.

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

Definition at line 95 of file libxr_cb.hpp.

96 {
97 if (this != &other)
98 {
99 fun_ = std::exchange(other.fun_, nullptr);
100 arg_ = std::move(other.arg_);
101 in_isr_ = other.in_isr_;
102 }
103 return *this;
104 }

Field Documentation

◆ arg_

template<typename ArgType , typename... Args>
ArgType LibXR::CallbackBlock< ArgType, Args >::arg_
private

绑定的参数。 The bound argument.

Definition at line 109 of file libxr_cb.hpp.

◆ fun_

template<typename ArgType , typename... Args>
void(* LibXR::CallbackBlock< ArgType, Args >::fun_) (bool, ArgType, Args...)
private

绑定的回调函数。 The bound callback function.

Definition at line 107 of file libxr_cb.hpp.

◆ in_isr_

template<typename ArgType , typename... Args>
bool LibXR::CallbackBlock< ArgType, Args >::in_isr_ = false
private

指示是否在中断上下文中执行。 Indicates whether the function is executed in an ISR context.

Definition at line 110 of file libxr_cb.hpp.


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