diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-05-22 13:25:58 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-05-23 09:31:20 +0200 |
commit | d1e47b1428abf1732ab4d5e219b210760d4152e0 (patch) | |
tree | 8eac1def834ba548c45a8a1a18e8e39d45eedc1d /sd | |
parent | 919a4ef592b6026a7533a93682f39118fef29ce8 (diff) |
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 <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/source/ui/app/optsitem.cxx | 19 | ||||
-rw-r--r-- | sd/source/ui/inc/optsitem.hxx | 7 |
2 files changed, 22 insertions, 4 deletions
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<SdOptionsGeneric*>(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 <svx/optgrid.hxx> #include <svx/dlgutil.hxx> #include "sddllapi.h" +#include <memory> class SdOptions; @@ -65,7 +66,8 @@ friend class SdOptionsItem; private: OUString maSubTree; - SdOptionsItem* mpCfgItem; + std::unique_ptr<SdOptionsItem> + 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; } |