SimpleWindow
载入中...
搜索中...
未找到
sw::Delegate< TRet(Args...)> 模板类 参考final

委托类,类似于C::中的委托,支持存储和调用任意可调用对象 更多...

#include <Delegate.h>

类 sw::Delegate< TRet(Args...)> 继承关系图:
sw::ICallable< TRet(Args...)>

Public 成员函数

 Delegate (std::nullptr_t=nullptr)
 默认构造函数
 
 Delegate (const ICallable< TRet(Args...)> &callable)
 构造函数,接受一个可调用对象
 
 Delegate (TRet(*func)(Args...))
 构造函数,接受一个函数指针
 
template<typename T , typename std::enable_if<!std::is_base_of< _ICallable, T >::value, int >::type = 0>
 Delegate (const T &callable)
 构造函数,接受一个可调用对象
 
template<typename T >
 Delegate (T &obj, TRet(T::*func)(Args...))
 构造函数,接受一个成员函数指针
 
template<typename T >
 Delegate (const T &obj, TRet(T::*func)(Args...) const)
 构造函数,接受一个常量成员函数指针
 
 Delegate (const Delegate &other)
 拷贝构造函数
 
 Delegate (Delegate &&other) noexcept
 移动构造函数
 
Delegateoperator= (const Delegate &other)
 拷贝赋值运算符
 
Delegateoperator= (Delegate &&other) noexcept
 移动赋值运算符
 
void Add (const ICallable< TRet(Args...)> &callable)
 添加一个可调用对象到委托中
 
void Add (TRet(*func)(Args...))
 添加一个函数指针到委托中
 
template<typename T >
std::enable_if<!std::is_base_of< _ICallable, T >::value, void >::type Add (const T &callable)
 添加一个可调用对象到委托中
 
template<typename T >
void Add (T &obj, TRet(T::*func)(Args...))
 添加一个成员函数指针到委托中
 
template<typename T >
void Add (const T &obj, TRet(T::*func)(Args...) const)
 添加一个常量成员函数指针到委托中
 
void Clear ()
 清空委托中的所有可调用对象
 
bool Remove (const ICallable< TRet(Args...)> &callable)
 移除一个可调用对象
 
bool Remove (TRet(*func)(Args...))
 移除一个函数指针
 
template<typename T >
std::enable_if<!std::is_base_of< _ICallable, T >::value, bool >::type Remove (const T &callable)
 移除一个可调用对象
 
template<typename T >
bool Remove (T &obj, TRet(T::*func)(Args...))
 移除一个成员函数指针
 
template<typename T >
bool Remove (const T &obj, TRet(T::*func)(Args...) const)
 移除一个常量成员函数指针
 
TRet operator() (Args... args) const
 调用委托,执行所有存储的可调用对象
 
bool operator== (const Delegate &other) const
 判断当前委托是否等于另一个委托
 
bool operator!= (const Delegate &other) const
 判断当前委托是否不等于另一个委托
 
bool operator== (std::nullptr_t) const noexcept
 判断当前委托是否等于nullptr
 
bool operator!= (std::nullptr_t) const noexcept
 判断当前委托是否不等于nullptr
 
 operator bool () const noexcept
 判断当前委托是否有效
 
Delegateoperator+= (const ICallable< TRet(Args...)> &callable)
 添加一个可调用对象到委托中
 
Delegateoperator+= (TRet(*func)(Args...))
 添加一个函数指针到委托中
 
template<typename T >
std::enable_if<!std::is_base_of< _ICallable, T >::value, Delegate & >::type operator+= (const T &callable)
 添加一个可调用对象到委托中
 
Delegateoperator-= (const ICallable< TRet(Args...)> &callable)
 移除一个可调用对象
 
Delegateoperator-= (TRet(*func)(Args...))
 移除一个函数指针
 
template<typename T >
std::enable_if<!std::is_base_of< _ICallable, T >::value, Delegate & >::type operator-= (const T &callable)
 移除一个可调用对象
 
virtual TRet Invoke (Args... args) const override
 调用委托,执行所有存储的可调用对象
 
