[Libreoffice-commits] core.git: sw/inc sw/source
Noel Grandin
noel.grandin at collabora.co.uk
Fri Oct 20 09:32:13 UTC 2017
sw/inc/sortopt.hxx | 5 ++++-
sw/source/core/doc/docsort.cxx | 2 +-
sw/source/core/doc/sortopt.cxx | 8 +++-----
sw/source/core/unocore/unoobj.cxx | 14 +++++++-------
sw/source/ui/misc/srtdlg.cxx | 19 ++++++++++---------
5 files changed, 25 insertions(+), 23 deletions(-)
New commits:
commit b42c7f2def7425dd379204a5bd15481e840093ed
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Wed Oct 18 17:09:39 2017 +0200
use std::unique_ptr in SwSortOptions
Change-Id: I5854e1492388d765a0503193a45f7c0f1bd14004
Reviewed-on: https://gerrit.libreoffice.org/43528
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
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;
More information about the Libreoffice-commits
mailing list