diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-06-21 15:32:52 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-06-22 20:11:50 +0200 |
commit | 200ca388246e525f6e8f909766977f534c0c897e (patch) | |
tree | a1ddcd356bddada68d1510eb409721b6b2564562 /sw | |
parent | ac9db25da2d78f8ecc2ce68ad622cc6012972494 (diff) |
teach useuniqueptr loplugin about calling delete on a param
which is often a useful indicator that the callers can be made to use
std::unique_ptr
Change-Id: Idb1745d1f58dbcf389c9f60f1a5728d7d092ade5
Reviewed-on: https://gerrit.libreoffice.org/56238
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/filter/xml/xmlimpit.cxx | 40 | ||||
-rw-r--r-- | sw/source/filter/xml/xmlithlp.cxx | 15 | ||||
-rw-r--r-- | sw/source/filter/xml/xmlithlp.hxx | 4 |
3 files changed, 23 insertions, 36 deletions
diff --git a/sw/source/filter/xml/xmlimpit.cxx b/sw/source/filter/xml/xmlimpit.cxx index 0c9566012c26..d6b1ea06ad44 100644 --- a/sw/source/filter/xml/xmlimpit.cxx +++ b/sw/source/filter/xml/xmlimpit.cxx @@ -224,32 +224,24 @@ SvXMLImportItemMapper::finished(SfxItemSet &, SvXMLUnitConverter const&) const struct BoxHolder { - SvxBorderLine* pTop; - SvxBorderLine* pBottom; - SvxBorderLine* pLeft; - SvxBorderLine* pRight; + std::unique_ptr<SvxBorderLine> pTop; + std::unique_ptr<SvxBorderLine> pBottom; + std::unique_ptr<SvxBorderLine> pLeft; + std::unique_ptr<SvxBorderLine> pRight; BoxHolder(BoxHolder const&) = delete; BoxHolder& operator=(BoxHolder const&) = delete; explicit BoxHolder(SvxBoxItem const & rBox) { - pTop = rBox.GetTop() == nullptr ? - nullptr : new SvxBorderLine( *rBox.GetTop() ); - pBottom = rBox.GetBottom() == nullptr ? - nullptr : new SvxBorderLine( *rBox.GetBottom() ); - pLeft = rBox.GetLeft() == nullptr ? - nullptr : new SvxBorderLine( *rBox.GetLeft() ); - pRight = rBox.GetRight() == nullptr ? - nullptr : new SvxBorderLine( *rBox.GetRight() ); - } - - ~BoxHolder() - { - delete pTop; - delete pBottom; - delete pLeft; - delete pRight; + if (rBox.GetTop()) + pTop.reset(new SvxBorderLine( *rBox.GetTop() )); + if (rBox.GetBottom()) + pBottom.reset(new SvxBorderLine( *rBox.GetBottom() )); + if (rBox.GetLeft()) + pLeft.reset(new SvxBorderLine( *rBox.GetLeft() )); + if (rBox.GetRight()) + pRight.reset(new SvxBorderLine( *rBox.GetRight() )); } }; @@ -576,10 +568,10 @@ bool SvXMLImportItemMapper::PutXMLValue( break; } - rBox.SetLine( aBoxes.pTop, SvxBoxItemLine::TOP ); - rBox.SetLine( aBoxes.pBottom, SvxBoxItemLine::BOTTOM ); - rBox.SetLine( aBoxes.pLeft, SvxBoxItemLine::LEFT ); - rBox.SetLine( aBoxes.pRight, SvxBoxItemLine::RIGHT ); + rBox.SetLine( aBoxes.pTop.get(), SvxBoxItemLine::TOP ); + rBox.SetLine( aBoxes.pBottom.get(), SvxBoxItemLine::BOTTOM ); + rBox.SetLine( aBoxes.pLeft.get(), SvxBoxItemLine::LEFT ); + rBox.SetLine( aBoxes.pRight.get(), SvxBoxItemLine::RIGHT ); bOk = true; } diff --git a/sw/source/filter/xml/xmlithlp.cxx b/sw/source/filter/xml/xmlithlp.cxx index 4d7a5f3e09c6..d879292d5aba 100644 --- a/sw/source/filter/xml/xmlithlp.cxx +++ b/sw/source/filter/xml/xmlithlp.cxx @@ -140,7 +140,7 @@ void sw_frmitems_setXMLBorderStyle( SvxBorderLine& rLine, sal_uInt16 nStyle ) rLine.SetBorderLineStyle(eStyle); } -bool sw_frmitems_setXMLBorder( SvxBorderLine*& rpLine, +bool sw_frmitems_setXMLBorder( std::unique_ptr<SvxBorderLine>& rpLine, bool bHasStyle, sal_uInt16 nStyle, bool bHasWidth, sal_uInt16 nWidth, sal_uInt16 nNamedWidth, @@ -151,12 +151,7 @@ bool sw_frmitems_setXMLBorder( SvxBorderLine*& rpLine, (bHasWidth && USHRT_MAX == nNamedWidth && 0 == nWidth) ) { bool bRet = nullptr != rpLine; - if( rpLine ) - { - delete rpLine; - rpLine = nullptr; - } - + rpLine.reset(); return bRet; } @@ -166,7 +161,7 @@ bool sw_frmitems_setXMLBorder( SvxBorderLine*& rpLine, // We now do know that there will be a line if( !rpLine ) - rpLine = new SvxBorderLine; + rpLine.reset(new SvxBorderLine); if( ( bHasWidth && (USHRT_MAX != nNamedWidth || (nWidth != rpLine->GetWidth() ) ) ) || @@ -208,12 +203,12 @@ bool sw_frmitems_setXMLBorder( SvxBorderLine*& rpLine, return true; } -void sw_frmitems_setXMLBorder( SvxBorderLine*& rpLine, +void sw_frmitems_setXMLBorder( std::unique_ptr<SvxBorderLine>& rpLine, sal_uInt16 nWidth, sal_uInt16 nOutWidth, sal_uInt16 nInWidth, sal_uInt16 nDistance ) { if( !rpLine ) - rpLine = new SvxBorderLine; + rpLine.reset(new SvxBorderLine); if( nWidth > 0 ) rpLine->SetWidth( nWidth ); diff --git a/sw/source/filter/xml/xmlithlp.hxx b/sw/source/filter/xml/xmlithlp.hxx index c3c0512f16b8..e5498009bd3e 100644 --- a/sw/source/filter/xml/xmlithlp.hxx +++ b/sw/source/filter/xml/xmlithlp.hxx @@ -40,13 +40,13 @@ bool sw_frmitems_parseXMLBorder( const OUString& rValue, sal_uInt16& rNamedWidth, bool& rHasColor, Color& rColor ); -bool sw_frmitems_setXMLBorder( editeng::SvxBorderLine*& rpLine, +bool sw_frmitems_setXMLBorder( std::unique_ptr<editeng::SvxBorderLine>& rpLine, bool bHasStyle, sal_uInt16 nStyle, bool bHasWidth, sal_uInt16 nWidth, sal_uInt16 nNamedWidth, bool bHasColor, const Color& rColor ); -void sw_frmitems_setXMLBorder( editeng::SvxBorderLine*& rpLine, +void sw_frmitems_setXMLBorder( std::unique_ptr<editeng::SvxBorderLine>& rpLine, sal_uInt16 nWidth, sal_uInt16 nOutWidth, sal_uInt16 nInWidth, sal_uInt16 nDistance ); |