ucb/source/ucp/file/bc.cxx | 85 ++++++++++++++++------------------------ ucb/source/ucp/file/bc.hxx | 10 ++-- ucb/source/ucp/file/filnot.cxx | 48 +++++++++++----------- ucb/source/ucp/file/filnot.hxx | 27 ++++++------ ucb/source/ucp/file/filtask.cxx | 68 ++++++++++++++++---------------- ucb/source/ucp/file/filtask.hxx | 24 +++++------ 6 files changed, 124 insertions(+), 138 deletions(-)
New commits: commit 2c9ead762dce6f75350f71e6418a81afe0d89092 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Mon Aug 9 09:11:43 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Aug 9 12:37:55 2021 +0200 can pass PropertyChangeNotifier around by value Change-Id: I0e88d5d9dc8dcfdf3310311038104fed2895119a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120195 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/ucb/source/ucp/file/bc.cxx b/ucb/source/ucp/file/bc.cxx index b21ba9f40175..7460fbbd23f1 100644 --- a/ucb/source/ucp/file/bc.cxx +++ b/ucb/source/ucp/file/bc.cxx @@ -1079,27 +1079,24 @@ void BaseContent::endTask( sal_Int32 CommandId ) } -std::unique_ptr<ContentEventNotifier> +std::optional<ContentEventNotifier> BaseContent::cDEL() { osl::MutexGuard aGuard( m_aMutex ); m_nState |= Deleted; - std::unique_ptr<ContentEventNotifier> p; - if( m_pContentEventListeners ) - { - p.reset( new ContentEventNotifier( m_pMyShell, - this, - m_xContentIdentifier, - m_pContentEventListeners->getElements() ) ); - } + if( !m_pContentEventListeners ) + return {}; - return p; + return ContentEventNotifier( m_pMyShell, + this, + m_xContentIdentifier, + m_pContentEventListeners->getElements() ); } -std::unique_ptr<ContentEventNotifier> +std::optional<ContentEventNotifier> BaseContent::cEXC( const OUString& aNewName ) { osl::MutexGuard aGuard( m_aMutex ); @@ -1108,72 +1105,60 @@ BaseContent::cEXC( const OUString& aNewName ) m_aUncPath = aNewName; m_xContentIdentifier = new FileContentIdentifier( aNewName ); - std::unique_ptr<ContentEventNotifier> p; - if( m_pContentEventListeners ) - p.reset( new ContentEventNotifier( m_pMyShell, - this, - m_xContentIdentifier, - xOldRef, - m_pContentEventListeners->getElements() ) ); - - return p; + if( !m_pContentEventListeners ) + return {}; + return ContentEventNotifier( m_pMyShell, + this, + m_xContentIdentifier, + xOldRef, + m_pContentEventListeners->getElements() ); } -std::unique_ptr<ContentEventNotifier> +std::optional<ContentEventNotifier> BaseContent::cCEL() { osl::MutexGuard aGuard( m_aMutex ); - std::unique_ptr<ContentEventNotifier> p; - if( m_pContentEventListeners ) - p.reset( new ContentEventNotifier( m_pMyShell, + if( !m_pContentEventListeners ) + return {}; + return ContentEventNotifier( m_pMyShell, this, m_xContentIdentifier, - m_pContentEventListeners->getElements() ) ); - - return p; + m_pContentEventListeners->getElements() ); } -std::unique_ptr<PropertySetInfoChangeNotifier> +std::optional<PropertySetInfoChangeNotifier> BaseContent::cPSL() { osl::MutexGuard aGuard( m_aMutex ); - std::unique_ptr<PropertySetInfoChangeNotifier> p; - if( m_pPropertySetInfoChangeListeners ) - p.reset( new PropertySetInfoChangeNotifier( this, - m_pPropertySetInfoChangeListeners->getElements() ) ); - - return p; + if( !m_pPropertySetInfoChangeListeners ) + return {}; + return PropertySetInfoChangeNotifier( this, m_pPropertySetInfoChangeListeners->getElements() ); } -std::unique_ptr<PropertyChangeNotifier> +std::optional<PropertyChangeNotifier> BaseContent::cPCL() { osl::MutexGuard aGuard( m_aMutex ); if (!m_pPropertyListener) - return nullptr; + return {}; const std::vector< OUString > seqNames = m_pPropertyListener->getContainedTypes(); + if( seqNames.empty() ) + return {}; - std::unique_ptr<PropertyChangeNotifier> p; - - if( !seqNames.empty() ) + ListenerMap listener; + for( const auto& rName : seqNames ) { - ListenerMap listener; - for( const auto& rName : seqNames ) - { - comphelper::OInterfaceContainerHelper2* pContainer = m_pPropertyListener->getContainer(rName); - if (!pContainer) - continue; - listener[rName] = pContainer->getElements(); - } - - p.reset( new PropertyChangeNotifier( this, std::move(listener) ) ); + comphelper::OInterfaceContainerHelper2* pContainer = m_pPropertyListener->getContainer(rName); + if (!pContainer) + continue; + listener[rName] = pContainer->getElements(); } - return p; + return PropertyChangeNotifier( this, std::move(listener) ); } diff --git a/ucb/source/ucp/file/bc.hxx b/ucb/source/ucp/file/bc.hxx index 2810b0a4d2ad..4b28b343652a 100644 --- a/ucb/source/ucp/file/bc.hxx +++ b/ucb/source/ucp/file/bc.hxx @@ -184,11 +184,11 @@ namespace fileaccess { // Notifier - std::unique_ptr<ContentEventNotifier> cDEL() override; - std::unique_ptr<ContentEventNotifier> cEXC( const OUString& aNewName ) override; - std::unique_ptr<ContentEventNotifier> cCEL() override; - std::unique_ptr<PropertySetInfoChangeNotifier> cPSL() override; - std::unique_ptr<PropertyChangeNotifier> cPCL() override; + std::optional<ContentEventNotifier> cDEL() override; + std::optional<ContentEventNotifier> cEXC( const OUString& aNewName ) override; + std::optional<ContentEventNotifier> cCEL() override; + std::optional<PropertySetInfoChangeNotifier> cPSL() override; + std::optional<PropertyChangeNotifier> cPCL() override; private: // Data members diff --git a/ucb/source/ucp/file/filnot.cxx b/ucb/source/ucp/file/filnot.cxx index 93d1d5f21f1f..f63f83f9e515 100644 --- a/ucb/source/ucp/file/filnot.cxx +++ b/ucb/source/ucp/file/filnot.cxx @@ -57,7 +57,7 @@ ContentEventNotifier::ContentEventNotifier( TaskManager* pMyShell, } -void ContentEventNotifier::notifyChildInserted( const OUString& aChildName ) +void ContentEventNotifier::notifyChildInserted( const OUString& aChildName ) const { rtl::Reference<FileContentIdentifier> xChildId = new FileContentIdentifier( aChildName ); @@ -76,7 +76,7 @@ void ContentEventNotifier::notifyChildInserted( const OUString& aChildName ) } } -void ContentEventNotifier::notifyDeleted() +void ContentEventNotifier::notifyDeleted() const { ContentEvent aEvt( m_xCreatorContent, @@ -94,7 +94,7 @@ void ContentEventNotifier::notifyDeleted() } -void ContentEventNotifier::notifyRemoved( const OUString& aChildName ) +void ContentEventNotifier::notifyRemoved( const OUString& aChildName ) const { rtl::Reference<FileContentIdentifier> xChildId = new FileContentIdentifier( aChildName ); @@ -117,7 +117,7 @@ void ContentEventNotifier::notifyRemoved( const OUString& aChildName ) } } -void ContentEventNotifier::notifyExchanged() +void ContentEventNotifier::notifyExchanged() const { ContentEvent aEvt( m_xCreatorContent, ContentAction::EXCHANGED, @@ -150,7 +150,7 @@ PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier( void -PropertySetInfoChangeNotifier::notifyPropertyAdded( const OUString & aPropertyName ) +PropertySetInfoChangeNotifier::notifyPropertyAdded( const OUString & aPropertyName ) const { beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent, aPropertyName, @@ -167,7 +167,7 @@ PropertySetInfoChangeNotifier::notifyPropertyAdded( const OUString & aPropertyNa void -PropertySetInfoChangeNotifier::notifyPropertyRemoved( const OUString & aPropertyName ) +PropertySetInfoChangeNotifier::notifyPropertyRemoved( const OUString & aPropertyName ) const { beans::PropertySetInfoChangeEvent aEvt( m_xCreatorContent, aPropertyName, @@ -199,13 +199,8 @@ PropertyChangeNotifier::PropertyChangeNotifier( } -PropertyChangeNotifier::~PropertyChangeNotifier() -{ -} - - void PropertyChangeNotifier::notifyPropertyChanged( - const uno::Sequence< beans::PropertyChangeEvent >& seqChanged ) + const uno::Sequence< beans::PropertyChangeEvent >& seqChanged ) const { uno::Sequence< beans::PropertyChangeEvent > Changes = seqChanged; @@ -214,13 +209,17 @@ void PropertyChangeNotifier::notifyPropertyChanged( // notify listeners for all Events - std::vector< uno::Reference< uno::XInterface > >& seqList = m_aListeners[ OUString() ]; - for( const auto& rListener : std::as_const(seqList) ) + auto it = m_aListeners.find( OUString() ); + if (it != m_aListeners.end()) { - uno::Reference< beans::XPropertiesChangeListener > aListener( rListener,uno::UNO_QUERY ); - if( aListener.is() ) + const std::vector< uno::Reference< uno::XInterface > >& seqList = it->second; + for( const auto& rListener : seqList ) { - aListener->propertiesChange( Changes ); + uno::Reference< beans::XPropertiesChangeListener > aListener( rListener,uno::UNO_QUERY ); + if( aListener.is() ) + { + aListener->propertiesChange( Changes ); + } } } @@ -228,14 +227,17 @@ void PropertyChangeNotifier::notifyPropertyChanged( for( const auto& rChange : std::as_const(Changes) ) { seq[0] = rChange; - seqList = m_aListeners[ rChange.PropertyName ]; - - for( const auto& rListener : std::as_const(seqList) ) + it = m_aListeners.find( rChange.PropertyName ); + if (it != m_aListeners.end()) { - uno::Reference< beans::XPropertiesChangeListener > aListener( rListener,uno::UNO_QUERY ); - if( aListener.is() ) + const std::vector< uno::Reference< uno::XInterface > >& seqList = it->second; + for( const auto& rListener : seqList ) { - aListener->propertiesChange( seq ); + uno::Reference< beans::XPropertiesChangeListener > aListener( rListener,uno::UNO_QUERY ); + if( aListener.is() ) + { + aListener->propertiesChange( seq ); + } } } } diff --git a/ucb/source/ucp/file/filnot.hxx b/ucb/source/ucp/file/filnot.hxx index daeffb8b11ba..bae7f6a038dd 100644 --- a/ucb/source/ucp/file/filnot.hxx +++ b/ucb/source/ucp/file/filnot.hxx @@ -24,6 +24,7 @@ #include <com/sun/star/ucb/XContentIdentifier.hpp> #include <com/sun/star/ucb/XContent.hpp> #include <memory> +#include <optional> #include <unordered_map> #include <vector> @@ -54,10 +55,10 @@ namespace fileaccess { const css::uno::Reference< css::ucb::XContentIdentifier >& xOldId, const std::vector< css::uno::Reference< css::uno::XInterface > >& sListeners ); - void notifyChildInserted( const OUString& aChildName ); - void notifyDeleted(); - void notifyRemoved( const OUString& aChildName ); - void notifyExchanged( ); + void notifyChildInserted( const OUString& aChildName ) const; + void notifyDeleted() const; + void notifyRemoved( const OUString& aChildName ) const; + void notifyExchanged() const; }; @@ -71,8 +72,8 @@ namespace fileaccess { const css::uno::Reference< css::ucb::XContent >& xCreatorContent, const std::vector< css::uno::Reference< css::uno::XInterface > >& sListeners ); - void notifyPropertyAdded( const OUString & aPropertyName ); - void notifyPropertyRemoved( const OUString & aPropertyName ); + void notifyPropertyAdded( const OUString & aPropertyName ) const; + void notifyPropertyRemoved( const OUString & aPropertyName ) const; }; @@ -89,10 +90,8 @@ namespace fileaccess { const css::uno::Reference< css::ucb::XContent >& xCreatorContent, ListenerMap&& pListeners ); - ~PropertyChangeNotifier(); - void notifyPropertyChanged( - const css::uno::Sequence< css::beans::PropertyChangeEvent >& seqChanged ); + const css::uno::Sequence< css::beans::PropertyChangeEvent >& seqChanged ) const; }; @@ -100,12 +99,12 @@ namespace fileaccess { { public: // Side effect of this function is the change of the name - virtual std::unique_ptr<ContentEventNotifier> cEXC( const OUString& aNewName ) = 0; + virtual std::optional<ContentEventNotifier> cEXC( const OUString& aNewName ) = 0; // Side effect is the change of the state of the object to "deleted". - virtual std::unique_ptr<ContentEventNotifier> cDEL() = 0; - virtual std::unique_ptr<ContentEventNotifier> cCEL() = 0; - virtual std::unique_ptr<PropertySetInfoChangeNotifier> cPSL() = 0; - virtual std::unique_ptr<PropertyChangeNotifier> cPCL() = 0; + virtual std::optional<ContentEventNotifier> cDEL() = 0; + virtual std::optional<ContentEventNotifier> cCEL() = 0; + virtual std::optional<PropertySetInfoChangeNotifier> cPSL() = 0; + virtual std::optional<PropertyChangeNotifier> cPCL() = 0; protected: ~Notifier() {} diff --git a/ucb/source/ucp/file/filtask.cxx b/ucb/source/ucp/file/filtask.cxx index 221f33c7c937..990b509b4f37 100644 --- a/ucb/source/ucp/file/filtask.cxx +++ b/ucb/source/ucp/file/filtask.cxx @@ -2536,10 +2536,10 @@ TaskManager::getv( // EventListener -std::vector< std::unique_ptr< ContentEventNotifier > > +std::vector< ContentEventNotifier > TaskManager::getContentEventListeners( const OUString& aName ) { - std::vector< std::unique_ptr<ContentEventNotifier> > listeners; + std::vector< ContentEventNotifier > listeners; { osl::MutexGuard aGuard( m_aMutex ); TaskManager::ContentMap::iterator it = m_aContent.find( aName ); @@ -2548,9 +2548,9 @@ TaskManager::getContentEventListeners( const OUString& aName ) std::vector<Notifier*>& listOfNotifiers = it->second.notifier; for (auto const& pointer : listOfNotifiers) { - std::unique_ptr<ContentEventNotifier> notifier = pointer->cCEL(); + std::optional<ContentEventNotifier> notifier = pointer->cCEL(); if( notifier ) - listeners.push_back( std::move(notifier) ); + listeners.push_back( std::move(*notifier) ); } } } @@ -2558,10 +2558,10 @@ TaskManager::getContentEventListeners( const OUString& aName ) } -std::vector< std::unique_ptr<ContentEventNotifier> > +std::vector< ContentEventNotifier > TaskManager::getContentDeletedEventListeners( const OUString& aName ) { - std::vector< std::unique_ptr< ContentEventNotifier > > listeners; + std::vector< ContentEventNotifier > listeners; { osl::MutexGuard aGuard( m_aMutex ); TaskManager::ContentMap::iterator it = m_aContent.find( aName ); @@ -2570,47 +2570,47 @@ TaskManager::getContentDeletedEventListeners( const OUString& aName ) std::vector<Notifier*>& listOfNotifiers = it->second.notifier; for (auto const& pointer : listOfNotifiers) { - std::unique_ptr<ContentEventNotifier> notifier = pointer->cDEL(); + std::optional<ContentEventNotifier> notifier = pointer->cDEL(); if( notifier ) - listeners.push_back( std::move(notifier) ); + listeners.push_back( std::move(*notifier) ); } } } return listeners; } -void TaskManager::notifyInsert(const std::vector<std::unique_ptr<ContentEventNotifier>>& listeners, +void TaskManager::notifyInsert(const std::vector<ContentEventNotifier>& listeners, const OUString& aChildName) { for (const auto & l : listeners ) { - l->notifyChildInserted( aChildName ); + l.notifyChildInserted( aChildName ); } } void TaskManager::notifyContentDeleted( - const std::vector<std::unique_ptr<ContentEventNotifier>>& listeners) + const std::vector<ContentEventNotifier>& listeners) { for( auto const & l : listeners ) { - l->notifyDeleted(); + l.notifyDeleted(); } } void TaskManager::notifyContentRemoved( - const std::vector<std::unique_ptr<ContentEventNotifier>>& listeners, const OUString& aChildName) + const std::vector<ContentEventNotifier>& listeners, const OUString& aChildName) { for( auto const & l : listeners ) { - l->notifyRemoved( aChildName ); + l.notifyRemoved( aChildName ); } } -std::vector< std::unique_ptr< PropertySetInfoChangeNotifier > > +std::vector< PropertySetInfoChangeNotifier > TaskManager::getPropertySetListeners( const OUString& aName ) { - std::vector< std::unique_ptr< PropertySetInfoChangeNotifier > > listeners; + std::vector< PropertySetInfoChangeNotifier > listeners; { osl::MutexGuard aGuard( m_aMutex ); TaskManager::ContentMap::iterator it = m_aContent.find( aName ); @@ -2619,9 +2619,9 @@ TaskManager::getPropertySetListeners( const OUString& aName ) std::vector<Notifier*>& listOfNotifiers = it->second.notifier; for (auto const& pointer : listOfNotifiers) { - std::unique_ptr<PropertySetInfoChangeNotifier> notifier = pointer->cPSL(); + std::optional<PropertySetInfoChangeNotifier> notifier = pointer->cPSL(); if( notifier ) - listeners.push_back( std::move(notifier) ); + listeners.push_back( std::move(*notifier) ); } } } @@ -2629,32 +2629,32 @@ TaskManager::getPropertySetListeners( const OUString& aName ) } void TaskManager::notifyPropertyAdded( - const std::vector<std::unique_ptr<PropertySetInfoChangeNotifier>>& listeners, + const std::vector<PropertySetInfoChangeNotifier>& listeners, const OUString& aPropertyName) { for( auto const & l : listeners ) { - l->notifyPropertyAdded( aPropertyName ); + l.notifyPropertyAdded( aPropertyName ); } } void TaskManager::notifyPropertyRemoved( - const std::vector<std::unique_ptr<PropertySetInfoChangeNotifier>>& listeners, + const std::vector<PropertySetInfoChangeNotifier>& listeners, const OUString& aPropertyName) { for( auto const & l : listeners ) { - l->notifyPropertyRemoved( aPropertyName ); + l.notifyPropertyRemoved( aPropertyName ); } } -std::vector< std::unique_ptr< ContentEventNotifier > > +std::vector< ContentEventNotifier > TaskManager::getContentExchangedEventListeners( const OUString& aOldPrefix, const OUString& aNewPrefix, bool withChildren ) { - std::vector< std::unique_ptr< ContentEventNotifier > > aVector; + std::vector< ContentEventNotifier > aVector; sal_Int32 count; OUString aOldName; @@ -2714,9 +2714,9 @@ TaskManager::getContentExchangedEventListeners( const OUString& aOldPrefix, std::vector<Notifier*>& listOfNotifiers = itnew->second.notifier; for (auto const& pointer : listOfNotifiers) { - std::unique_ptr<ContentEventNotifier> notifier = pointer->cEXC( aNewName ); + std::optional<ContentEventNotifier> notifier = pointer->cEXC( aNewName ); if( notifier ) - aVector.push_back( std::move(notifier) ); + aVector.push_back( std::move(*notifier) ); } } @@ -2733,19 +2733,19 @@ TaskManager::getContentExchangedEventListeners( const OUString& aOldPrefix, } void TaskManager::notifyContentExchanged( - const std::vector<std::unique_ptr<ContentEventNotifier>>& listeners_vec) + const std::vector<ContentEventNotifier>& listeners_vec) { for( auto & l : listeners_vec) { - l->notifyExchanged(); + l.notifyExchanged(); } } -std::vector< std::unique_ptr<PropertyChangeNotifier> > +std::vector< PropertyChangeNotifier > TaskManager::getPropertyChangeNotifier( const OUString& aName ) { - std::vector< std::unique_ptr<PropertyChangeNotifier> > listeners; + std::vector< PropertyChangeNotifier > listeners; { osl::MutexGuard aGuard( m_aMutex ); TaskManager::ContentMap::iterator it = m_aContent.find( aName ); @@ -2754,9 +2754,9 @@ TaskManager::getPropertyChangeNotifier( const OUString& aName ) std::vector<Notifier*>& listOfNotifiers = it->second.notifier; for (auto const& pointer : listOfNotifiers) { - std::unique_ptr<PropertyChangeNotifier> notifier = pointer->cPCL(); + std::optional<PropertyChangeNotifier> notifier = pointer->cPCL(); if( notifier ) - listeners.push_back( std::move(notifier) ); + listeners.push_back( std::move(*notifier) ); } } } @@ -2764,12 +2764,12 @@ TaskManager::getPropertyChangeNotifier( const OUString& aName ) } void TaskManager::notifyPropertyChanges( - const std::vector<std::unique_ptr<PropertyChangeNotifier>>& listeners, + const std::vector<PropertyChangeNotifier>& listeners, const uno::Sequence<beans::PropertyChangeEvent>& seqChanged) { for( auto const & l : listeners ) { - l->notifyPropertyChanged( seqChanged ); + l.notifyPropertyChanged( seqChanged ); } } diff --git a/ucb/source/ucp/file/filtask.hxx b/ucb/source/ucp/file/filtask.hxx index 3440ec0d5947..f8d070a4f36d 100644 --- a/ucb/source/ucp/file/filtask.hxx +++ b/ucb/source/ucp/file/filtask.hxx @@ -490,21 +490,21 @@ namespace fileaccess /* get eventListeners */ /********************************************************************************/ - std::vector< std::unique_ptr< ContentEventNotifier > > + std::vector< ContentEventNotifier > getContentEventListeners( const OUString& aName ); - std::vector< std::unique_ptr< ContentEventNotifier > > + std::vector< ContentEventNotifier > getContentDeletedEventListeners( const OUString& aName ); - std::vector< std::unique_ptr < ContentEventNotifier > > + std::vector< ContentEventNotifier > getContentExchangedEventListeners( const OUString& aOldPrefix, const OUString& aNewPrefix, bool withChildren ); - std::vector< std::unique_ptr< PropertyChangeNotifier > > + std::vector< PropertyChangeNotifier > getPropertyChangeNotifier( const OUString& aName ); - std::vector< std::unique_ptr< PropertySetInfoChangeNotifier > > + std::vector< PropertySetInfoChangeNotifier > getPropertySetListeners( const OUString& aName ); @@ -513,29 +513,29 @@ namespace fileaccess /********************************************************************************/ static void notifyPropertyChanges( - const std::vector<std::unique_ptr<PropertyChangeNotifier>>& listeners, + const std::vector<PropertyChangeNotifier>& listeners, const css::uno::Sequence<css::beans::PropertyChangeEvent>& seqChanged); static void notifyContentExchanged( - const std::vector<std::unique_ptr<ContentEventNotifier>>& listeners_vec); + const std::vector<ContentEventNotifier>& listeners_vec); static void - notifyInsert(const std::vector<std::unique_ptr<ContentEventNotifier>>& listeners, + notifyInsert(const std::vector<ContentEventNotifier>& listeners, const OUString& aChildName); static void - notifyContentDeleted(const std::vector<std::unique_ptr<ContentEventNotifier>>& listeners); + notifyContentDeleted(const std::vector<ContentEventNotifier>& listeners); static void - notifyContentRemoved(const std::vector<std::unique_ptr<ContentEventNotifier>>& listeners, + notifyContentRemoved(const std::vector<ContentEventNotifier>& listeners, const OUString& aChildName); static void notifyPropertyAdded( - const std::vector<std::unique_ptr<PropertySetInfoChangeNotifier>>& listeners, + const std::vector<PropertySetInfoChangeNotifier>& listeners, const OUString& aPropertyName); static void notifyPropertyRemoved( - const std::vector<std::unique_ptr<PropertySetInfoChangeNotifier>>& listeners, + const std::vector<PropertySetInfoChangeNotifier>& listeners, const OUString& aPropertyName); /********************************************************************************/