summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-11-16 09:51:25 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-11-17 08:10:40 +0100
commit54604f01330063635fb974b0ab4335d6af851551 (patch)
tree08a8f420db1b785c77dea4703547142febf5c1e7
parentef3a2e634ca81f5fb292f88c4d7eb28d170ce3dd (diff)
loplugin:useuniqueptr in SwNumRulesWithName
Change-Id: If539e9a3d859cea034d53690fdad746479a9f548 Reviewed-on: https://gerrit.libreoffice.org/44820 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/source/uibase/config/uinums.cxx29
-rw-r--r--sw/source/uibase/inc/uinums.hxx6
2 files changed, 14 insertions, 21 deletions
diff --git a/sw/source/uibase/config/uinums.cxx b/sw/source/uibase/config/uinums.cxx
index 24c79ddc2c79..3b7f3e35e10c 100644
--- a/sw/source/uibase/config/uinums.cxx
+++ b/sw/source/uibase/config/uinums.cxx
@@ -73,14 +73,12 @@ void SwChapterNumRules::Save()
SwChapterNumRules::~SwChapterNumRules()
{
- for(SwNumRulesWithName* pNumRule : pNumRules)
- delete pNumRule;
}
void SwChapterNumRules::Init()
{
- for(SwNumRulesWithName* & rpNumRule : pNumRules)
- rpNumRule = nullptr;
+ for(auto & rpNumRule : pNumRules)
+ rpNumRule.reset();
OUString sNm(CHAPTER_FILENAME);
SvtPathOptions aOpt;
@@ -96,14 +94,14 @@ void SwChapterNumRules::CreateEmptyNumRule(sal_uInt16 const nIndex)
{
assert(nIndex < nMaxRules);
assert(!pNumRules[nIndex]);
- pNumRules[nIndex] = new SwNumRulesWithName;
+ pNumRules[nIndex].reset(new SwNumRulesWithName);
}
void SwChapterNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 nIdx)
{
assert(nIdx < nMaxRules);
if( !pNumRules[nIdx] )
- pNumRules[nIdx] = new SwNumRulesWithName( rCopy );
+ pNumRules[nIdx].reset(new SwNumRulesWithName( rCopy ));
else
*pNumRules[nIdx] = rCopy;
Save(); // store it immediately
@@ -117,9 +115,9 @@ SwNumRulesWithName::SwNumRulesWithName( const SwNumRule &rCopy,
{
const SwNumFormat* pFormat = rCopy.GetNumFormat( n );
if( pFormat )
- aFormats[ n ] = new SwNumFormatGlobal( *pFormat );
+ aFormats[ n ].reset(new SwNumFormatGlobal( *pFormat ));
else
- aFormats[ n ] = nullptr;
+ aFormats[ n ].reset();
}
}
@@ -136,8 +134,6 @@ SwNumRulesWithName::SwNumRulesWithName( const SwNumRulesWithName& rCopy )
SwNumRulesWithName::~SwNumRulesWithName()
{
- for(SwNumFormatGlobal* p : aFormats)
- delete p;
}
SwNumRulesWithName& SwNumRulesWithName::operator=(const SwNumRulesWithName &rCopy)
@@ -147,13 +143,11 @@ SwNumRulesWithName& SwNumRulesWithName::operator=(const SwNumRulesWithName &rCop
maName = rCopy.maName;
for( int n = 0; n < MAXLEVEL; ++n )
{
- delete aFormats[ n ];
-
- SwNumFormatGlobal* pFormat = rCopy.aFormats[ n ];
+ SwNumFormatGlobal* pFormat = rCopy.aFormats[ n ].get();
if( pFormat )
- aFormats[ n ] = new SwNumFormatGlobal( *pFormat );
+ aFormats[ n ].reset(new SwNumFormatGlobal( *pFormat ));
else
- aFormats[ n ] = nullptr;
+ aFormats[ n ].reset();
}
}
return *this;
@@ -166,7 +160,7 @@ SwNumRule* SwNumRulesWithName::MakeNumRule(SwWrtShell& rSh) const
pChg->SetAutoRule( false );
for (sal_uInt16 n = 0; n < MAXLEVEL; ++n)
{
- SwNumFormatGlobal* pFormat = aFormats[ n ];
+ SwNumFormatGlobal* pFormat = aFormats[ n ].get();
if (!pFormat)
continue;
pChg->Set(n, pFormat->MakeNumFormat(rSh));
@@ -184,8 +178,7 @@ void SwNumRulesWithName::GetNumFormat(
void SwNumRulesWithName::SetNumFormat(
size_t const nIndex, SwNumFormat const& rNumFormat, OUString const& rName)
{
- delete aFormats[nIndex];
- aFormats[nIndex] = new SwNumFormatGlobal(rNumFormat);
+ aFormats[nIndex].reset( new SwNumFormatGlobal(rNumFormat) );
aFormats[nIndex]->sCharFormatName = rName;
aFormats[nIndex]->nCharPoolId = USHRT_MAX;
aFormats[nIndex]->m_Items.clear();
diff --git a/sw/source/uibase/inc/uinums.hxx b/sw/source/uibase/inc/uinums.hxx
index 9ccbddcae512..3e5767c4d87a 100644
--- a/sw/source/uibase/inc/uinums.hxx
+++ b/sw/source/uibase/inc/uinums.hxx
@@ -56,7 +56,7 @@ class SW_DLLPUBLIC SwNumRulesWithName final
SwNumFormat MakeNumFormat(SwWrtShell& rSh) const;
};
- SwNumFormatGlobal* aFormats[ MAXLEVEL ];
+ std::unique_ptr<SwNumFormatGlobal> aFormats[ MAXLEVEL ];
friend class sw::StoredChapterNumberingRules;
friend class SwChapterNumRules;
@@ -82,7 +82,7 @@ class SW_DLLPUBLIC SwChapterNumRules final
public:
enum { nMaxRules = MAX_NUM_RULES }; // currently 9 defined forms
private:
- SwNumRulesWithName *pNumRules[ MAX_NUM_RULES ];
+ std::unique_ptr<SwNumRulesWithName> pNumRules[ MAX_NUM_RULES ];
void Init();
void Save();
@@ -100,7 +100,7 @@ public:
inline const SwNumRulesWithName *SwChapterNumRules::GetRules(sal_uInt16 nIdx) const
{
assert(nIdx < nMaxRules);
- return pNumRules[nIdx];
+ return pNumRules[nIdx].get();
}