24#ifndef COMMON_OBSERVABLE_H__
25#define COMMON_OBSERVABLE_H__
106 LINK( std::shared_ptr<DETAIL::OBSERVABLE_BASE::IMPL> token,
void* observer );
115 explicit operator bool()
const;
120 std::shared_ptr<DETAIL::OBSERVABLE_BASE::IMPL>
token_;
125template <
typename ObserverInterface>
148 OBSERVABLE_BASE::add_observer(
static_cast<void*
>( aObserver ) );
159 OBSERVABLE_BASE::add_observer(
static_cast<void*
>( aObserver ) );
160 return LINK(
impl_,
static_cast<void*
>( aObserver ) );
172 OBSERVABLE_BASE::remove_observer(
static_cast<void*
>( aObserver ) );
181 template <
typename... Args1,
typename... Args2>
182 void Notify(
void ( ObserverInterface::*Ptr )( Args1... ), Args2&&... aArgs )
184 static_assert(
sizeof...( Args1 ) ==
sizeof...( Args2 ),
"argument counts don't match" );
191 for(
auto* void_ptr :
impl_->observers_ )
195 auto* typed_ptr =
static_cast<ObserverInterface*
>( void_ptr );
196 ( typed_ptr->*Ptr )( std::forward<Args2>( aArgs )... );
217 template <
typename... Args1,
typename... Args2>
218 void NotifyIgnore(
void ( ObserverInterface::*Ptr )( Args1... ), ObserverInterface* aIgnore,
221 static_assert(
sizeof...( Args1 ) ==
sizeof...( Args2 ),
"argument counts don't match" );
229 for(
auto* void_ptr :
impl_->observers_ )
231 if( void_ptr && void_ptr != aIgnore )
233 auto* typed_ptr =
static_cast<ObserverInterface*
>( void_ptr );
234 ( 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_
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_