diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-07 09:59:09 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-08 19:27:59 +0200 |
commit | d34098cdb98966e537d9c500e34c8719c21094a8 (patch) | |
tree | 325d8b53d50e15082bf78218aea0d15d2b063791 | |
parent | 9db52c294f37c9404e846a1c0bd1741f142f5708 (diff) |
loplugin:useuniqueptr in CGMElements
Change-Id: Icff5c5c3790f06af19d463a66a2dcef0a7917f44
Reviewed-on: https://gerrit.libreoffice.org/60190
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | filter/source/graphicfilter/icgm/bundles.hxx | 13 | ||||
-rw-r--r-- | filter/source/graphicfilter/icgm/elements.cxx | 33 | ||||
-rw-r--r-- | filter/source/graphicfilter/icgm/elements.hxx | 3 |
3 files changed, 16 insertions, 33 deletions
diff --git a/filter/source/graphicfilter/icgm/bundles.hxx b/filter/source/graphicfilter/icgm/bundles.hxx index ba0740afdb45..36f45393ea3d 100644 --- a/filter/source/graphicfilter/icgm/bundles.hxx +++ b/filter/source/graphicfilter/icgm/bundles.hxx @@ -23,6 +23,7 @@ #include <sal/types.h> #include "cgmtypes.hxx" #include <vcl/salbtype.hxx> +#include <o3tl/make_unique.hxx> #include <vector> #include <memory> @@ -44,7 +45,7 @@ public: , mnColor( 0 ) {}; - virtual Bundle* Clone() { return new Bundle( *this ); }; + virtual std::unique_ptr<Bundle> Clone() { return o3tl::make_unique<Bundle>( *this ); }; virtual ~Bundle() {} ; @@ -67,7 +68,7 @@ public: , nLineWidth(0) {} - virtual Bundle* Clone() override { return new LineBundle( *this ); } + virtual std::unique_ptr<Bundle> Clone() override { return o3tl::make_unique<LineBundle>( *this ); } }; @@ -83,7 +84,7 @@ public: , nMarkerSize( 0.0 ) {}; - virtual Bundle* Clone() override { return new MarkerBundle( *this ); } ; + virtual std::unique_ptr<Bundle> Clone() override { return o3tl::make_unique<MarkerBundle>( *this ); } ; }; @@ -98,7 +99,7 @@ public: : eEdgeType(ET_NONE) , nEdgeWidth(0) {} - virtual Bundle* Clone() override { return new EdgeBundle( *this ); } + virtual std::unique_ptr<Bundle> Clone() override { return o3tl::make_unique<EdgeBundle>( *this ); } }; @@ -118,7 +119,7 @@ public: , nCharacterSpacing( 0.0 ) {}; - virtual Bundle* Clone() override { return new TextBundle( *this ); } ; + virtual std::unique_ptr<Bundle> Clone() override { return o3tl::make_unique<TextBundle>( *this ); } ; }; @@ -135,7 +136,7 @@ public: , nFillPatternIndex(0) , nFillHatchIndex(0) {} - virtual Bundle* Clone() override { return new FillBundle( *this ); } + virtual std::unique_ptr<Bundle> Clone() override { return o3tl::make_unique<FillBundle>( *this ); } }; diff --git a/filter/source/graphicfilter/icgm/elements.cxx b/filter/source/graphicfilter/icgm/elements.cxx index 609128e11585..4449785988e4 100644 --- a/filter/source/graphicfilter/icgm/elements.cxx +++ b/filter/source/graphicfilter/icgm/elements.cxx @@ -29,11 +29,6 @@ CGMElements::CGMElements() CGMElements::~CGMElements() { - DeleteAllBundles( aLineList ); - DeleteAllBundles( aMarkerList ); - DeleteAllBundles( aEdgeList ); - DeleteAllBundles( aTextList ); - DeleteAllBundles( aFillList ); } @@ -290,23 +285,13 @@ void CGMElements::ImplInsertHatch( sal_Int32 nKey, int nStyle, long nDistance, l } -void CGMElements::DeleteAllBundles( BundleList& rList ) -{ - for (Bundle* i : rList) { - delete i; - } - rList.clear(); -}; - - void CGMElements::CopyAllBundles( const BundleList& rSource, BundleList& rDest ) { - DeleteAllBundles( rDest ); + rDest.clear(); - for (Bundle* pPtr : rSource) + for (auto & pPtr : rSource) { - Bundle* pTempBundle = pPtr->Clone(); - rDest.push_back( pTempBundle ); + rDest.push_back( pPtr->Clone() ); } }; @@ -323,9 +308,9 @@ Bundle* CGMElements::GetBundleIndex( long nIndex, BundleList& rList, Bundle& rBu Bundle* CGMElements::GetBundle( BundleList& rList, long nIndex ) { - for (Bundle* i : rList) { + for (auto const & i : rList) { if ( i->GetIndex() == nIndex ) { - return i; + return i.get(); } } return nullptr; @@ -338,16 +323,14 @@ Bundle* CGMElements::InsertBundle( BundleList& rList, Bundle& rBundle ) if ( pBundle ) { for ( BundleList::iterator it = rList.begin(); it != rList.end(); ++it ) { - if ( *it == pBundle ) { + if ( it->get() == pBundle ) { rList.erase( it ); - delete pBundle; break; } } } - pBundle = rBundle.Clone(); - rList.push_back( pBundle ); - return pBundle; + rList.push_back( rBundle.Clone() ); + return rList.back().get(); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/graphicfilter/icgm/elements.hxx b/filter/source/graphicfilter/icgm/elements.hxx index 8356e0d6deb5..bfcba6156416 100644 --- a/filter/source/graphicfilter/icgm/elements.hxx +++ b/filter/source/graphicfilter/icgm/elements.hxx @@ -26,7 +26,7 @@ #define nBackGroundColor aColorTable[ 0 ] -typedef ::std::vector< Bundle* > BundleList; +typedef ::std::vector< std::unique_ptr<Bundle> > BundleList; class CGMElements { @@ -132,7 +132,6 @@ class CGMElements static Bundle* GetBundleIndex( long nIndex, BundleList&, Bundle& ); static Bundle* GetBundle( BundleList& rList, long nIndex ); static Bundle* InsertBundle( BundleList&, Bundle& ); - static void DeleteAllBundles( BundleList& ); static void CopyAllBundles( const BundleList& Source, BundleList& Dest ); }; |