make memory management more explicit in BaseContext

Change-Id: I3afdfd7b461c6eccc57c23314f992900d14bd7d8
Reviewed-on: https://gerrit.libreoffice.org/48708
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2018-01-23 15:55:36 +02:00
parent 1168956b91
commit 03f427793b
6 changed files with 93 additions and 138 deletions

View File

@@ -1174,29 +1174,27 @@ void BaseContent::endTask( sal_Int32 CommandId )
}
ContentEventNotifier*
std::unique_ptr<ContentEventNotifier>
BaseContent::cDEL()
{
osl::MutexGuard aGuard( m_aMutex );
m_nState |= Deleted;
ContentEventNotifier* p;
std::unique_ptr<ContentEventNotifier> p;
if( m_pContentEventListeners )
{
p = new ContentEventNotifier( m_pMyShell,
p.reset( new ContentEventNotifier( m_pMyShell,
this,
m_xContentIdentifier,
m_pContentEventListeners->getElements() );
m_pContentEventListeners->getElements() ) );
}
else
p = nullptr;
return p;
}
ContentEventNotifier*
std::unique_ptr<ContentEventNotifier>
BaseContent::cEXC( const OUString& aNewName )
{
osl::MutexGuard aGuard( m_aMutex );
@@ -1206,46 +1204,46 @@ BaseContent::cEXC( const OUString& aNewName )
FileContentIdentifier* pp = new FileContentIdentifier( aNewName );
m_xContentIdentifier.set( pp );
ContentEventNotifier* p = nullptr;
std::unique_ptr<ContentEventNotifier> p;
if( m_pContentEventListeners )
p = new ContentEventNotifier( m_pMyShell,
p.reset( new ContentEventNotifier( m_pMyShell,
this,
m_xContentIdentifier,
xOldRef,
m_pContentEventListeners->getElements() );
m_pContentEventListeners->getElements() ) );
return p;
}
ContentEventNotifier*
std::unique_ptr<ContentEventNotifier>
BaseContent::cCEL()
{
osl::MutexGuard aGuard( m_aMutex );
ContentEventNotifier* p = nullptr;
std::unique_ptr<ContentEventNotifier> p;
if( m_pContentEventListeners )
p = new ContentEventNotifier( m_pMyShell,
p.reset( new ContentEventNotifier( m_pMyShell,
this,
m_xContentIdentifier,
m_pContentEventListeners->getElements() );
m_pContentEventListeners->getElements() ) );
return p;
}
PropertySetInfoChangeNotifier*
std::unique_ptr<PropertySetInfoChangeNotifier>
BaseContent::cPSL()
{
osl::MutexGuard aGuard( m_aMutex );
PropertySetInfoChangeNotifier* p = nullptr;
std::unique_ptr<PropertySetInfoChangeNotifier> p;
if( m_pPropertySetInfoChangeListeners )
p = new PropertySetInfoChangeNotifier( this,
m_pPropertySetInfoChangeListeners->getElements() );
p.reset( new PropertySetInfoChangeNotifier( this,
m_pPropertySetInfoChangeListeners->getElements() ) );
return p;
}
PropertyChangeNotifier*
std::unique_ptr<PropertyChangeNotifier>
BaseContent::cPCL()
{
osl::MutexGuard aGuard( m_aMutex );
@@ -1255,7 +1253,7 @@ BaseContent::cPCL()
Sequence< OUString > seqNames = m_pPropertyListener->getContainedTypes();
PropertyChangeNotifier* p = nullptr;
std::unique_ptr<PropertyChangeNotifier> p;
sal_Int32 length = seqNames.getLength();
@@ -1270,8 +1268,8 @@ BaseContent::cPCL()
(*listener)[seqNames[i]] = pContainer->getElements();
}
p = new PropertyChangeNotifier( this,
listener );
p.reset( new PropertyChangeNotifier( this,
listener ) );
}
return p;

View File

