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_;
125 template <
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 )... );
void operator=(const LINK &)=delete
bool is_iterating() const
OBSERVABLE_BASE * owned_by_
OBSERVABLE()
Construct an observable with empty non-shared subscription list.
std::vector< void * > observers_
LINK Subscribe(ObserverInterface *aObserver)
Add a subscription returning an RAII link.
std::shared_ptr< IMPL > impl_
void SubscribeUnmanaged(ObserverInterface *aObserver)
Add a subscription without RAII link.
Simple RAII-handle to a subscription.
void add_observer(void *observer)
std::shared_ptr< DETAIL::OBSERVABLE_BASE::IMPL > token_
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.
unsigned int iteration_count_
OBSERVABLE(OBSERVABLE &aInherit)
Construct an observable with a shared subscription list.
std::shared_ptr< IMPL > get_shared_impl()
void allocate_shared_impl()
void add_observer(void *observer)
A model subscriber implementation using links to represent connections.
void remove_observer(void *observer)
void on_observers_empty()
void Unsubscribe(ObserverInterface *aObserver)
Cancel the subscription of a subscriber.
IMPL(OBSERVABLE_BASE *owned_by=nullptr)
void remove_observer(void *observer)