Kaydet (Commit) b42c7f2d authored tarafından Noel Grandin's avatar Noel Grandin

use std::unique_ptr in SwSortOptions

Change-Id: I5854e1492388d765a0503193a45f7c0f1bd14004
Reviewed-on: https://gerrit.libreoffice.org/43528Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 92fe6fed
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include "swdllapi.h" #include "swdllapi.h"
#include <memory>
#include <vector> #include <vector>
enum SwSortOrder { SRT_ASCENDING, SRT_DESCENDING }; enum SwSortOrder { SRT_ASCENDING, SRT_DESCENDING };
...@@ -44,7 +45,9 @@ struct SW_DLLPUBLIC SwSortOptions ...@@ -44,7 +45,9 @@ struct SW_DLLPUBLIC SwSortOptions
~SwSortOptions(); ~SwSortOptions();
SwSortOptions(const SwSortOptions& rOpt); SwSortOptions(const SwSortOptions& rOpt);
std::vector<SwSortKey*> aKeys; SwSortOptions& operator=( SwSortOptions const & ) = delete; // MSVC2015 workaround
std::vector<std::unique_ptr<SwSortKey>> aKeys;
SwSortDirection eDirection; SwSortDirection eDirection;
sal_Unicode cDeli; sal_Unicode cDeli;
LanguageType nLanguage; LanguageType nLanguage;
......
...@@ -128,7 +128,7 @@ int SwSortElement::keycompare(const SwSortElement& rCmp, sal_uInt16 nKey) const ...@@ -128,7 +128,7 @@ int SwSortElement::keycompare(const SwSortElement& rCmp, sal_uInt16 nKey) const
// The actual comparison // The actual comparison
const SwSortElement *pOrig, *pCmp; const SwSortElement *pOrig, *pCmp;
const SwSortKey* pSrtKey = pOptions->aKeys[ nKey ]; const SwSortKey* pSrtKey = pOptions->aKeys[ nKey ].get();
if( pSrtKey->eSortOrder == SRT_ASCENDING ) if( pSrtKey->eSortOrder == SRT_ASCENDING )
{ {
pOrig = this; pOrig = this;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <i18nlangtag/lang.h> #include <i18nlangtag/lang.h>
#include <sortopt.hxx> #include <sortopt.hxx>
#include <o3tl/make_unique.hxx>
SwSortKey::SwSortKey() : SwSortKey::SwSortKey() :
eSortOrder( SRT_ASCENDING ), eSortOrder( SRT_ASCENDING ),
...@@ -59,17 +60,14 @@ SwSortOptions::SwSortOptions(const SwSortOptions& rOpt) : ...@@ -59,17 +60,14 @@ SwSortOptions::SwSortOptions(const SwSortOptions& rOpt) :
bTable( rOpt.bTable ), bTable( rOpt.bTable ),
bIgnoreCase( rOpt.bIgnoreCase ) bIgnoreCase( rOpt.bIgnoreCase )
{ {
for(SwSortKey* pKey : rOpt.aKeys) for(auto const & pKey : rOpt.aKeys)
{ {
SwSortKey* pNew = new SwSortKey(*pKey); aKeys.push_back( o3tl::make_unique<SwSortKey>(*pKey) );
aKeys.push_back( pNew );
} }
} }
SwSortOptions::~SwSortOptions() SwSortOptions::~SwSortOptions()
{ {
for( SwSortKey *pKey : aKeys )
delete pKey;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -2588,21 +2588,21 @@ bool SwUnoCursorHelper::ConvertSortProperties( ...@@ -2588,21 +2588,21 @@ bool SwUnoCursorHelper::ConvertSortProperties(
rSortOpt.cDeli = ' '; rSortOpt.cDeli = ' ';
rSortOpt.eDirection = SRT_COLUMNS; //!! UI text may be contrary though !! 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->nColumnId = USHRT_MAX;
pKey1->bIsNumeric = true; pKey1->bIsNumeric = true;
pKey1->eSortOrder = SRT_ASCENDING; pKey1->eSortOrder = SRT_ASCENDING;
SwSortKey* pKey2 = new SwSortKey; std::unique_ptr<SwSortKey> pKey2(new SwSortKey);
pKey2->nColumnId = USHRT_MAX; pKey2->nColumnId = USHRT_MAX;
pKey2->bIsNumeric = true; pKey2->bIsNumeric = true;
pKey2->eSortOrder = SRT_ASCENDING; pKey2->eSortOrder = SRT_ASCENDING;
SwSortKey* pKey3 = new SwSortKey; std::unique_ptr<SwSortKey> pKey3(new SwSortKey);
pKey3->nColumnId = USHRT_MAX; pKey3->nColumnId = USHRT_MAX;
pKey3->bIsNumeric = true; pKey3->bIsNumeric = true;
pKey3->eSortOrder = SRT_ASCENDING; pKey3->eSortOrder = SRT_ASCENDING;
SwSortKey* aKeys[3] = {pKey1, pKey2, pKey3}; SwSortKey* aKeys[3] = {pKey1.get(), pKey2.get(), pKey3.get()};
bool bOldSortdescriptor(false); bool bOldSortdescriptor(false);
bool bNewSortdescriptor(false); bool bNewSortdescriptor(false);
...@@ -2815,15 +2815,15 @@ bool SwUnoCursorHelper::ConvertSortProperties( ...@@ -2815,15 +2815,15 @@ bool SwUnoCursorHelper::ConvertSortProperties(
if (pKey1->nColumnId != USHRT_MAX) if (pKey1->nColumnId != USHRT_MAX)
{ {
rSortOpt.aKeys.push_back(pKey1); rSortOpt.aKeys.push_back(std::move(pKey1));
} }
if (pKey2->nColumnId != USHRT_MAX) if (pKey2->nColumnId != USHRT_MAX)
{ {
rSortOpt.aKeys.push_back(pKey2); rSortOpt.aKeys.push_back(std::move(pKey2));
} }
if (pKey3->nColumnId != USHRT_MAX) if (pKey3->nColumnId != USHRT_MAX)
{ {
rSortOpt.aKeys.push_back(pKey3); rSortOpt.aKeys.push_back(std::move(pKey3));
} }
return bRet && !rSortOpt.aKeys.empty(); return bRet && !rSortOpt.aKeys.empty();
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <swtable.hxx> #include <swtable.hxx>
#include <node.hxx> #include <node.hxx>
#include <tblsel.hxx> #include <tblsel.hxx>
#include <o3tl/make_unique.hxx>
#include <sfx2/request.hxx> #include <sfx2/request.hxx>
#include <memory> #include <memory>
...@@ -317,9 +318,9 @@ void SwSortDlg::Apply() ...@@ -317,9 +318,9 @@ void SwSortDlg::Apply()
else if( nullptr != (pUserData = m_pTypDLB1->GetSelectedEntryData()) ) else if( nullptr != (pUserData = m_pTypDLB1->GetSelectedEntryData()) )
sEntry = *static_cast<OUString*>(pUserData); sEntry = *static_cast<OUString*>(pUserData);
SwSortKey *pKey = new SwSortKey( nCol1, sEntry, aOptions.aKeys.push_back(
bAsc1 ? SRT_ASCENDING : SRT_DESCENDING ); o3tl::make_unique<SwSortKey>( nCol1, sEntry,
aOptions.aKeys.push_back( pKey ); bAsc1 ? SRT_ASCENDING : SRT_DESCENDING ));
} }
if( bCheck2 ) if( bCheck2 )
...@@ -330,9 +331,9 @@ void SwSortDlg::Apply() ...@@ -330,9 +331,9 @@ void SwSortDlg::Apply()
else if( nullptr != (pUserData = m_pTypDLB2->GetSelectedEntryData()) ) else if( nullptr != (pUserData = m_pTypDLB2->GetSelectedEntryData()) )
sEntry = *static_cast<OUString*>(pUserData); sEntry = *static_cast<OUString*>(pUserData);
SwSortKey *pKey = new SwSortKey( nCol2, sEntry, aOptions.aKeys.push_back(
bAsc2 ? SRT_ASCENDING : SRT_DESCENDING ); o3tl::make_unique<SwSortKey>( nCol2, sEntry,
aOptions.aKeys.push_back( pKey ); bAsc2 ? SRT_ASCENDING : SRT_DESCENDING ));
} }
if( bCheck3 ) if( bCheck3 )
...@@ -343,9 +344,9 @@ void SwSortDlg::Apply() ...@@ -343,9 +344,9 @@ void SwSortDlg::Apply()
else if( nullptr != (pUserData = m_pTypDLB3->GetSelectedEntryData()) ) else if( nullptr != (pUserData = m_pTypDLB3->GetSelectedEntryData()) )
sEntry = *static_cast<OUString*>(pUserData); sEntry = *static_cast<OUString*>(pUserData);
SwSortKey *pKey = new SwSortKey( nCol3, sEntry, aOptions.aKeys.push_back(
bAsc3 ? SRT_ASCENDING : SRT_DESCENDING ); o3tl::make_unique<SwSortKey>( nCol3, sEntry,
aOptions.aKeys.push_back( pKey ); bAsc3 ? SRT_ASCENDING : SRT_DESCENDING ));
} }
aOptions.eDirection = bCol ? SRT_COLUMNS : SRT_ROWS; aOptions.eDirection = bCol ? SRT_COLUMNS : SRT_ROWS;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment