summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-09-26 13:56:59 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-09-28 09:04:16 +0200
commit12c953fa25cc6c1e56eff6429f73cac8e870a58e (patch)
treeb982e6a3823330932f1287400bf365df6ad51262
parentb1f9aa5f58ea322097998839e00d95fc40be8b22 (diff)
loplugin:useuniqueptr in DocumentListsManager
Change-Id: Id179245161d707e27e009b6ebc53d925aae5ce0f Reviewed-on: https://gerrit.libreoffice.org/61000 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/inc/IDocumentListsAccess.hxx1
-rw-r--r--sw/source/core/doc/DocumentListsManager.cxx46
-rw-r--r--sw/source/core/inc/DocumentListsManager.hxx7
3 files changed, 12 insertions, 42 deletions
diff --git a/sw/inc/IDocumentListsAccess.hxx b/sw/inc/IDocumentListsAccess.hxx
index a6bf287b8ccd..ada66af3b574 100644
--- a/sw/inc/IDocumentListsAccess.hxx
+++ b/sw/inc/IDocumentListsAccess.hxx
@@ -31,7 +31,6 @@ class IDocumentListsAccess
public:
virtual SwList* createList( const OUString& rListId,
const OUString& rDefaultListStyleName ) = 0;
- virtual void deleteList( const OUString& rListId ) = 0;
virtual SwList* getListByName( const OUString& rListId ) const = 0;
virtual void createListForListStyle( const OUString& rListStyleName ) = 0;
diff --git a/sw/source/core/doc/DocumentListsManager.cxx b/sw/source/core/doc/DocumentListsManager.cxx
index 1fedbff2cc45..df335c2d6d9e 100644
--- a/sw/source/core/doc/DocumentListsManager.cxx
+++ b/sw/source/core/doc/DocumentListsManager.cxx
@@ -56,30 +56,19 @@ SwList* DocumentListsManager::createList( const OUString& rListId,
}
SwList* pNewList = new SwList( sListId, *pDefaultNumRuleForNewList, m_rDoc.GetNodes() );
- maLists[sListId] = pNewList;
+ maLists[sListId].reset(pNewList);
return pNewList;
}
-void DocumentListsManager::deleteList( const OUString& sListId )
-{
- SwList* pList = getListByName( sListId );
- if ( pList )
- {
- maLists.erase( sListId );
- delete pList;
- }
-}
-
SwList* DocumentListsManager::getListByName( const OUString& sListId ) const
{
SwList* pList = nullptr;
- std::unordered_map< OUString, SwList* >::const_iterator
- aListIter = maLists.find( sListId );
+ auto aListIter = maLists.find( sListId );
if ( aListIter != maLists.end() )
{
- pList = (*aListIter).second;
+ pList = (*aListIter).second.get();
}
return pList;
@@ -145,28 +134,21 @@ void DocumentListsManager::deleteListForListStyle( const OUString& sListStyleNam
if ( !sListId.isEmpty() )
{
maListStyleLists.erase( sListStyleName );
- deleteList( sListId );
+ maLists.erase( sListId );
}
}
void DocumentListsManager::deleteListsByDefaultListStyle( const OUString& rListStyleName )
{
- std::vector< SwList* > aListsForDeletion;
- tHashMapForLists::iterator aListIter = maLists.begin();
+ auto aListIter = maLists.begin();
while ( aListIter != maLists.end() )
{
- SwList* pList = (*aListIter).second;
- if ( pList->GetDefaultListStyleName() == rListStyleName )
+ if ( (*aListIter).second->GetDefaultListStyleName() == rListStyleName )
{
- aListsForDeletion.push_back( pList );
+ aListIter = maLists.erase(aListIter);
}
- ++aListIter;
- }
- while ( !aListsForDeletion.empty() )
- {
- SwList* pList = aListsForDeletion.back();
- aListsForDeletion.pop_back();
- deleteList( pList->GetListId() );
+ else
+ ++aListIter;
}
}
@@ -194,16 +176,6 @@ void DocumentListsManager::trackChangeOfListStyleName( const OUString& sListStyl
DocumentListsManager::~DocumentListsManager()
{
- for ( std::unordered_map< OUString, SwList* >::iterator
- aListIter = maLists.begin();
- aListIter != maLists.end();
- ++aListIter )
- {
- delete (*aListIter).second;
- }
- maLists.clear();
-
- maListStyleLists.clear();
}
diff --git a/sw/source/core/inc/DocumentListsManager.hxx b/sw/source/core/inc/DocumentListsManager.hxx
index dc6bdc2a5a88..ab02ab41fe8d 100644
--- a/sw/source/core/inc/DocumentListsManager.hxx
+++ b/sw/source/core/inc/DocumentListsManager.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_SW_SOURCE_CORE_INC_DOCUMENTLISTSMANAGER_HXX
#include <IDocumentListsAccess.hxx>
+#include <memory>
#include <unordered_map>
class SwList;
@@ -38,7 +39,6 @@ class DocumentListsManager : public IDocumentListsAccess
SwList* createList( const OUString& rListId,
const OUString& rDefaultListStyleName ) override;
- void deleteList( const OUString& rListId ) override;
SwList* getListByName( const OUString& rListId ) const override;
void createListForListStyle( const OUString& rListStyleName ) override;
@@ -57,11 +57,10 @@ class DocumentListsManager : public IDocumentListsAccess
SwDoc& m_rDoc;
- typedef std::unordered_map<OUString, SwList*> tHashMapForLists;
// container to hold the lists of the text document
- tHashMapForLists maLists;
+ std::unordered_map<OUString, std::unique_ptr<SwList>> maLists;
// relation between list style and its default list
- tHashMapForLists maListStyleLists;
+ std::unordered_map<OUString, SwList*> maListStyleLists;
const OUString CreateUniqueListId();
const OUString MakeListIdUnique( const OUString& aSuggestedUniqueListId );