19#ifndef INCLUDED_SLIDESHOW_SOURCE_INC_LISTENERCONTAINER_HXX
20#define INCLUDED_SLIDESHOW_SOURCE_INC_LISTENERCONTAINER_HXX
42template<
typename result_type,
typename ListenerTargetT >
struct FunctionApply
44 template<
typename FuncT>
static bool apply(
46 ListenerTargetT
const& rArg )
52template<
typename ListenerTargetT>
struct FunctionApply<void,ListenerTargetT>
54 template<
typename FuncT>
static bool apply(
56 ListenerTargetT
const& rArg )
66 template<
typename ContainerT,
73 return std::any_of( rContainer.begin(),
79 template<
typename ContainerT,
85 for(
const auto& rCurr : rContainer )
87 if(
FunctionApply< typename ::std::invoke_result< FuncT, const typename ContainerT::value_type& >::type,
88 typename ContainerT::value_type >::apply(
102 template<
typename ContainerT >
108template<
typename ListenerTargetT >
111 template<
typename ContainerT,
116 for(
const auto& rCurr : rContainer )
118 std::shared_ptr<ListenerTargetT> pListener( rCurr.lock() );
120 if( pListener && func(pListener) )
127 template<
typename ContainerT,
133 for(
const auto& rCurr : rContainer )
135 std::shared_ptr<ListenerTargetT> pListener( rCurr.lock() );
137 if( pListener.get() &&
138 FunctionApply<typename ::std::invoke_result<FuncT, std::shared_ptr<ListenerTargetT>
const&>::type,
139 std::shared_ptr<ListenerTargetT> >::apply(func,pListener) )
147 template<
typename ContainerT >
149 size_t nSizeThreshold )
151 if( rContainer.size() <= nSizeThreshold )
154 ContainerT aAliveListeners;
155 aAliveListeners.reserve(rContainer.size());
157 for(
const auto& rCurr : rContainer )
159 if( !rCurr.expired() )
160 aAliveListeners.push_back( rCurr );
163 std::swap( rContainer, aAliveListeners );
187template<
typename ListenerT,
188 typename MutexHolderBaseT,
189 typename ContainerT=std::vector<ListenerT>,
192 typedef typename MutexHolderBaseT::Guard
Guard;
219 const typename container_type::const_iterator aEnd(
maListeners.end() );
222 rListener ) != aEnd )
247 MaxDeceasedListenerUllage);
285 MaxDeceasedListenerUllage);
302 const typename container_type::iterator aEnd(
maListeners.end() );
303 typename container_type::iterator aIter;
306 rListener)) == aEnd )
336 template<
typename FuncT >
bool apply( FuncT func )
const
351 Guard aGuard2(*
this);
354 MaxDeceasedListenerUllage);
372 template<
typename FuncT >
bool applyAll( FuncT func )
const
387 Guard aGuard2(*
this);
390 MaxDeceasedListenerUllage);
406template<
typename ListenerT,
407 typename ContainerT=std::vector<ListenerT> >
Container for objects that can be notified.
bool isAdded(listener_type const &rListener) const
Check whether given listener is already added.
bool apply(FuncT func) const
Apply functor to one listener.
ContainerT container_type
bool remove(listener_type const &rListener)
Remove listener from container.
bool isEmpty() const
Check whether listener container is empty.
bool applyAll(FuncT func) const
Apply functor to all listeners.
MutexHolderBaseT::ClearableGuard ClearableGuard
bool addSorted(listener_type const &rListener)
Add new listener into sorted container.
MutexHolderBaseT::Guard Guard
void clear()
Removes all listeners in one go.
void add(listener_type const &rListener)
Add new listener.
ListenerContainer variant that does not serialize access.
EmptyClearableGuard(EmptyBase)
EmptyClearableGuard ClearableGuard
static bool apply(FuncT func, ListenerTargetT const &rArg)
static bool apply(FuncT func, ListenerTargetT const &rArg)
static bool notifyAllListeners(ContainerT &rContainer, FuncT func)
static void pruneListeners(ContainerT &rContainer, size_t nSizeThreshold)
static bool notifySingleListener(ContainerT &rContainer, FuncT func)
static bool notifyAllListeners(ContainerT &rContainer, FuncT func)
Notify all listeners.
static bool notifySingleListener(ContainerT &rContainer, FuncT func)
Notify a single one of the listeners.
static void pruneListeners(ContainerT &, size_t)
Prune container from deceased listeners.