virtual ICallable< TRet(Args...)> * Clone () const override
 克隆当前委托
 
virtual std::type_index GetType () const override
 获取当前委托的类型信息
 
virtual bool Equals (const ICallable< TRet(Args...)> &other) const override
 判断当前委托是否与另一个可调用对象相等
 
template<typename U = TRet>
std::enable_if<!std::is_void< U >::value, std::vector< U > >::type InvokeAll (Args... args) const
 调用所有存储的可调用对象,并返回它们的结果
 
- Public 成员函数 继承自 sw::ICallable< TRet(Args...)>
virtual ~ICallable ()=default
 析构函数
 
virtual bool Equals (const ICallable &other) const =0
 判断当前可调用对象是否与另一个可调用对象相等
 

详细描述

template<typename TRet, typename... Args>
class sw::Delegate< TRet(Args...)>

委托类,类似于C::中的委托,支持存储和调用任意可调用对象

成员函数说明

◆ Clone()

template<typename TRet , typename... Args>
virtual ICallable< TRet(Args...)> * sw::Delegate< TRet(Args...)>::Clone ( ) const
inlineoverridevirtual

克隆当前委托

返回
返回一个新的Delegate对象,包含相同的可调用对象

实现了 sw::ICallable< TRet(Args...)>.

◆ Equals()

template<typename TRet , typename... Args>
virtual bool sw::Delegate< TRet(Args...)>::Equals ( const ICallable< TRet(Args...)> &  other) const
inlineoverridevirtual

判断当前委托是否与另一个可调用对象相等

参数
other另一个可调用对象
返回
如果相等则返回true,否则返回false

◆ GetType()

template<typename TRet , typename... Args>
virtual std::type_index sw::Delegate< TRet(Args...)>::GetType ( ) const
inlineoverridevirtual

获取当前委托的类型信息

返回
返回typeid(Delegate<TRet(Args...)>)

实现了 sw::ICallable< TRet(Args...)>.

◆ Invoke()

template<typename TRet , typename... Args>
virtual TRet sw::Delegate< TRet(Args...)>::Invoke ( Args...  args) const
inlineoverridevirtual

调用委托,执行所有存储的可调用对象

参数
args函数参数
返回
最后一个可调用对象的返回值
异常
std::runtime_error如果委托为空

实现了 sw::ICallable< TRet(Args...)>.

◆ InvokeAll()

template<typename TRet , typename... Args>
template<typename U = TRet>
std::enable_if<!std::is_void< U >::value, std::vector< U > >::type sw::Delegate< TRet(Args...)>::InvokeAll ( Args...  args) const
inline

调用所有存储的可调用对象,并返回它们的结果

参数
args函数参数
返回
返回一个包含所有可调用对象返回值的vector

◆ operator bool()

template<typename TRet , typename... Args>
sw::Delegate< TRet(Args...)>::operator bool ( ) const
inlinenoexcept

判断当前委托是否有效

返回
如果委托不为空则返回true,否则返回false

◆ operator!=() [1/2]

template<typename TRet , typename... Args>
bool sw::Delegate< TRet(Args...)>::operator!= ( const Delegate< TRet(Args...)> &  other) const
inline

判断当前委托是否不等于另一个委托

参数
other另一个委托
返回
如果不相等则返回true,否则返回false

◆ operator!=() [2/2]

template<typename TRet , typename... Args>
bool sw::Delegate< TRet(Args...)>::operator!= ( std::nullptr_t  ) const
inlinenoexcept

判断当前委托是否不等于nullptr

返回
如果委托不为空则返回true,否则返回false

◆ operator()()

template<typename TRet , typename... Args>
TRet sw::Delegate< TRet(Args...)>::operator() ( Args...  args) const
inline

调用委托,执行所有存储的可调用对象

参数
args函数参数
返回
最后一个可调用对象的返回值
异常
std::runtime_error如果委托为空

◆ operator+=() [1/3]

template<typename TRet , typename... Args>
Delegate & sw::Delegate< TRet(Args...)>::operator+= ( const ICallable< TRet(Args...)> &  callable)
inline

添加一个可调用对象到委托中

注解
该函数调用Add函数

◆ operator+=() [2/3]

template<typename TRet , typename... Args>
template<typename T >
std::enable_if<!std::is_base_of< _ICallable, T >::value, Delegate & >::type sw::Delegate< TRet(Args...)>::operator+= ( const T &  callable)
inline

添加一个可调用对象到委托中

注解
该函数调用Add函数

◆ operator+=() [3/3]

template<typename TRet , typename... Args>
Delegate & sw::Delegate< TRet(Args...)>::operator+= ( TRet(*)(Args...)  func)
inline

添加一个函数指针到委托中

注解
该函数调用Add函数

◆ operator-=() [1/3]

template<typename TRet , typename... Args>
Delegate & sw::Delegate< TRet(Args...)>::operator-= ( const ICallable< TRet(Args...)> &  callable)
inline

移除一个可调用对象

注解
该函数调用Remove函数

◆ operator-=() [2/3]

template<typename TRet , typename... Args>
template<typename T >
std::enable_if<!std::is_base_of< _ICallable, T >::value, Delegate & >::type sw::Delegate< TRet(Args...)>::operator-= ( const T &  callable)
inline

移除一个可调用对象

注解
该函数调用Remove函数

◆ operator-=() [3/3]

template<typename TRet , typename... Args>
Delegate & sw::Delegate< TRet(Args...)>::operator-= ( TRet(*)(Args...)  func)
inline

移除一个函数指针

注解
该函数调用Remove函数

◆ operator==() [1/2]

template<typename TRet , typename... Args>
bool sw::Delegate< TRet(Args...)>::operator== ( const Delegate< TRet(Args...)> &  other) const
inline

判断当前委托是否等于另一个委托

参数
other另一个委托
返回
如果相等则返回true,否则返回false

◆ operator==() [2/2]

template<typename TRet , typename... Args>
bool sw::Delegate< TRet(Args...)>::operator== ( std::nullptr_t  ) const
inlinenoexcept

判断当前委托是否等于nullptr

返回
如果委托为空则返回true,否则返回false

◆ Remove() [1/5]

template<typename TRet , typename... Args>
bool sw::Delegate< TRet(Args...)>::Remove ( const ICallable< TRet(Args...)> &  callable)
inline

移除一个可调用对象

返回
如果成功移除则返回true,否则返回false
注解
按照添加顺序从后向前查找,找到第一个匹配的可调用对象并移除

◆ Remove() [2/5]

template<typename TRet , typename... Args>
template<typename T >
std::enable_if<!std::is_base_of< _ICallable, T >::value, bool >::type sw::Delegate< TRet(Args...)>::Remove ( const T &  callable)
inline

移除一个可调用对象

返回
如果成功移除则返回true,否则返回false
注解
按照添加顺序从后向前查找,找到第一个匹配的可调用对象并移除

◆ Remove() [3/5]

template<typename TRet , typename... Args>
template<typename T >
bool sw::Delegate< TRet(Args...)>::Remove ( const T &  obj,
TRet(T::*)(Args...) const  func 
)
inline

移除一个常量成员函数指针

返回
如果成功移除则返回true,否则返回false
注解
按照添加顺序从后向前查找,找到第一个匹配的可调用对象并移除

◆ Remove() [4/5]

template<typename TRet , typename... Args>
template<typename T >
bool sw::Delegate< TRet(Args...)>::Remove ( T &  obj,
TRet(T::*)(Args...)  func 
)
inline

移除一个成员函数指针

返回
如果成功移除则返回true,否则返回false
注解
按照添加顺序从后向前查找,找到第一个匹配的可调用对象并移除

◆ Remove() [5/5]

template<typename TRet , typename... Args>
bool sw::Delegate< TRet(Args...)>::Remove ( TRet(*)(Args...)  func)
inline

移除一个函数指针

返回
如果成功移除则返回true,否则返回false
注解
按照添加顺序从后向前查找,找到第一个匹配的函数指针并移除

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