20#ifndef COMMON_OBSERVABLE_H__
21#define COMMON_OBSERVABLE_H__
102 LINK( std::shared_ptr<DETAIL::OBSERVABLE_BASE::IMPL> token,
void* observer );
111 explicit operator bool()
const;
116 std::shared_ptr<DETAIL::OBSERVABLE_BASE::IMPL>
token_;
121template <
typename ObserverInterface>
144 OBSERVABLE_BASE::add_observer(
static_cast<void*
>( aObserver ) );
155 OBSERVABLE_BASE::add_observer(
static_cast<void*
>( aObserver ) );
156 return LINK(
impl_,
static_cast<void*
>( aObserver ) );
168 OBSERVABLE_BASE::remove_observer(
static_cast<void*
>( aObserver ) );
177 template <
typename... Args1,
typename... Args2>
178 void Notify(
void ( ObserverInterface::*Ptr )( Args1... ), Args2&&... aArgs )
180 static_assert(
sizeof...( Args1 ) ==
sizeof...( Args2 ),
"argument counts don't match" );
187 for(
auto* void_ptr :
impl_->observers_ )
191 auto* typed_ptr =
static_cast<ObserverInterface*
>( void_ptr );
192 ( typed_ptr->*Ptr )( std::forward<Args2>( aArgs )... );
213 template <
typename... Args1,
typename... Args2>
214 void NotifyIgnore(
void ( ObserverInterface::*Ptr )( Args1... ), ObserverInterface* aIgnore,
217 static_assert(
sizeof...( Args1 ) ==
sizeof...( Args2 ),
"argument counts don't match" );
225 for(
auto* void_ptr :
impl_->observers_ )
227 if( void_ptr && void_ptr != aIgnore )
229 auto* typed_ptr =
static_cast<ObserverInterface*
>( void_ptr );
230 ( typed_ptr->*Ptr )( std::forward<Args2>( aArgs )... );
Simple RAII-handle to a subscription.
void operator=(const LINK &)=delete
std::shared_ptr< DETAIL::OBSERVABLE_BASE::IMPL > token_
LINK(const LINK &)=delete
LINK Subscribe(ObserverInterface *aObserver)
Add a subscription returning an RAII link.
OBSERVABLE(OBSERVABLE &aInherit)
Construct an observable with a shared subscription list.
void SubscribeUnmanaged(ObserverInterface *aObserver)
Add a subscription without RAII link.
void NotifyIgnore(void(ObserverInterface::*Ptr)(Args1...), ObserverInterface *aIgnore, Args2 &&... aArgs)
Notify event to all subscribed observers but one to be ignore.
void Notify(void(ObserverInterface::*Ptr)(Args1...), Args2 &&... aArgs)
Notify event to all subscribed observers.
OBSERVABLE()
Construct an observable with empty non-shared subscription list.
void Unsubscribe(ObserverInterface *aObserver)
Cancel the subscription of a subscriber.
A model subscriber implementation using links to represent connections.
bool is_iterating() const
void remove_observer(void *observer)
void add_observer(void *observer)
std::vector< void * > observers_
OBSERVABLE_BASE * owned_by_
IMPL(OBSERVABLE_BASE *owned_by=nullptr)
unsigned int iteration_count_
void remove_observer(void *observer)
std::shared_ptr< IMPL > get_shared_impl()
void add_observer(void *observer)
void on_observers_empty()
void allocate_shared_impl()
std::shared_ptr< IMPL > impl_