Signal: made reset() public and added parameter to reset without disconnecting the signal.
This commit is contained in:
parent
c0e70341c9
commit
1172116d6b
@ -32,6 +32,10 @@ inline constexpr signal_token_t INVALID_SIGNAL_TOKEN = std::numeric_limits<signa
|
||||
//
|
||||
|
||||
MIJIN_DEFINE_FLAG(Oneshot);
|
||||
MIJIN_DEFINE_FLAG(DisconnectSignal);
|
||||
|
||||
template<template<typename> typename TAllocator, typename... TArgs>
|
||||
class SignalAutoToken;
|
||||
|
||||
template<template<typename> typename TAllocator, typename... TArgs>
|
||||
class BaseSignal
|
||||
@ -39,6 +43,7 @@ class BaseSignal
|
||||
public:
|
||||
using handler_t = std::function<void(TArgs...)>; // TODO: write a custom function wrapper with allocator support
|
||||
using token_t = signal_token_t;
|
||||
using auto_token_t = SignalAutoToken<TAllocator, TArgs...>;
|
||||
private:
|
||||
struct RegisteredHandler
|
||||
{
|
||||
@ -118,8 +123,7 @@ public:
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
void reset() MIJIN_NOEXCEPT;
|
||||
void reset(DisconnectSignal disconnect = DisconnectSignal::YES) MIJIN_NOEXCEPT;
|
||||
|
||||
friend signal_t;
|
||||
};
|
||||
@ -129,11 +133,13 @@ private:
|
||||
//
|
||||
|
||||
template<template<typename> typename TAllocator, typename... TArgs>
|
||||
void SignalAutoToken<TAllocator, TArgs...>::reset() MIJIN_NOEXCEPT
|
||||
void SignalAutoToken<TAllocator, TArgs...>::reset(DisconnectSignal disconnect) MIJIN_NOEXCEPT
|
||||
{
|
||||
if (signal_ != nullptr && token_ != INVALID_SIGNAL_TOKEN)
|
||||
{
|
||||
signal_->disconnect(token_);
|
||||
if (disconnect) {
|
||||
signal_->disconnect(token_);
|
||||
}
|
||||
signal_ = nullptr;
|
||||
token_ = INVALID_SIGNAL_TOKEN;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user