SimpleWindow
载入中...
搜索中...
未找到
sw::CallableList< T > 模板类 参考

用于存储和管理多个可调用对象的列表,针对单个可调用对象的情况进行优化 更多...

#include <Delegate.h>

Public 类型

using TCallable = ICallable< T >
 可调用对象类型别名
 
using TSinglePtr = std::unique_ptr< TCallable >
 智能指针类型别名,用于存储可调用对象的唯一指针
 
using TSharedList = std::vector< std::shared_ptr< TCallable > >
 列表类型别名,用于存储多个可调用对象的智能指针
 

Public 成员函数

 CallableList ()
 默认构造函数
 
 CallableList (const CallableList &other)
 拷贝构造函数
 
 CallableList (CallableList &&other) noexcept
 移动构造函数
 
CallableListoperator= (const CallableList &other)
 拷贝赋值运算
 
CallableListoperator= (CallableList &&other) noexcept
 移动赋值运算
 
 ~CallableList ()
 析构函数
 
size_t Count () const noexcept
 获取当前存储的可调用对象数量
 
bool IsEmpty () const noexcept
 判断当前存储的可调用对象是否为空
 
void Clear () noexcept
 清空当前存储的可调用对象
 
void Add (TCallable *callable)
 添加一个可调用对象到列表中
 
bool RemoveAt (size_t index) noexcept
 移除指定索引处的可调用对象
 
TCallableGetAt (size_t index) const noexcept
 获取指定索引处的可调用对象
 
TCallableoperator[] (size_t index) const noexcept
 获取指定索引处的可调用对象
 

详细描述

template<typename T>
class sw::CallableList< T >

用于存储和管理多个可调用对象的列表,针对单个可调用对象的情况进行优化

成员函数说明

◆ Add()

template<typename T >
void sw::CallableList< T >::Add ( TCallable callable)
inline

添加一个可调用对象到列表中

注解
传入对象的生命周期将由CallableList管理
异常安全:
  • SINGLE→LIST 升级时使用 reserve(2) 避免后续 emplace_back 触发扩容, 此时唯一的失败路径是 shared_ptr 控制块分配失败,shared_ptr 构造函数 保证抛异常时自动 delete 传入的裸指针。
  • STATE_LIST 分支先把裸指针转交给本地 shared_ptr,再 emplace_back, 即使 vector 扩容失败,本地 shared_ptr 析构时也会正确释放对象。

◆ Count()

template<typename T >
size_t sw::CallableList< T >::Count ( ) const
inlinenoexcept

获取当前存储的可调用对象数量

返回
可调用对象的数量

◆ GetAt()

template<typename T >
TCallable * sw::CallableList< T >::GetAt ( size_t  index) const
inlinenoexcept

获取指定索引处的可调用对象

返回
如果索引有效则返回对应的可调用对象,否则返回nullptr

◆ IsEmpty()

template<typename T >
bool sw::CallableList< T >::IsEmpty ( ) const
inlinenoexcept

判断当前存储的可调用对象是否为空

返回
如果没有存储任何可调用对象则返回true,否则返回false

◆ operator=()

template<typename T >
CallableList & sw::CallableList< T >::operator= ( const CallableList< T > &  other)
inline

拷贝赋值运算

注解
强异常安全:先在本地完成可能抛异常的 Clone / vector 拷贝, 全部成功后再原子地切换 *this 的状态。提交阶段(_Reset(state) 与 unique_ptr/vector 的移动赋值)均为 noexcept,不会导致中间不一致。

◆ operator[]()

template<typename T >
TCallable * sw::CallableList< T >::operator[] ( size_t  index) const
inlinenoexcept

获取指定索引处的可调用对象

返回
如果索引有效则返回对应的可调用对象,否则返回nullptr

◆ RemoveAt()

template<typename T >
bool sw::CallableList< T >::RemoveAt ( size_t  index)
inlinenoexcept

移除指定索引处的可调用对象

返回
如果成功移除则返回true,否则返回false

该类的文档由以下文件生成: