diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-26 13:56:59 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-28 09:04:16 +0200 |
commit | 12c953fa25cc6c1e56eff6429f73cac8e870a58e (patch) | |
tree | b982e6a3823330932f1287400bf365df6ad51262 /sw/source | |
parent | b1f9aa5f58ea322097998839e00d95fc40be8b22 (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>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/doc/DocumentListsManager.cxx | 46 | ||||
-rw-r--r-- | sw/source/core/inc/DocumentListsManager.hxx | 7 |
2 files changed, 12 insertions, 41 deletions
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 ); |