[Libreoffice-commits] core.git: slideshow/source
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Mon Sep 2 17:20:43 UTC 2019
slideshow/source/engine/eventmultiplexer.cxx | 77 ++++++++++++++++++++++++---
1 file changed, 69 insertions(+), 8 deletions(-)
New commits:
commit e161826d5766cfb0816f666f6f65a7fb25d78f33
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Mon Sep 2 16:45:54 2019 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Mon Sep 2 19:20:01 2019 +0200
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 at redhat.com>
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(
More information about the Libreoffice-commits
mailing list