From 1da9761c72e0893ee01abacb341435a1539a1f93 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 2 Aug 2018 12:44:49 +0200 Subject: loplugin:useuniqueptr in ImplHomMatrixTemplate Change-Id: I31175a5110672e864b07d6b5508b8b04b14e66ee Reviewed-on: https://gerrit.libreoffice.org/58484 Tested-by: Jenkins Reviewed-by: Noel Grandin --- basegfx/source/inc/hommatrixtemplate.hxx | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'basegfx/source/inc') diff --git a/basegfx/source/inc/hommatrixtemplate.hxx b/basegfx/source/inc/hommatrixtemplate.hxx index 4e00fdf2119c..b7106f6fb22d 100644 --- a/basegfx/source/inc/hommatrixtemplate.hxx +++ b/basegfx/source/inc/hommatrixtemplate.hxx @@ -75,7 +75,7 @@ namespace basegfx template < sal_uInt16 RowSize > class ImplHomMatrixTemplate { ImplMatLine< RowSize > maLine[RowSize - 1]; - ImplMatLine< RowSize >* mpLine; + std::unique_ptr> mutable mpLine; public: // Is last line used? @@ -96,14 +96,12 @@ namespace basegfx } // reset last line, it equals default - delete const_cast*>(this)->mpLine; - const_cast*>(this)->mpLine = nullptr; + mpLine.reset(); return true; } ImplHomMatrixTemplate() - : mpLine(nullptr) { // complete initialization with identity matrix, all lines // were initialized with a trailing 1 followed by 0's. @@ -115,26 +113,22 @@ namespace basegfx } ImplHomMatrixTemplate(const ImplHomMatrixTemplate& rToBeCopied) - : mpLine(nullptr) + { + operator=(rToBeCopied); + } + + ImplHomMatrixTemplate& operator=(const ImplHomMatrixTemplate& rToBeCopied) { // complete initialization using copy for(sal_uInt16 a(0); a < (RowSize - 1); a++) { memcpy(&maLine[a], &rToBeCopied.maLine[a], sizeof(ImplMatLine< RowSize >)); } - if(rToBeCopied.mpLine) { - mpLine = new ImplMatLine< RowSize >((RowSize - 1), rToBeCopied.mpLine); - } - } - - ~ImplHomMatrixTemplate() - { - if(mpLine) - { - delete mpLine; + mpLine.reset( new ImplMatLine< RowSize >((RowSize - 1), rToBeCopied.mpLine.get()) ); } + return *this; } static sal_uInt16 getEdgeLength() { return RowSize; } @@ -170,7 +164,7 @@ namespace basegfx if(!::basegfx::fTools::equal(fDefault, rValue)) { - mpLine = new ImplMatLine< RowSize >((RowSize - 1), nullptr); + mpLine.reset(new ImplMatLine< RowSize >((RowSize - 1), nullptr)); mpLine->set(nColumn, rValue); } } @@ -195,8 +189,7 @@ namespace basegfx if(!bNecessary) { - delete mpLine; - mpLine = nullptr; + mpLine.reset(); } } } -- cgit v1.2.3