diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-18 17:09:39 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-20 11:31:47 +0200 |
commit | b42c7f2def7425dd379204a5bd15481e840093ed (patch) | |
tree | e7897eb920b046652a431f8758d49a0567741b0d /sw | |
parent | 92fe6fed58d3166740ab00a274e4c69562b20d0e (diff) |
use std::unique_ptr in SwSortOptions
Change-Id: I5854e1492388d765a0503193a45f7c0f1bd14004
Reviewed-on: https://gerrit.libreoffice.org/43528
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/sortopt.hxx | 5 | ||||
-rw-r--r-- | sw/source/core/doc/docsort.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/doc/sortopt.cxx | 8 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj.cxx | 14 | ||||
-rw-r--r-- | sw/source/ui/misc/srtdlg.cxx | 19 |
5 files changed, 25 insertions, 23 deletions
diff --git a/sw/inc/sortopt.hxx b/sw/inc/sortopt.hxx index 964f55c3dd5b..2f1e5c064ecb 100644 --- a/sw/inc/sortopt.hxx +++ b/sw/inc/sortopt.hxx @@ -21,6 +21,7 @@ #include <rtl/ustring.hxx> #include "swdllapi.h" +#include <memory> #include <vector> enum SwSortOrder { SRT_ASCENDING, SRT_DESCENDING }; @@ -44,7 +45,9 @@ struct SW_DLLPUBLIC SwSortOptions ~SwSortOptions(); SwSortOptions(const SwSortOptions& rOpt); - std::vector<SwSortKey*> aKeys; + SwSortOptions& operator=( SwSortOptions const & ) = delete; // MSVC2015 workaround + + std::vector<std::unique_ptr<SwSortKey>> aKeys; SwSortDirection eDirection; sal_Unicode cDeli; LanguageType nLanguage; diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index 751a80ad12f8..c0111810e7c2 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -128,7 +128,7 @@ int SwSortElement::keycompare(const SwSortElement& rCmp, sal_uInt16 nKey) const // The actual comparison const SwSortElement *pOrig, *pCmp; - const SwSortKey* pSrtKey = pOptions->aKeys[ nKey ]; + const SwSortKey* pSrtKey = pOptions->aKeys[ nKey ].get(); if( pSrtKey->eSortOrder == SRT_ASCENDING ) { pOrig = this; diff --git a/sw/source/core/doc/sortopt.cxx b/sw/source/core/doc/sortopt.cxx index 6dec43953f34..57b0a9fce6d6 100644 --- a/sw/source/core/doc/sortopt.cxx +++ b/sw/source/core/doc/sortopt.cxx @@ -19,6 +19,7 @@ #include <i18nlangtag/lang.h> #include <sortopt.hxx> +#include <o3tl/make_unique.hxx> SwSortKey::SwSortKey() : eSortOrder( SRT_ASCENDING ), @@ -59,17 +60,14 @@ SwSortOptions::SwSortOptions(const SwSortOptions& rOpt) : bTable( rOpt.bTable ), bIgnoreCase( rOpt.bIgnoreCase ) { - for(SwSortKey* pKey : rOpt.aKeys) + for(auto const & pKey : rOpt.aKeys) { - SwSortKey* pNew = new SwSortKey(*pKey); - aKeys.push_back( pNew ); + aKeys.push_back( o3tl::make_unique<SwSortKey>(*pKey) ); } } SwSortOptions::~SwSortOptions() { - for( SwSortKey *pKey : aKeys ) - delete pKey; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index b633cbb6a448..ed6cf2ded70b 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -2588,21 +2588,21 @@ bool SwUnoCursorHelper::ConvertSortProperties( rSortOpt.cDeli = ' '; rSortOpt.eDirection = SRT_COLUMNS; //!! UI text may be contrary though !! - SwSortKey* pKey1 = new SwSortKey; + std::unique_ptr<SwSortKey> pKey1(new SwSortKey); pKey1->nColumnId = USHRT_MAX; pKey1->bIsNumeric = true; pKey1->eSortOrder = SRT_ASCENDING; - SwSortKey* pKey2 = new SwSortKey; + std::unique_ptr<SwSortKey> pKey2(new SwSortKey); pKey2->nColumnId = USHRT_MAX; pKey2->bIsNumeric = true; pKey2->eSortOrder = SRT_ASCENDING; - SwSortKey* pKey3 = new SwSortKey; + std::unique_ptr<SwSortKey> pKey3(new SwSortKey); pKey3->nColumnId = USHRT_MAX; pKey3->bIsNumeric = true; pKey3->eSortOrder = SRT_ASCENDING; - SwSortKey* aKeys[3] = {pKey1, pKey2, pKey3}; + SwSortKey* aKeys[3] = {pKey1.get(), pKey2.get(), pKey3.get()}; bool bOldSortdescriptor(false); bool bNewSortdescriptor(false); @@ -2815,15 +2815,15 @@ bool SwUnoCursorHelper::ConvertSortProperties( if (pKey1->nColumnId != USHRT_MAX) { - rSortOpt.aKeys.push_back(pKey1); + rSortOpt.aKeys.push_back(std::move(pKey1)); } if (pKey2->nColumnId != USHRT_MAX) { - rSortOpt.aKeys.push_back(pKey2); + rSortOpt.aKeys.push_back(std::move(pKey2)); } if (pKey3->nColumnId != USHRT_MAX) { - rSortOpt.aKeys.push_back(pKey3); + rSortOpt.aKeys.push_back(std::move(pKey3)); } return bRet && !rSortOpt.aKeys.empty(); diff --git a/sw/source/ui/misc/srtdlg.cxx b/sw/source/ui/misc/srtdlg.cxx index 990ea0183721..2f95f2fe170a 100644 --- a/sw/source/ui/misc/srtdlg.cxx +++ b/sw/source/ui/misc/srtdlg.cxx @@ -41,6 +41,7 @@ #include <swtable.hxx> #include <node.hxx> #include <tblsel.hxx> +#include <o3tl/make_unique.hxx> #include <sfx2/request.hxx> #include <memory> @@ -317,9 +318,9 @@ void SwSortDlg::Apply() else if( nullptr != (pUserData = m_pTypDLB1->GetSelectedEntryData()) ) sEntry = *static_cast<OUString*>(pUserData); - SwSortKey *pKey = new SwSortKey( nCol1, sEntry, - bAsc1 ? SRT_ASCENDING : SRT_DESCENDING ); - aOptions.aKeys.push_back( pKey ); + aOptions.aKeys.push_back( + o3tl::make_unique<SwSortKey>( nCol1, sEntry, + bAsc1 ? SRT_ASCENDING : SRT_DESCENDING )); } if( bCheck2 ) @@ -330,9 +331,9 @@ void SwSortDlg::Apply() else if( nullptr != (pUserData = m_pTypDLB2->GetSelectedEntryData()) ) sEntry = *static_cast<OUString*>(pUserData); - SwSortKey *pKey = new SwSortKey( nCol2, sEntry, - bAsc2 ? SRT_ASCENDING : SRT_DESCENDING ); - aOptions.aKeys.push_back( pKey ); + aOptions.aKeys.push_back( + o3tl::make_unique<SwSortKey>( nCol2, sEntry, + bAsc2 ? SRT_ASCENDING : SRT_DESCENDING )); } if( bCheck3 ) @@ -343,9 +344,9 @@ void SwSortDlg::Apply() else if( nullptr != (pUserData = m_pTypDLB3->GetSelectedEntryData()) ) sEntry = *static_cast<OUString*>(pUserData); - SwSortKey *pKey = new SwSortKey( nCol3, sEntry, - bAsc3 ? SRT_ASCENDING : SRT_DESCENDING ); - aOptions.aKeys.push_back( pKey ); + aOptions.aKeys.push_back( + o3tl::make_unique<SwSortKey>( nCol3, sEntry, + bAsc3 ? SRT_ASCENDING : SRT_DESCENDING )); } aOptions.eDirection = bCol ? SRT_COLUMNS : SRT_ROWS; |