diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-28 11:12:20 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-29 08:37:12 +0200 |
commit | 57871f98d30c0283969de1a41e72f5838d6c0eb0 (patch) | |
tree | 359af27f4879cc817e2b2139e8e7a55f4492afc7 | |
parent | 0dde5e7d6c69fbf59a898b019ef230adfef30633 (diff) |
loplugin:useuniqueptr in SwNumRule
Change-Id: Id74c0dac582b1dc52076488332e26c88e5e7b4c3
Reviewed-on: https://gerrit.libreoffice.org/52033
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sw/inc/numrule.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/doc/number.cxx | 34 |
2 files changed, 15 insertions, 21 deletions
diff --git a/sw/inc/numrule.hxx b/sw/inc/numrule.hxx index b1029c810a82..cdbfd9f5f252 100644 --- a/sw/inc/numrule.hxx +++ b/sw/inc/numrule.hxx @@ -113,7 +113,7 @@ private: static SwNumFormat* maLabelAlignmentBaseFormats [ RULE_END ][ MAXLEVEL ]; static sal_uInt16 mnRefCount; - SwNumFormat* maFormats[ MAXLEVEL ]; + std::unique_ptr<SwNumFormat> maFormats[ MAXLEVEL ]; /** container for associated text nodes */ tTextNodeList maTextNodeList; diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx index 7a8574065a87..2b7047b57535 100644 --- a/sw/source/core/doc/number.cxx +++ b/sw/source/core/doc/number.cxx @@ -93,7 +93,7 @@ const SwNumFormat* SwNumRule::GetNumFormat( sal_uInt16 i ) const assert( i < MAXLEVEL && meRuleType < RULE_END ); if ( i < MAXLEVEL && meRuleType < RULE_END) { - pResult = maFormats[ i ]; + pResult = maFormats[ i ].get(); } return pResult; @@ -461,7 +461,6 @@ SwNumRule::SwNumRule( const SwNumRule& rNumRule ) msDefaultListId( rNumRule.msDefaultListId ) { ++mnRefCount; - memset( maFormats, 0, sizeof( maFormats )); for( sal_uInt16 n = 0; n < MAXLEVEL; ++n ) if( rNumRule.maFormats[ n ] ) Set( n, *rNumRule.maFormats[ n ] ); @@ -469,8 +468,8 @@ SwNumRule::SwNumRule( const SwNumRule& rNumRule ) SwNumRule::~SwNumRule() { - for(SwNumFormat* p : maFormats) - delete p; + for (auto & i : maFormats) + i.reset(); if (mpNumRuleMap) { @@ -515,7 +514,7 @@ SwNumRule::~SwNumRule() void SwNumRule::CheckCharFormats( SwDoc* pDoc ) { - for(SwNumFormat*& rpNumFormat : maFormats) + for(auto& rpNumFormat : maFormats) { SwCharFormat* pFormat; if( rpNumFormat && nullptr != ( pFormat = rpNumFormat->GetCharFormat() ) && @@ -524,8 +523,7 @@ void SwNumRule::CheckCharFormats( SwDoc* pDoc ) // copy SwNumFormat* pNew = new SwNumFormat( *rpNumFormat ); pNew->SetCharFormat( pDoc->CopyCharFormat( *pFormat ) ); - delete rpNumFormat; - rpNumFormat = pNew; + rpNumFormat.reset(pNew); } } } @@ -535,7 +533,7 @@ SwNumRule& SwNumRule::operator=( const SwNumRule& rNumRule ) if( this != &rNumRule ) { for( sal_uInt16 n = 0; n < MAXLEVEL; ++n ) - Set( n, rNumRule.maFormats[ n ] ); + Set( n, rNumRule.maFormats[ n ].get() ); meRuleType = rNumRule.meRuleType; msName = rNumRule.msName; @@ -580,8 +578,7 @@ void SwNumRule::Set( sal_uInt16 i, const SwNumFormat& rNumFormat ) { if( !maFormats[ i ] || !(rNumFormat == Get( i )) ) { - delete maFormats[ i ]; - maFormats[ i ] = new SwNumFormat( rNumFormat ); + maFormats[ i ].reset(new SwNumFormat( rNumFormat )); mbInvalidRuleFlag = true; } } @@ -592,24 +589,22 @@ void SwNumRule::Set( sal_uInt16 i, const SwNumFormat* pNumFormat ) OSL_ENSURE( i < MAXLEVEL, "Serious defect" ); if( i >= MAXLEVEL ) return; - SwNumFormat* pOld = maFormats[ i ]; - if( !pOld ) + if( !maFormats[ i ] ) { if( pNumFormat ) { - maFormats[ i ] = new SwNumFormat( *pNumFormat ); + maFormats[ i ].reset(new SwNumFormat( *pNumFormat )); mbInvalidRuleFlag = true; } } else if( !pNumFormat ) { - delete pOld; - maFormats[ i ] = nullptr; + maFormats[ i ].reset(); mbInvalidRuleFlag = true; } - else if( *pOld != *pNumFormat ) + else if( *maFormats[i] != *pNumFormat ) { - *pOld = *pNumFormat; + *maFormats[ i ] = *pNumFormat; mbInvalidRuleFlag = true; } } @@ -807,7 +802,7 @@ SwNumRule& SwNumRule::CopyNumRule( SwDoc* pDoc, const SwNumRule& rNumRule ) { for( sal_uInt16 n = 0; n < MAXLEVEL; ++n ) { - Set( n, rNumRule.maFormats[ n ] ); + Set( n, rNumRule.maFormats[ n ].get() ); if( maFormats[ n ] && maFormats[ n ]->GetCharFormat() && !pDoc->GetCharFormats()->IsAlive(maFormats[n]->GetCharFormat())) { @@ -832,8 +827,7 @@ void SwNumRule::SetSvxRule(const SvxNumRule& rNumRule, SwDoc* pDoc) for( sal_uInt16 n = 0; n < MAXLEVEL; ++n ) { const SvxNumberFormat* pSvxFormat = rNumRule.Get(n); - delete maFormats[n]; - maFormats[n] = pSvxFormat ? new SwNumFormat(*pSvxFormat, pDoc) : nullptr; + maFormats[n].reset( pSvxFormat ? new SwNumFormat(*pSvxFormat, pDoc) : nullptr ); } mbInvalidRuleFlag = true; |