@@ -210,11 +210,11 @@ namespace fileaccess {
// Notifier
ContentEventNotifier* cDEL() override;
ContentEventNotifier* cEXC( const OUString& aNewName ) override;
ContentEventNotifier* cCEL() override;
PropertySetInfoChangeNotifier* cPSL() override;
PropertyChangeNotifier* cPCL() override;
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;
private:
// Data members

View File

@@ -101,12 +101,12 @@ namespace fileaccess {
{
public:
// Side effect of this function is the change of the name
virtual ContentEventNotifier* cEXC( const OUString& aNewName ) = 0;
virtual std::unique_ptr<ContentEventNotifier> cEXC( const OUString& aNewName ) = 0;
// Side effect is the change of the state of the object to "deleted".
virtual ContentEventNotifier* cDEL() = 0;
virtual ContentEventNotifier* cCEL() = 0;
virtual PropertySetInfoChangeNotifier* cPSL() = 0;
virtual PropertyChangeNotifier* cPCL() = 0;
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;
protected:
~Notifier() {}

View File

@@ -61,27 +61,27 @@ class XResultSet_impl : public Notifier,
virtual ~XResultSet_impl() override;
virtual ContentEventNotifier* cDEL() override
virtual std::unique_ptr<ContentEventNotifier> cDEL() override
{
return nullptr;
}
virtual ContentEventNotifier* cEXC( const OUString& ) override
virtual std::unique_ptr<ContentEventNotifier> cEXC( const OUString& ) override
{
return nullptr;
}
virtual ContentEventNotifier* cCEL() override
virtual std::unique_ptr<ContentEventNotifier> cCEL() override
{
return nullptr;
}
virtual PropertySetInfoChangeNotifier* cPSL() override
virtual std::unique_ptr<PropertySetInfoChangeNotifier> cPSL() override
{
return nullptr;
}
virtual PropertyChangeNotifier* cPCL() override
virtual std::unique_ptr<PropertyChangeNotifier> cPCL() override
{
return nullptr;
}

View File

@@ -2604,11 +2604,10 @@ TaskManager::getv(
// EventListener
std::vector< ContentEventNotifier* >*
std::vector< std::unique_ptr< ContentEventNotifier > >
TaskManager::getContentEventListeners( const OUString& aName )
{
std::vector< ContentEventNotifier* >* p = new std::vector< ContentEventNotifier* >;
std::vector< ContentEventNotifier* >& listeners = *p;
std::vector< std::unique_ptr<ContentEventNotifier> > listeners;
{
osl::MutexGuard aGuard( m_aMutex );
TaskManager::ContentMap::iterator it = m_aContent.find( aName );
@@ -2617,21 +2616,20 @@ TaskManager::getContentEventListeners( const OUString& aName )
std::vector<Notifier*>& listOfNotifiers = *( it->second.notifier );
for (auto const& pointer : listOfNotifiers)
{
ContentEventNotifier* notifier = pointer->cCEL();
std::unique_ptr<ContentEventNotifier> notifier = pointer->cCEL();
if( notifier )
listeners.push_back( notifier );
listeners.push_back( std::move(notifier) );
}
}
}
return p;
return listeners;
}
std::vector< ContentEventNotifier* >*
std::vector< std::unique_ptr<ContentEventNotifier> >
TaskManager::getContentDeletedEventListeners( const OUString& aName )
{
std::vector< ContentEventNotifier* >* p = new std::vector< ContentEventNotifier* >;
std::vector< ContentEventNotifier* >& listeners = *p;
std::vector< std::unique_ptr< ContentEventNotifier > > listeners;
{
osl::MutexGuard aGuard( m_aMutex );
TaskManager::ContentMap::iterator it = m_aContent.find( aName );
@@ -2640,64 +2638,51 @@ TaskManager::getContentDeletedEventListeners( const OUString& aName )
std::vector<Notifier*>& listOfNotifiers = *( it->second.notifier );
for (auto const& pointer : listOfNotifiers)
{
ContentEventNotifier* notifier = pointer->cDEL();
std::unique_ptr<ContentEventNotifier> notifier = pointer->cDEL();
if( notifier )
listeners.push_back( notifier );
listeners.push_back( std::move(notifier) );
}
}
}
return p;
return listeners;
}
void
TaskManager::notifyInsert( std::vector< ContentEventNotifier* >* listeners,const OUString& aChildName )
TaskManager::notifyInsert( std::vector< std::unique_ptr<ContentEventNotifier> > listeners, const OUString& aChildName )
{
std::vector< ContentEventNotifier* >::iterator it = listeners->begin();
while( it != listeners->end() )
for (const auto & l : listeners )
{
(*it)->notifyChildInserted( aChildName );
delete *it;
++it;
l->notifyChildInserted( aChildName );
}
delete listeners;
}
void
TaskManager::notifyContentDeleted( std::vector< ContentEventNotifier* >* listeners )
TaskManager::notifyContentDeleted( std::vector< std::unique_ptr< ContentEventNotifier> > listeners )
{
std::vector< ContentEventNotifier* >::iterator it = listeners->begin();
while( it != listeners->end() )
for( auto const & l : listeners )
{
(*it)->notifyDeleted();
delete *it;
++it;
l->notifyDeleted();
}
delete listeners;
}
void
TaskManager::notifyContentRemoved( std::vector< ContentEventNotifier* >* listeners,
TaskManager::notifyContentRemoved( std::vector< std::unique_ptr<ContentEventNotifier> > listeners,
const OUString& aChildName )
{
std::vector< ContentEventNotifier* >::iterator it = listeners->begin();
while( it != listeners->end() )
for( auto const & l : listeners )
{
(*it)->notifyRemoved( aChildName );
delete *it;
++it;
l->notifyRemoved( aChildName );
}
delete listeners;
}
std::vector< PropertySetInfoChangeNotifier* >*
std::vector< std::unique_ptr< PropertySetInfoChangeNotifier > >
TaskManager::getPropertySetListeners( const OUString& aName )
{
std::vector< PropertySetInfoChangeNotifier* >* p = new std::vector< PropertySetInfoChangeNotifier* >;
std::vector< PropertySetInfoChangeNotifier* >& listeners = *p;
std::vector< std::unique_ptr< PropertySetInfoChangeNotifier > > listeners;
{
osl::MutexGuard aGuard( m_aMutex );
TaskManager::ContentMap::iterator it = m_aContent.find( aName );
@@ -2706,55 +2691,44 @@ TaskManager::getPropertySetListeners( const OUString& aName )
std::vector<Notifier*>& listOfNotifiers = *( it->second.notifier );
for (auto const& pointer : listOfNotifiers)
{
PropertySetInfoChangeNotifier* notifier = pointer->cPSL();
std::unique_ptr<PropertySetInfoChangeNotifier> notifier = pointer->cPSL();
if( notifier )
listeners.push_back( notifier );
listeners.push_back( std::move(notifier) );
}
}
}
return p;
return listeners;
}
void
TaskManager::notifyPropertyAdded( std::vector< PropertySetInfoChangeNotifier* >* listeners,
TaskManager::notifyPropertyAdded( std::vector< std::unique_ptr< PropertySetInfoChangeNotifier > > listeners,
const OUString& aPropertyName )
{
std::vector< PropertySetInfoChangeNotifier* >::iterator it = listeners->begin();
while( it != listeners->end() )
for( auto const & l : listeners )
{
(*it)->notifyPropertyAdded( aPropertyName );
delete *it;
++it;
l->notifyPropertyAdded( aPropertyName );
}
delete listeners;
}
void
TaskManager::notifyPropertyRemoved( std::vector< PropertySetInfoChangeNotifier* >* listeners,
TaskManager::notifyPropertyRemoved( std::vector< std::unique_ptr< PropertySetInfoChangeNotifier > > listeners,
const OUString& aPropertyName )
{
std::vector< PropertySetInfoChangeNotifier* >::iterator it = listeners->begin();
while( it != listeners->end() )
for( auto const & l : listeners )
{
(*it)->notifyPropertyRemoved( aPropertyName );
delete *it;
++it;
l->notifyPropertyRemoved( aPropertyName );
}
delete listeners;
}
std::vector< std::vector< ContentEventNotifier* >* >*
std::vector< std::unique_ptr< ContentEventNotifier > >
TaskManager::getContentExchangedEventListeners( const OUString& aOldPrefix,
const OUString& aNewPrefix,
bool withChildren )
{
std::vector< std::vector< ContentEventNotifier* >* >* aVectorOnHeap =
new std::vector< std::vector< ContentEventNotifier* >* >;
std::vector< std::vector< ContentEventNotifier* >* >& aVector = *aVectorOnHeap;
std::vector< std::unique_ptr< ContentEventNotifier > > aVector;
sal_Int32 count;
OUString aOldName;
@@ -2785,9 +2759,6 @@ TaskManager::getContentExchangedEventListeners( const OUString& aOldPrefix,
for( sal_Int32 j = 0; j < count; ++j )
{
std::vector< ContentEventNotifier* >* p = new std::vector< ContentEventNotifier* >;
std::vector< ContentEventNotifier* >& listeners = *p;
if( withChildren )
{
aOldName = oldChildList[j];
@@ -2817,9 +2788,9 @@ TaskManager::getContentExchangedEventListeners( const OUString& aOldPrefix,
std::vector<Notifier*>& listOfNotifiers = *( itnew->second.notifier );
for (auto const& pointer : listOfNotifiers)
{
ContentEventNotifier* notifier = pointer->cEXC( aNewName );
std::unique_ptr<ContentEventNotifier> notifier = pointer->cEXC( aNewName );
if( notifier )
listeners.push_back( notifier );
aVector.push_back( std::move(notifier) );
}
}
@@ -2836,37 +2807,27 @@ TaskManager::getContentExchangedEventListeners( const OUString& aOldPrefix,
}
delete copyList;
}
aVector.push_back( p );
}
}
return aVectorOnHeap;
return aVector;
}
void
TaskManager::notifyContentExchanged( std::vector< std::vector< ContentEventNotifier* >* >* listeners_vec )
TaskManager::notifyContentExchanged( std::vector< std::unique_ptr< ContentEventNotifier > > listeners_vec )
{
for( std::vector< ContentEventNotifier* >* listeners : *listeners_vec)
for( auto & l : listeners_vec)
{
std::vector< ContentEventNotifier* >::iterator it = listeners->begin();
while( it != listeners->end() )
{
(*it)->notifyExchanged();
delete *it;
++it;
}
delete listeners;
l->notifyExchanged();
}
delete listeners_vec;
}
std::vector< PropertyChangeNotifier* >*
std::vector< std::unique_ptr<PropertyChangeNotifier> >
TaskManager::getPropertyChangeNotifier( const OUString& aName )
{
std::vector< PropertyChangeNotifier* >* p = new std::vector< PropertyChangeNotifier* >;
std::vector< PropertyChangeNotifier* >& listeners = *p;
std::vector< std::unique_ptr<PropertyChangeNotifier> > listeners;
{
osl::MutexGuard aGuard( m_aMutex );
TaskManager::ContentMap::iterator it = m_aContent.find( aName );
@@ -2875,27 +2836,23 @@ TaskManager::getPropertyChangeNotifier( const OUString& aName )
std::vector<Notifier*>& listOfNotifiers = *( it->second.notifier );
for (auto const& pointer : listOfNotifiers)
{
PropertyChangeNotifier* notifier = pointer->cPCL();
std::unique_ptr<PropertyChangeNotifier> notifier = pointer->cPCL();
if( notifier )
listeners.push_back( notifier );
listeners.push_back( std::move(notifier) );
}
}
}
return p;
return listeners;
}
void TaskManager::notifyPropertyChanges( std::vector< PropertyChangeNotifier* >* listeners,
void TaskManager::notifyPropertyChanges( std::vector< std::unique_ptr< PropertyChangeNotifier > > listeners,
const uno::Sequence< beans::PropertyChangeEvent >& seqChanged )
{
std::vector< PropertyChangeNotifier* >::iterator it = listeners->begin();
while( it != listeners->end() )
for( auto const & l : listeners )
{
(*it)->notifyPropertyChanged( seqChanged );
delete *it;
++it;
l->notifyPropertyChanged( seqChanged );
}
delete listeners;
}

View File

@@ -515,21 +515,21 @@ namespace fileaccess
/* get eventListeners */
/********************************************************************************/
std::vector< ContentEventNotifier* >*
std::vector< std::unique_ptr< ContentEventNotifier > >
getContentEventListeners( const OUString& aName );
std::vector< ContentEventNotifier* >*
std::vector< std::unique_ptr< ContentEventNotifier > >
getContentDeletedEventListeners( const OUString& aName );
std::vector< std::vector< ContentEventNotifier* >* >*
std::vector< std::unique_ptr < ContentEventNotifier > >
getContentExchangedEventListeners( const OUString& aOldPrefix,
const OUString& aNewPrefix,
bool withChildren );
std::vector< PropertyChangeNotifier* >*
std::vector< std::unique_ptr< PropertyChangeNotifier > >
getPropertyChangeNotifier( const OUString& aName );
std::vector< PropertySetInfoChangeNotifier* >*
std::vector< std::unique_ptr< PropertySetInfoChangeNotifier > >
getPropertySetListeners( const OUString& aName );
@@ -538,28 +538,28 @@ namespace fileaccess
/********************************************************************************/
static void notifyPropertyChanges(
std::vector< PropertyChangeNotifier* >* listeners,
std::vector< std::unique_ptr< PropertyChangeNotifier > > listeners,
const css::uno::Sequence< css::beans::PropertyChangeEvent >& seqChanged );
static void notifyContentExchanged(
std::vector< std::vector< ContentEventNotifier* >* >* listeners_vec );
std::vector< std::unique_ptr< ContentEventNotifier > > listeners_vec );
static void notifyInsert(
std::vector< ContentEventNotifier* >* listeners,const OUString& aChildName );
std::vector< std::unique_ptr< ContentEventNotifier > > listeners, const OUString& aChildName );
static void notifyContentDeleted(
std::vector< ContentEventNotifier* >* listeners );
std::vector< std::unique_ptr< ContentEventNotifier > > listeners );
static void notifyContentRemoved(
std::vector< ContentEventNotifier* >* listeners,
std::vector< std::unique_ptr< ContentEventNotifier > > listeners,
const OUString& aChildName );
static void notifyPropertyAdded(
std::vector< PropertySetInfoChangeNotifier* >* listeners,
std::vector< std::unique_ptr< PropertySetInfoChangeNotifier > > listeners,
const OUString& aPropertyName );
static void notifyPropertyRemoved(
std::vector< PropertySetInfoChangeNotifier* >* listeners,
std::vector< std::unique_ptr< PropertySetInfoChangeNotifier > > listeners,
const OUString& aPropertyName );