From d1e47b1428abf1732ab4d5e219b210760d4152e0 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 22 May 2017 13:25:58 +0200 Subject: enhance useuniqueptr loplugin teach it to look for the following sequence in a destructor: delete m_pfoo; m_pfoo = nullptr; Change-Id: Icd6271a63a024e32b53cc9e599f8f59952160380 Reviewed-on: https://gerrit.libreoffice.org/37900 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sd/source/ui/app/optsitem.cxx | 19 ++++++++++++++++--- sd/source/ui/inc/optsitem.hxx | 7 ++++++- 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'sd') diff --git a/sd/source/ui/app/optsitem.cxx b/sd/source/ui/app/optsitem.cxx index cdbcacd330e4..f23f1fbc6059 100644 --- a/sd/source/ui/app/optsitem.cxx +++ b/sd/source/ui/app/optsitem.cxx @@ -86,6 +86,21 @@ SdOptionsGeneric::SdOptionsGeneric(sal_uInt16 nConfigId, const OUString& rSubTre { } +SdOptionsGeneric::SdOptionsGeneric(SdOptionsGeneric const & rSource) +{ + operator=(rSource); +} + +SdOptionsGeneric& SdOptionsGeneric::operator=(SdOptionsGeneric const & rSource) +{ + maSubTree = rSource.maSubTree; + mpCfgItem.reset(rSource.mpCfgItem ? new SdOptionsItem(*rSource.mpCfgItem) : nullptr ); + mnConfigId = rSource.mnConfigId; + mbInit = rSource.mbInit; + mbEnableModify = rSource.mbEnableModify; + return *this; +} + void SdOptionsGeneric::Init() const { if( !mbInit ) @@ -93,7 +108,7 @@ void SdOptionsGeneric::Init() const SdOptionsGeneric* pThis = const_cast(this); if( !mpCfgItem ) - pThis->mpCfgItem = new SdOptionsItem( *this, maSubTree ); + pThis->mpCfgItem.reset( new SdOptionsItem( *this, maSubTree ) ); const Sequence< OUString > aNames( GetPropertyNames() ); const Sequence< Any > aValues = mpCfgItem->GetProperties( aNames ); @@ -113,8 +128,6 @@ void SdOptionsGeneric::Init() const SdOptionsGeneric::~SdOptionsGeneric() { - delete mpCfgItem; - mpCfgItem = nullptr; } void SdOptionsGeneric::Commit( SdOptionsItem& rCfgItem ) const diff --git a/sd/source/ui/inc/optsitem.hxx b/sd/source/ui/inc/optsitem.hxx index 5bf26e738eff..5ff8e4cf7e81 100644 --- a/sd/source/ui/inc/optsitem.hxx +++ b/sd/source/ui/inc/optsitem.hxx @@ -27,6 +27,7 @@ #include #include #include "sddllapi.h" +#include class SdOptions; @@ -65,7 +66,8 @@ friend class SdOptionsItem; private: OUString maSubTree; - SdOptionsItem* mpCfgItem; + std::unique_ptr + mpCfgItem; sal_uInt16 mnConfigId; bool mbInit : 1; bool mbEnableModify : 1; @@ -87,8 +89,11 @@ protected: public: SdOptionsGeneric( sal_uInt16 nConfigId, const OUString& rSubTree ); + SdOptionsGeneric( SdOptionsGeneric const & ); virtual ~SdOptionsGeneric(); + SdOptionsGeneric& operator=( SdOptionsGeneric const & ); + sal_uInt16 GetConfigId() const { return mnConfigId; } void EnableModify( bool bModify ) { mbEnableModify = bModify; } -- cgit