diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-09-02 16:45:54 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-09-02 19:20:01 +0200 |
commit | e161826d5766cfb0816f666f6f65a7fb25d78f33 (patch) | |
tree | a7bedf40fec180c02e2e6d3797dac786e396e55a /slideshow | |
parent | 32a96e44b4c073c7c61c94a7f0fe6108dde663bc (diff) |
tdf#127258: Fix ViewEventHandlerWeakPtrWrapper
...which had been introduced with 042e30a3dc057aef4a02d95960e4dd4fb8d083ae
"Avoid adding a function template declaration to namespace std" but without
taking the ListenerOperations<std::weak_ptr<ListenerTargetT>> partial
specialization (in slideshow/source/inc/listenercontainer.hxx) into account, so
that commit had made some confused changes to the
mpImpl->maViewHandlers.applyAll calls (that can now be reverted).
Change-Id: Iaaafc560dfd34940f1708027808ab4f9b8db7764
Reviewed-on: https://gerrit.libreoffice.org/78405
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'slideshow')
-rw-r--r-- | slideshow/source/engine/eventmultiplexer.cxx | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/slideshow/source/engine/eventmultiplexer.cxx b/slideshow/source/engine/eventmultiplexer.cxx index 1ea583da8d9c..ae915bf3a2ca 100644 --- a/slideshow/source/engine/eventmultiplexer.cxx +++ b/slideshow/source/engine/eventmultiplexer.cxx @@ -45,6 +45,7 @@ #include <functional> #include <memory> #include <algorithm> +#include <type_traits> #include <utility> #include <vector> @@ -64,6 +65,67 @@ namespace }; } +// Needed by ImplViewHandlers; see the ListenerOperations<std::weak_ptr<ListenerTargetT>> partial +// specialization in slideshow/source/inc/listenercontainer.hxx: +template<> +struct slideshow::internal::ListenerOperations<ViewEventHandlerWeakPtrWrapper> +{ + template< typename ContainerT, + typename FuncT > + static bool notifySingleListener( ContainerT& rContainer, + FuncT func ) + { + for( const auto& rCurr : rContainer ) + { + std::shared_ptr<ViewEventHandler> pListener( rCurr.ptr.lock() ); + + if( pListener && func(pListener) ) + return true; + } + + return false; + } + + template< typename ContainerT, + typename FuncT > + static bool notifyAllListeners( ContainerT& rContainer, + FuncT func ) + { + bool bRet(false); + for( const auto& rCurr : rContainer ) + { + std::shared_ptr<ViewEventHandler> pListener( rCurr.ptr.lock() ); + + if( pListener.get() && + FunctionApply<typename ::std::result_of<FuncT (std::shared_ptr<ViewEventHandler> const&)>::type, + std::shared_ptr<ViewEventHandler> >::apply(func,pListener) ) + { + bRet = true; + } + } + + return bRet; + } + template< typename ContainerT > + static void pruneListeners( ContainerT& rContainer, + size_t nSizeThreshold ) + { + if( rContainer.size() <= nSizeThreshold ) + return; + + ContainerT aAliveListeners; + aAliveListeners.reserve(rContainer.size()); + + for( const auto& rCurr : rContainer ) + { + if( !rCurr.ptr.expired() ) + aAliveListeners.push_back( rCurr ); + } + + std::swap( rContainer, aAliveListeners ); + } +}; + namespace slideshow { namespace internal { @@ -1105,8 +1167,8 @@ void EventMultiplexer::notifyViewAdded( const UnoViewSharedPtr& rView ) mpImpl->mxListener.get() ); mpImpl->maViewHandlers.applyAll( - [&rView]( const ViewEventHandlerWeakPtrWrapper& pHandler ) - { return pHandler.ptr.lock()->viewAdded( rView ); } ); + [&rView]( const ViewEventHandlerWeakPtr& pHandler ) + { return pHandler.lock()->viewAdded( rView ); } ); } void EventMultiplexer::notifyViewRemoved( const UnoViewSharedPtr& rView ) @@ -1127,15 +1189,15 @@ void EventMultiplexer::notifyViewRemoved( const UnoViewSharedPtr& rView ) mpImpl->mxListener.get() ); mpImpl->maViewHandlers.applyAll( - [&rView]( const ViewEventHandlerWeakPtrWrapper& pHandler ) - { return pHandler.ptr.lock()->viewRemoved( rView ); } ); + [&rView]( const ViewEventHandlerWeakPtr& pHandler ) + { return pHandler.lock()->viewRemoved( rView ); } ); } void EventMultiplexer::notifyViewChanged( const UnoViewSharedPtr& rView ) { mpImpl->maViewHandlers.applyAll( - [&rView]( const ViewEventHandlerWeakPtrWrapper& pHandler ) - { return pHandler.ptr.lock()->viewChanged( rView ); } ); + [&rView]( const ViewEventHandlerWeakPtr& pHandler ) + { return pHandler.lock()->viewChanged( rView ); } ); } void EventMultiplexer::notifyViewChanged( const uno::Reference<presentation::XSlideShowView>& xView ) @@ -1151,8 +1213,7 @@ void EventMultiplexer::notifyViewChanged( const uno::Reference<presentation::XSl void EventMultiplexer::notifyViewsChanged() { mpImpl->maViewHandlers.applyAll( - []( const ViewEventHandlerWeakPtrWrapper& pHandler ) - { return pHandler.ptr.lock()->viewsChanged(); } ); + std::mem_fn( &ViewEventHandler::viewsChanged )); } void EventMultiplexer::notifyViewClobbered( |