basic/source/classes/sb.cxx | 20 +- basic/source/classes/sbintern.cxx | 6 basic/source/classes/sbunoobj.cxx | 4 basic/source/classes/sbxmod.cxx | 42 ++--- basic/source/comp/codegen.cxx | 10 - basic/source/inc/sbintern.hxx | 6 basic/source/inc/sbunoobj.hxx | 2 basic/source/inc/stdobj.hxx | 2 basic/source/runtime/methods.cxx | 7 basic/source/runtime/runtime.cxx | 7 basic/source/runtime/stdobj.cxx | 8 - basic/source/sbx/sbxvar.cxx | 19 -- compilerplugins/clang/useuniqueptr.cxx | 3 cppcanvas/source/mtfrenderer/emfpbrush.cxx | 43 +---- cppcanvas/source/mtfrenderer/emfpbrush.hxx | 10 - cppcanvas/source/mtfrenderer/emfppen.cxx | 6 cppcanvas/source/mtfrenderer/emfppen.hxx | 4 cppcanvas/source/mtfrenderer/emfpregion.cxx | 6 cppcanvas/source/mtfrenderer/emfpregion.hxx | 2 drawinglayer/source/primitive2d/svggradientprimitive2d.cxx | 7 drawinglayer/source/processor3d/zbufferprocessor3d.cxx | 13 - drawinglayer/source/texture/texture3d.cxx | 15 - drawinglayer/source/tools/emfpbrush.cxx | 51 +----- drawinglayer/source/tools/emfpbrush.hxx | 10 - drawinglayer/source/tools/emfppen.cxx | 6 drawinglayer/source/tools/emfppen.hxx | 4 hwpfilter/source/drawdef.h | 5 hwpfilter/source/drawing.h | 10 - hwpfilter/source/hwpfile.cxx | 11 - hwpfilter/source/hwpfile.h | 4 hwpfilter/source/hwpreader.cxx | 14 - idl/inc/database.hxx | 2 idl/inc/globals.hxx | 7 idl/source/prj/command.cxx | 4 idl/source/prj/database.cxx | 4 idl/source/prj/globals.cxx | 2 include/basic/sbmod.hxx | 7 include/basic/sbxvar.hxx | 4 include/drawinglayer/primitive2d/svggradientprimitive2d.hxx | 2 include/drawinglayer/processor3d/zbufferprocessor3d.hxx | 5 include/drawinglayer/texture/texture3d.hxx | 6 include/editeng/outliner.hxx | 20 -- include/sfx2/childwin.hxx | 4 include/sfx2/lnkbase.hxx | 2 include/sfx2/request.hxx | 4 sfx2/source/appl/appdata.cxx | 4 sfx2/source/appl/childwin.cxx | 13 - sfx2/source/appl/helpinterceptor.cxx | 20 -- sfx2/source/appl/helpinterceptor.hxx | 4 sfx2/source/appl/impldde.cxx | 23 +- sfx2/source/appl/impldde.hxx | 6 sfx2/source/appl/lnkbase2.cxx | 6 sfx2/source/appl/module.cxx | 36 ++-- sfx2/source/control/itemdel.cxx | 4 sfx2/source/control/request.cxx | 21 +- sfx2/source/control/shell.cxx | 12 - sfx2/source/dialog/filedlghelper.cxx | 4 sfx2/source/dialog/filedlgimpl.hxx | 2 sfx2/source/dialog/templdlg.cxx | 6 sfx2/source/doc/docfile.cxx | 95 +++++------- sfx2/source/doc/doctemplates.cxx | 30 +-- sfx2/source/doc/guisaveas.cxx | 18 -- sfx2/source/explorer/nochaos.cxx | 12 - sfx2/source/inc/appdata.hxx | 5 sfx2/source/inc/templdgi.hxx | 2 65 files changed, 306 insertions(+), 447 deletions(-)
New commits: commit 0008af393325be8f33b9a68db6f04026ced93b10 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 16:13:43 2018 +0200 loplugin:useuniqueptr in SfxCommonTemplateDialog_Impl Change-Id: I484cb863c054c71cb22b30d108c95692213c8451 diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx index dc2e7e47e882..c5b10206916d 100644 --- a/sfx2/source/dialog/templdlg.cxx +++ b/sfx2/source/dialog/templdlg.cxx @@ -861,7 +861,7 @@ SfxCommonTemplateDialog_Impl::~SfxCommonTemplateDialog_Impl() EndListening(*pStyleSheetPool); pStyleSheetPool = nullptr; pTreeBox.disposeAndClear(); - delete pIdle; + pIdle.reset(); if ( m_pDeletionWatcher ) m_pDeletionWatcher->signal(); aFmtLb.disposeAndClear(); @@ -1402,7 +1402,7 @@ IMPL_LINK_NOARG( SfxCommonTemplateDialog_Impl, TimeOut, Timer *, void ) } } bDontUpdate=false; - DELETEZ(pIdle); + pIdle.reset(); } else pIdle->Start(); @@ -1488,7 +1488,7 @@ void SfxCommonTemplateDialog_Impl::Notify(SfxBroadcaster& /*rBC*/, const SfxHint { if(!pIdle) { - pIdle=new Idle("SfxCommonTemplate"); + pIdle.reset(new Idle("SfxCommonTemplate")); pIdle->SetPriority(TaskPriority::LOWEST); pIdle->SetInvokeHandler(LINK(this,SfxCommonTemplateDialog_Impl,TimeOut)); } diff --git a/sfx2/source/inc/templdgi.hxx b/sfx2/source/inc/templdgi.hxx index 4a911d292003..381da18b8916 100644 --- a/sfx2/source/inc/templdgi.hxx +++ b/sfx2/source/inc/templdgi.hxx @@ -176,7 +176,7 @@ protected: VclPtr<PopupMenu> mxMenu; OString sLastItemIdent; SfxModule* pModule; - Idle* pIdle; + std::unique_ptr<Idle> pIdle; SfxStyleFamilies* pStyleFamilies; SfxTemplateItem* pFamilyState[MAX_FAMILIES]; commit 5911f4bded3fcb63cb89e1c52cdcfdb5a331e0fc Author: Noel Grandin <[email protected]> Date: Tue Jan 16 16:12:29 2018 +0200 loplugin:useuniqueptr in SfxMedium_Impl Change-Id: Ifd973c243684cb0ed172f236c8cfd4dea9c3c653 diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index e862a88ecabe..c61639c8ef93 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -198,8 +198,8 @@ public: OUString m_aLogicName; OUString m_aLongName; - mutable SfxItemSet* m_pSet; - mutable INetURLObject* m_pURLObj; + mutable std::unique_ptr<SfxItemSet> m_pSet; + mutable std::unique_ptr<INetURLObject> m_pURLObj; std::shared_ptr<const SfxFilter> m_pFilter; std::shared_ptr<const SfxFilter> m_pCustomFilter; @@ -217,7 +217,7 @@ public: uno::Sequence < util::RevisionTag > aVersions; - ::utl::TempFile* pTempFile; + std::unique_ptr<::utl::TempFile> pTempFile; uno::Reference<embed::XStorage> xStorage; uno::Reference<embed::XStorage> m_xZipStorage; @@ -290,9 +290,9 @@ SfxMedium_Impl::~SfxMedium_Impl() { aDoneLink.ClearPendingCall(); - delete pTempFile; - delete m_pSet; - delete m_pURLObj; + pTempFile.reset(); + m_pSet.reset(); + m_pURLObj.reset(); } void SfxMedium::ResetError() @@ -407,7 +407,7 @@ Reference < XContent > SfxMedium::GetContent() const Reference < css::ucb::XCommandEnvironment > xEnv( static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY ); - const SfxUnoAnyItem* pItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet, SID_CONTENT, false); + const SfxUnoAnyItem* pItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet.get(), SID_CONTENT, false); if ( pItem ) pItem->GetValue() >>= xContent; @@ -791,7 +791,7 @@ void SfxMedium::SetEncryptionDataToStorage_Impl() if ( pImpl->xStorage.is() && pImpl->m_pSet ) { uno::Sequence< beans::NamedValue > aEncryptionData; - if ( GetEncryptionData_Impl( pImpl->m_pSet, aEncryptionData ) ) + if ( GetEncryptionData_Impl( pImpl->m_pSet.get(), aEncryptionData ) ) { // replace the password with encryption data pImpl->m_pSet->ClearItem( SID_PASSWORD ); @@ -1097,7 +1097,7 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI ) { // the error should be set in case it is storing process // or the document has been opened for editing explicitly - const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(pImpl->m_pSet, SID_DOC_READONLY, false); + const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(pImpl->m_pSet.get(), SID_DOC_READONLY, false); if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->GetValue()) ) SetError(ERRCODE_IO_ACCESSDENIED); @@ -1300,7 +1300,7 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI ) { // the error should be set in case it is storing process // or the document has been opened for editing explicitly - const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(pImpl->m_pSet, SID_DOC_READONLY, false); + const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(pImpl->m_pSet.get(), SID_DOC_READONLY, false); if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->GetValue()) ) SetError(ERRCODE_IO_ACCESSDENIED); @@ -1421,7 +1421,7 @@ uno::Reference < embed::XStorage > SfxMedium::GetStorage( bool bCreateTempIfNo ) GetVersionList(); } - const SfxInt16Item* pVersion = SfxItemSet::GetItem<SfxInt16Item>(pImpl->m_pSet, SID_VERSION, false); + const SfxInt16Item* pVersion = SfxItemSet::GetItem<SfxInt16Item>(pImpl->m_pSet.get(), SID_VERSION, false); bool bResetStorage = false; if ( pVersion && pVersion->GetValue() ) @@ -1792,8 +1792,7 @@ void SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource, if ( pImpl->pTempFile ) { pImpl->pTempFile->EnableKillingFile(); - delete pImpl->pTempFile; - pImpl->pTempFile = nullptr; + pImpl->pTempFile.reset(); } } else if ( bTransactStarted ) @@ -1899,7 +1898,7 @@ void SfxMedium::Transfer_Impl() if (pImpl->m_aLogicName.startsWith("private:stream")) { // TODO/LATER: support storing to SID_STREAM - const SfxUnoAnyItem* pOutStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet, SID_OUTPUTSTREAM, false); + const SfxUnoAnyItem* pOutStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet.get(), SID_OUTPUTSTREAM, false); if( pOutStreamItem && ( pOutStreamItem->GetValue() >>= rOutStream ) ) { if ( pImpl->xStorage.is() ) @@ -1935,8 +1934,7 @@ void SfxMedium::Transfer_Impl() if ( pImpl->pTempFile ) { pImpl->pTempFile->EnableKillingFile(); - delete pImpl->pTempFile; - pImpl->pTempFile = nullptr; + pImpl->pTempFile.reset(); } } catch( const Exception& ) @@ -2332,7 +2330,7 @@ void SfxMedium::GetLockingStream_Impl() if ( GetURLObject().GetProtocol() == INetProtocol::File && !pImpl->m_xLockingStream.is() ) { - const SfxUnoAnyItem* pWriteStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet, SID_STREAM, false); + const SfxUnoAnyItem* pWriteStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet.get(), SID_STREAM, false); if ( pWriteStreamItem ) pWriteStreamItem->GetValue() >>= pImpl->m_xLockingStream; @@ -2375,8 +2373,8 @@ void SfxMedium::GetMedium_Impl() Reference< css::task::XInteractionHandler > xInteractionHandler = GetInteractionHandler(); //TODO/MBA: need support for SID_STREAM - const SfxUnoAnyItem* pWriteStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet, SID_STREAM, false); - const SfxUnoAnyItem* pInStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet, SID_INPUTSTREAM, false); + const SfxUnoAnyItem* pWriteStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet.get(), SID_STREAM, false); + const SfxUnoAnyItem* pInStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet.get(), SID_INPUTSTREAM, false); if ( pWriteStreamItem ) { pWriteStreamItem->GetValue() >>= pImpl->xStream; @@ -2555,7 +2553,7 @@ void SfxMedium::Init_Impl() // TODO/LATER: handle lifetime of storages pImpl->bDisposeStorage = false; - const SfxStringItem* pSalvageItem = SfxItemSet::GetItem<SfxStringItem>(pImpl->m_pSet, SID_DOC_SALVAGE, false); + const SfxStringItem* pSalvageItem = SfxItemSet::GetItem<SfxStringItem>(pImpl->m_pSet.get(), SID_DOC_SALVAGE, false); if ( pSalvageItem && pSalvageItem->GetValue().isEmpty() ) { pSalvageItem = nullptr; @@ -2592,13 +2590,13 @@ void SfxMedium::Init_Impl() if ( pSalvageItem && !pSalvageItem->GetValue().isEmpty() ) { pImpl->m_aLogicName = pSalvageItem->GetValue(); - DELETEZ( pImpl->m_pURLObj ); + pImpl->m_pURLObj.reset(); pImpl->m_bSalvageMode = true; } // in case output stream is by mistake here // clear the reference - const SfxUnoAnyItem* pOutStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet, SID_OUTPUTSTREAM, false); + const SfxUnoAnyItem* pOutStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet.get(), SID_OUTPUTSTREAM, false); if( pOutStreamItem && ( !( pOutStreamItem->GetValue() >>= rOutStream ) || !pImpl->m_aLogicName.startsWith("private:stream")) ) @@ -2610,7 +2608,7 @@ void SfxMedium::Init_Impl() if (!pImpl->m_aLogicName.isEmpty()) { // if the logic name is set it should be set in MediaDescriptor as well - const SfxStringItem* pFileNameItem = SfxItemSet::GetItem<SfxStringItem>(pImpl->m_pSet, SID_FILE_NAME, false); + const SfxStringItem* pFileNameItem = SfxItemSet::GetItem<SfxStringItem>(pImpl->m_pSet.get(), SID_FILE_NAME, false); if ( !pFileNameItem ) { // let the ItemSet be created if necessary @@ -2659,7 +2657,7 @@ SfxMedium::GetInteractionHandler( bool bGetAlways ) if ( pImpl->m_pSet ) { css::uno::Reference< css::task::XInteractionHandler > xHandler; - const SfxUnoAnyItem* pHandler = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet, SID_INTERACTIONHANDLER, false); + const SfxUnoAnyItem* pHandler = SfxItemSet::GetItem<SfxUnoAnyItem>(pImpl->m_pSet.get(), SID_INTERACTIONHANDLER, false); if ( pHandler && (pHandler->GetValue() >>= xHandler) && xHandler.is() ) return xHandler; } @@ -2903,7 +2901,7 @@ void SfxMedium::SetName( const OUString& aNameP, bool bSetOrigURL ) if( bSetOrigURL ) pImpl->aOrigURL = aNameP; pImpl->m_aLogicName = aNameP; - DELETEZ( pImpl->m_pURLObj ); + pImpl->m_pURLObj.reset(); pImpl->aContent = ::ucbhelper::Content(); Init_Impl(); } @@ -2919,11 +2917,7 @@ void SfxMedium::SetPhysicalName_Impl( const OUString& rNameP ) { if ( rNameP != pImpl->m_aName ) { - if( pImpl->pTempFile ) - { - delete pImpl->pTempFile; - pImpl->pTempFile = nullptr; - } + pImpl->pTempFile.reset(); if ( !pImpl->m_aName.isEmpty() || !rNameP.isEmpty() ) pImpl->aContent = ::ucbhelper::Content(); @@ -2950,11 +2944,10 @@ void SfxMedium::CompleteReOpen() bool bUseInteractionHandler = pImpl->bUseInteractionHandler; pImpl->bUseInteractionHandler = false; - ::utl::TempFile* pTmpFile = nullptr; + std::unique_ptr<::utl::TempFile> pTmpFile; if ( pImpl->pTempFile ) { - pTmpFile = pImpl->pTempFile; - pImpl->pTempFile = nullptr; + pTmpFile = std::move(pImpl->pTempFile); pImpl->m_aName.clear(); } @@ -2965,17 +2958,15 @@ void SfxMedium::CompleteReOpen() if ( pImpl->pTempFile ) { pImpl->pTempFile->EnableKillingFile(); - delete pImpl->pTempFile; + pImpl->pTempFile.reset(); } - pImpl->pTempFile = pTmpFile; + pImpl->pTempFile = std::move(pTmpFile); if ( pImpl->pTempFile ) pImpl->m_aName = pImpl->pTempFile->GetFileName(); } else if (pTmpFile) { pTmpFile->EnableKillingFile(); - delete pTmpFile; - } pImpl->bUseInteractionHandler = bUseInteractionHandler; @@ -2984,7 +2975,7 @@ void SfxMedium::CompleteReOpen() SfxMedium::SfxMedium(const OUString &rName, StreamMode nOpenMode, std::shared_ptr<const SfxFilter> pFilter, SfxItemSet *pInSet) : pImpl(new SfxMedium_Impl) { - pImpl->m_pSet = pInSet; + pImpl->m_pSet.reset( pInSet ); pImpl->m_pFilter = std::move(pFilter); pImpl->m_aLogicName = rName; pImpl->m_nStorOpenMode = nOpenMode; @@ -2994,7 +2985,7 @@ SfxMedium::SfxMedium(const OUString &rName, StreamMode nOpenMode, std::shared_pt SfxMedium::SfxMedium(const OUString &rName, const OUString &rReferer, StreamMode nOpenMode, std::shared_ptr<const SfxFilter> pFilter, SfxItemSet *pInSet) : pImpl(new SfxMedium_Impl) { - pImpl->m_pSet = pInSet; + pImpl->m_pSet.reset( pInSet ); SfxItemSet * s = GetItemSet(); if (s->GetItem(SID_REFERER) == nullptr) { s->Put(SfxStringItem(SID_REFERER, rReferer)); @@ -3009,7 +3000,7 @@ SfxMedium::SfxMedium( const uno::Sequence<beans::PropertyValue>& aArgs ) : pImpl(new SfxMedium_Impl) { SfxAllItemSet *pParams = new SfxAllItemSet( SfxGetpApp()->GetPool() ); - pImpl->m_pSet = pParams; + pImpl->m_pSet.reset( pParams ); TransformParameters( SID_OPENDOC, aArgs, *pParams ); OUString aFilterProvider, aFilterName; @@ -3034,7 +3025,7 @@ SfxMedium::SfxMedium( const uno::Sequence<beans::PropertyValue>& aArgs ) : pImpl->m_pFilter = pImpl->m_pCustomFilter; } - const SfxStringItem* pSalvageItem = SfxItemSet::GetItem<SfxStringItem>(pImpl->m_pSet, SID_DOC_SALVAGE, false); + const SfxStringItem* pSalvageItem = SfxItemSet::GetItem<SfxStringItem>(pImpl->m_pSet.get(), SID_DOC_SALVAGE, false); if( pSalvageItem ) { // QUESTION: there is some treatment of Salvage in Init_Impl; align! @@ -3043,7 +3034,7 @@ SfxMedium::SfxMedium( const uno::Sequence<beans::PropertyValue>& aArgs ) : // if an URL is provided in SalvageItem that means that the FileName refers to a temporary file // that must be copied here - const SfxStringItem* pFileNameItem = SfxItemSet::GetItem<SfxStringItem>(pImpl->m_pSet, SID_FILE_NAME, false); + const SfxStringItem* pFileNameItem = SfxItemSet::GetItem<SfxStringItem>(pImpl->m_pSet.get(), SID_FILE_NAME, false); if (!pFileNameItem) throw uno::RuntimeException(); OUString aNewTempFileURL = SfxMedium::CreateTempCopyWithExt( pFileNameItem->GetValue() ); if ( !aNewTempFileURL.isEmpty() ) @@ -3060,11 +3051,11 @@ SfxMedium::SfxMedium( const uno::Sequence<beans::PropertyValue>& aArgs ) : } } - const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(pImpl->m_pSet, SID_DOC_READONLY, false); + const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(pImpl->m_pSet.get(), SID_DOC_READONLY, false); if ( pReadOnlyItem && pReadOnlyItem->GetValue() ) pImpl->m_bOriginallyLoadedReadOnly = true; - const SfxStringItem* pFileNameItem = SfxItemSet::GetItem<SfxStringItem>(pImpl->m_pSet, SID_FILE_NAME, false); + const SfxStringItem* pFileNameItem = SfxItemSet::GetItem<SfxStringItem>(pImpl->m_pSet.get(), SID_FILE_NAME, false); if (!pFileNameItem) throw uno::RuntimeException(); pImpl->m_aLogicName = pFileNameItem->GetValue(); pImpl->m_nStorOpenMode = pImpl->m_bOriginallyLoadedReadOnly @@ -3140,7 +3131,7 @@ const INetURLObject& SfxMedium::GetURLObject() const { if (!pImpl->m_pURLObj) { - pImpl->m_pURLObj = new INetURLObject( pImpl->m_aLogicName ); + pImpl->m_pURLObj.reset( new INetURLObject( pImpl->m_aLogicName ) ); pImpl->m_pURLObj->SetMark(""); } @@ -3186,8 +3177,8 @@ SfxItemSet* SfxMedium::GetItemSet() const { // this method *must* return an ItemSet, returning NULL can cause crashes if (!pImpl->m_pSet) - pImpl->m_pSet = new SfxAllItemSet( SfxGetpApp()->GetPool() ); - return pImpl->m_pSet; + pImpl->m_pSet.reset( new SfxAllItemSet( SfxGetpApp()->GetPool() ) ); + return pImpl->m_pSet.get(); } @@ -3406,7 +3397,7 @@ void SfxMedium::CreateTempFile( bool bReplace ) if ( !bReplace ) return; - DELETEZ( pImpl->pTempFile ); + pImpl->pTempFile.reset(); pImpl->m_aName.clear(); } @@ -3421,7 +3412,7 @@ void SfxMedium::CreateTempFile( bool bReplace ) // Doesn't make sense. aLogicBase.clear(); } - pImpl->pTempFile = new ::utl::TempFile(aLogicBase.isEmpty() ? nullptr : &aLogicBase); + pImpl->pTempFile.reset( new ::utl::TempFile(aLogicBase.isEmpty() ? nullptr : &aLogicBase) ); pImpl->pTempFile->EnableKillingFile(); pImpl->m_aName = pImpl->pTempFile->GetFileName(); OUString aTmpURL = pImpl->pTempFile->GetURL(); @@ -3517,9 +3508,7 @@ void SfxMedium::CreateTempFile( bool bReplace ) void SfxMedium::CreateTempFileNoCopy() { // this call always replaces the existing temporary file - delete pImpl->pTempFile; - - pImpl->pTempFile = new ::utl::TempFile(); + pImpl->pTempFile.reset(new ::utl::TempFile()); pImpl->pTempFile->EnableKillingFile(); pImpl->m_aName = pImpl->pTempFile->GetFileName(); if ( pImpl->m_aName.isEmpty() ) @@ -3821,7 +3810,7 @@ OUString SfxMedium::SwitchDocumentToTempFile() // remove the readonly state bool bWasReadonly = false; pImpl->m_nStorOpenMode = SFX_STREAM_READWRITE; - const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(pImpl->m_pSet, SID_DOC_READONLY, false); + const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(pImpl->m_pSet.get(), SID_DOC_READONLY, false); if ( pReadOnlyItem && pReadOnlyItem->GetValue() ) bWasReadonly = true; GetItemSet()->ClearItem( SID_DOC_READONLY ); commit fc5df8fe80935785ee47d23b9ba7d878f438b2f8 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 16:05:49 2018 +0200 loplugin:useuniqueptr in ModelData_Impl Change-Id: I66866ed1698fafe59ba31f99df09fb792da410e3 diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index 62d462d2d66d..56b669a5e1e1 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -235,6 +235,9 @@ void UseUniquePtr::CheckForForLoopDelete(const CXXDestructorDecl* destructorDecl StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart())); if (loplugin::hasPathnamePrefix(aFileName, WORKDIR)) continue; + // the std::vector is being passed to another class + if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sfx2/source/explorer/nochaos.cxx")) + return; report( DiagnosticsEngine::Warning, diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index 4240f62f16e2..4f878d32f14d 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -275,8 +275,8 @@ class ModelData_Impl uno::Reference< frame::XStorable2 > m_xStorable2; OUString m_aModuleName; - ::comphelper::SequenceAsHashMap* m_pDocumentPropsHM; - ::comphelper::SequenceAsHashMap* m_pModulePropsHM; + std::unique_ptr<::comphelper::SequenceAsHashMap> m_pDocumentPropsHM; + std::unique_ptr<::comphelper::SequenceAsHashMap> m_pModulePropsHM; ::comphelper::SequenceAsHashMap m_aMediaDescrHM; @@ -381,18 +381,14 @@ ModelData_Impl::ModelData_Impl( SfxStoringHelper& aOwner, ModelData_Impl::~ModelData_Impl() { FreeDocumentProps(); - delete m_pDocumentPropsHM; - delete m_pModulePropsHM; + m_pDocumentPropsHM.reset(); + m_pModulePropsHM.reset(); } void ModelData_Impl::FreeDocumentProps() { - if ( m_pDocumentPropsHM ) - { - delete m_pDocumentPropsHM; - m_pDocumentPropsHM = nullptr; - } + m_pDocumentPropsHM.reset(); } @@ -430,7 +426,7 @@ uno::Reference< frame::XStorable2 > const & ModelData_Impl::GetStorable2() const ::comphelper::SequenceAsHashMap& ModelData_Impl::GetDocProps() { if ( !m_pDocumentPropsHM ) - m_pDocumentPropsHM = new ::comphelper::SequenceAsHashMap( GetModel()->getArgs() ); + m_pDocumentPropsHM.reset( new ::comphelper::SequenceAsHashMap( GetModel()->getArgs() ) ); return *m_pDocumentPropsHM; } @@ -457,7 +453,7 @@ const ::comphelper::SequenceAsHashMap& ModelData_Impl::GetModuleProps() m_pOwner->GetModuleManager()->getByName( GetModuleName() ) >>= aModuleProps; if ( !aModuleProps.getLength() ) throw uno::RuntimeException(); // TODO; - m_pModulePropsHM = new ::comphelper::SequenceAsHashMap( aModuleProps ); + m_pModulePropsHM.reset( new ::comphelper::SequenceAsHashMap( aModuleProps ) ); } return *m_pModulePropsHM; commit 9779cd8715e2e0f62d454f37b8d0ffa140d70e64 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 16:05:30 2018 +0200 loplugin:useuniqueptr in FileDialogHelper_Impl Change-Id: I91f831be99284b61385cee42dc59efd0cf7f45ba diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index f19ea1488b63..52b3f5fa395d 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -1141,7 +1141,7 @@ FileDialogHelper_Impl::~FileDialogHelper_Impl() Application::RemoveUserEvent( mnPostUserEventId ); mnPostUserEventId = nullptr; - delete mpGraphicFilter; + mpGraphicFilter.reset(); if ( mbDeleteMatcher ) delete mpMatcher; @@ -1841,7 +1841,7 @@ void FileDialogHelper_Impl::addGraphicFilter() return; // create the list of filters - mpGraphicFilter = new GraphicFilter; + mpGraphicFilter.reset( new GraphicFilter ); sal_uInt16 i, j, nCount = mpGraphicFilter->GetImportFormatCount(); // compute the extension string for all known import filters diff --git a/sfx2/source/dialog/filedlgimpl.hxx b/sfx2/source/dialog/filedlgimpl.hxx index b7aae374dfcd..38a894e0d42e 100644 --- a/sfx2/source/dialog/filedlgimpl.hxx +++ b/sfx2/source/dialog/filedlgimpl.hxx @@ -50,7 +50,7 @@ namespace sfx2 std::vector< css::beans::StringPair > maFilters; SfxFilterMatcher* mpMatcher; - GraphicFilter* mpGraphicFilter; + std::unique_ptr<GraphicFilter> mpGraphicFilter; FileDialogHelper* mpAntiImpl; VclPtr<vcl::Window> mpPreferredParentWindow; commit 623b56fd6f841617444de7f324bcbb0546d35fb3 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:58:39 2018 +0200 loplugin:useuniqueptr in CntStaticPoolDefaults_Impl Change-Id: I8d7766d473499b4d154debc1aafaf03359078aa3 diff --git a/sfx2/source/explorer/nochaos.cxx b/sfx2/source/explorer/nochaos.cxx index 2ba551d4662a..edb1a560765d 100644 --- a/sfx2/source/explorer/nochaos.cxx +++ b/sfx2/source/explorer/nochaos.cxx @@ -37,7 +37,7 @@ class CntItemPool; class CntStaticPoolDefaults_Impl { static const sal_uInt32 m_nItems = 1; - std::vector<SfxPoolItem*>* m_pDefaults; + std::vector<SfxPoolItem*> mvDefaults; std::unique_ptr<SfxItemInfo[]> m_pItemInfos; private: @@ -49,7 +49,7 @@ public: CntStaticPoolDefaults_Impl(const CntStaticPoolDefaults_Impl&) = delete; CntStaticPoolDefaults_Impl& operator=(const CntStaticPoolDefaults_Impl&) = delete; - std::vector<SfxPoolItem*>* GetDefaults() const { return m_pDefaults; } + std::vector<SfxPoolItem*>* GetDefaults() { return &mvDefaults; } const SfxItemInfo* GetItemInfos() const { return m_pItemInfos.get(); } }; @@ -161,7 +161,7 @@ inline void CntStaticPoolDefaults_Impl::Insert( { sal_uInt16 nPos = pItem->Which() - WID_CHAOS_START; - (*m_pDefaults)[ nPos ] = pItem; + mvDefaults[ nPos ] = pItem; m_pItemInfos[ nPos ]._nSID = 0; m_pItemInfos[ nPos ]._bPoolable = true; } @@ -170,14 +170,12 @@ inline void CntStaticPoolDefaults_Impl::Insert( CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl() { for ( sal_uInt32 n = 0; n < m_nItems; ++n ) - delete (*m_pDefaults)[ n ]; - - delete m_pDefaults; + delete mvDefaults[ n ]; } CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl() -: m_pDefaults( new std::vector<SfxPoolItem*>( m_nItems, nullptr ) ), +: mvDefaults( m_nItems, nullptr ), m_pItemInfos( new SfxItemInfo [ m_nItems ] ) { memset( m_pItemInfos.get(), 0, sizeof( SfxItemInfo ) * m_nItems ); commit 128a2f154bb64189bf740379e86e948a7ec90395 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:49:15 2018 +0200 loplugin:useuniqueptr in GroupData_Impl Change-Id: Icddaf78a58b74338ac763c12c8ac06f464986cac diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx index 61bf957b5713..80d6ce983667 100644 --- a/sfx2/source/doc/doctemplates.cxx +++ b/sfx2/source/doc/doctemplates.cxx @@ -346,7 +346,7 @@ public: class GroupData_Impl { - vector< DocTemplates_EntryData_Impl* > maEntries; + std::vector< std::unique_ptr<DocTemplates_EntryData_Impl> > maEntries; OUString maTitle; OUString maHierarchyURL; OUString maTargetURL; @@ -355,7 +355,6 @@ class GroupData_Impl public: explicit GroupData_Impl( const OUString& rTitle ); - ~GroupData_Impl(); void setInUse() { mbInUse = true; } void setHierarchy( bool bInHierarchy ) { mbInHierarchy = bInHierarchy; } @@ -373,7 +372,7 @@ public: const OUString& rType, const OUString& rHierURL ); size_t count() { return maEntries.size(); } - DocTemplates_EntryData_Impl* getEntry( size_t nPos ) { return maEntries[ nPos ]; } + DocTemplates_EntryData_Impl* getEntry( size_t nPos ) { return maEntries[ nPos ].get(); } }; @@ -2641,14 +2640,6 @@ GroupData_Impl::GroupData_Impl( const OUString& rTitle ) } -GroupData_Impl::~GroupData_Impl() -{ - for (DocTemplates_EntryData_Impl* p : maEntries) - delete p; - maEntries.clear(); -} - - DocTemplates_EntryData_Impl* GroupData_Impl::addEntry( const OUString& rTitle, const OUString& rTargetURL, const OUString& rType, @@ -2657,9 +2648,9 @@ DocTemplates_EntryData_Impl* GroupData_Impl::addEntry( const OUString& rTitle, DocTemplates_EntryData_Impl* pData = nullptr; bool EntryFound = false; - for (DocTemplates_EntryData_Impl* p : maEntries) + for (auto const & p : maEntries) { - pData = p; + pData = p.get(); if ( pData->getTitle() == rTitle ) { EntryFound = true; @@ -2677,7 +2668,7 @@ DocTemplates_EntryData_Impl* GroupData_Impl::addEntry( const OUString& rTitle, pData->setHierarchyURL( rHierURL ); pData->setHierarchy( true ); } - maEntries.push_back( pData ); + maEntries.emplace_back( pData ); } else { commit 77c15a95196d5fd8873901cdf6dccc53898b026b Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:47:16 2018 +0200 loplugin:useuniqueptr in SfxDocTplService_Impl Change-Id: Iacda2920f632a6f21d852d843e97086a23479bbd diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx index eee0ac0363ac..61bf957b5713 100644 --- a/sfx2/source/doc/doctemplates.cxx +++ b/sfx2/source/doc/doctemplates.cxx @@ -185,7 +185,7 @@ class SfxDocTplService_Impl Sequence< OUString > maTemplateDirs; Sequence< OUString > maInternalTemplateDirs; OUString maRootURL; - std::vector< NamePair_Impl* > maNames; + std::vector< std::unique_ptr<NamePair_Impl> > maNames; lang::Locale maLocale; Content maRootContent; bool mbIsInitialized : 1; @@ -506,11 +506,11 @@ void SfxDocTplService_Impl::readFolderList() const size_t nCount = std::min(SAL_N_ELEMENTS(TEMPLATE_SHORT_NAMES_ARY), SAL_N_ELEMENTS(TEMPLATE_LONG_NAMES_ARY)); for (size_t i = 0; i < nCount; ++i) { - NamePair_Impl* pPair = new NamePair_Impl; + std::unique_ptr<NamePair_Impl> pPair( new NamePair_Impl ); pPair->maShortName = OUString::createFromAscii(TEMPLATE_SHORT_NAMES_ARY[i]); pPair->maLongName = SfxResId(TEMPLATE_LONG_NAMES_ARY[i]); - maNames.push_back( pPair ); + maNames.push_back( std::move(pPair) ); } } @@ -519,7 +519,7 @@ OUString SfxDocTplService_Impl::getLongName( const OUString& rShortName ) { OUString aRet; - for (NamePair_Impl* pPair : maNames) + for (auto const & pPair : maNames) { if ( pPair->maShortName == rShortName ) { @@ -1086,9 +1086,6 @@ SfxDocTplService_Impl::SfxDocTplService_Impl( const uno::Reference< XComponentCo SfxDocTplService_Impl::~SfxDocTplService_Impl() { ::osl::MutexGuard aGuard( maMutex ); - - for (NamePair_Impl* p : maNames) - delete p; maNames.clear(); } commit 3e6c792d25738af0944254682c51765d44032a99 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:45:13 2018 +0200 loplugin:useuniqueptr in SfxShell_Impl Change-Id: If59142c2d55da5f3ccf2de101dbd9f18a8bda84c diff --git a/sfx2/source/control/shell.cxx b/sfx2/source/control/shell.cxx index 5f0867e94cae..2f25891ce5e5 100644 --- a/sfx2/source/control/shell.cxx +++ b/sfx2/source/control/shell.cxx @@ -62,8 +62,8 @@ struct SfxShell_Impl: public SfxBroadcaster SfxRepeatTarget* pRepeatTarget; // SbxObjectRef xParent; bool bActive; SfxDisableFlags nDisableFlags; - svtools::AsynchronLink* pExecuter; - svtools::AsynchronLink* pUpdater; + std::unique_ptr<svtools::AsynchronLink> pExecuter; + std::unique_ptr<svtools::AsynchronLink> pUpdater; std::vector<std::unique_ptr<SfxSlot> > aSlotArr; css::uno::Sequence < css::embed::VerbDescriptor > aVerbList; @@ -80,7 +80,7 @@ struct SfxShell_Impl: public SfxBroadcaster { } - virtual ~SfxShell_Impl() override { delete pExecuter; delete pUpdater;} + virtual ~SfxShell_Impl() override { pExecuter.reset(); pUpdater.reset();} }; @@ -400,8 +400,8 @@ void SfxShell::ExecuteSlot( SfxRequest& rReq, bool bAsync ) else { if( !pImpl->pExecuter ) - pImpl->pExecuter = new svtools::AsynchronLink( - Link<void*,void>( this, ShellCall_Impl ) ); + pImpl->pExecuter.reset( new svtools::AsynchronLink( + Link<void*,void>( this, ShellCall_Impl ) ) ); pImpl->pExecuter->Call( new SfxRequest( rReq ) ); } } @@ -654,7 +654,7 @@ void SfxShell::UIFeatureChanged() // something my get stuck in the bunkered tools. Asynchronous call to // prevent recursion. if ( !pImpl->pUpdater ) - pImpl->pUpdater = new svtools::AsynchronLink( Link<void*,void>( this, DispatcherUpdate_Impl ) ); + pImpl->pUpdater.reset( new svtools::AsynchronLink( Link<void*,void>( this, DispatcherUpdate_Impl ) ) ); // Multiple views allowed pImpl->pUpdater->Call( pFrame->GetDispatcher(), true ); commit 4ae318ad0d076bdfdd42f8e1fcff27dc588b3a78 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:43:05 2018 +0200 loplugin:useuniqueptr in SfxModule_Impl Change-Id: I218cd34aefcf8bfbc8a52379fb1e15ec2ef3ac31 diff --git a/sfx2/source/appl/module.cxx b/sfx2/source/appl/module.cxx index 202a4391f5ad..38e9db653104 100644 --- a/sfx2/source/appl/module.cxx +++ b/sfx2/source/appl/module.cxx @@ -44,10 +44,10 @@ class SfxModule_Impl { public: - SfxSlotPool* pSlotPool; - SfxTbxCtrlFactArr_Impl* pTbxCtrlFac; - SfxStbCtrlFactArr_Impl* pStbCtrlFac; - SfxChildWinFactArr_Impl* pFactArr; + std::unique_ptr<SfxSlotPool> pSlotPool; + std::unique_ptr<SfxTbxCtrlFactArr_Impl> pTbxCtrlFac; + std::unique_ptr<SfxStbCtrlFactArr_Impl> pStbCtrlFac; + std::unique_ptr<SfxChildWinFactArr_Impl> pFactArr; OString maResName; SfxModule_Impl(); @@ -61,10 +61,10 @@ SfxModule_Impl::SfxModule_Impl() SfxModule_Impl::~SfxModule_Impl() { - delete pSlotPool; - delete pTbxCtrlFac; - delete pStbCtrlFac; - delete pFactArr; + pSlotPool.reset(); + pTbxCtrlFac.reset(); + pStbCtrlFac.reset(); + pFactArr.reset(); } SFX_IMPL_SUPERCLASS_INTERFACE(SfxModule, SfxShell) @@ -84,11 +84,7 @@ void SfxModule::Construct_Impl(const OString& rResName) { SfxApplication *pApp = SfxApplication::GetOrCreate(); pImpl = new SfxModule_Impl; - pImpl->pSlotPool = new SfxSlotPool(&pApp->GetAppSlotPool_Impl()); - - pImpl->pTbxCtrlFac=nullptr; - pImpl->pStbCtrlFac=nullptr; - pImpl->pFactArr=nullptr; + pImpl->pSlotPool.reset( new SfxSlotPool(&pApp->GetAppSlotPool_Impl()) ); pImpl->maResName = rResName; SetPool( &pApp->GetPool() ); @@ -110,7 +106,7 @@ std::locale SfxModule::GetResLocale() const SfxSlotPool* SfxModule::GetSlotPool() const { - return pImpl->pSlotPool; + return pImpl->pSlotPool.get(); } @@ -119,7 +115,7 @@ void SfxModule::RegisterChildWindow(SfxChildWinFactory *pFact) DBG_ASSERT( pImpl, "No real Module!" ); if (!pImpl->pFactArr) - pImpl->pFactArr = new SfxChildWinFactArr_Impl; + pImpl->pFactArr.reset( new SfxChildWinFactArr_Impl ); for (size_t nFactory=0; nFactory<pImpl->pFactArr->size(); ++nFactory) { @@ -138,7 +134,7 @@ void SfxModule::RegisterChildWindow(SfxChildWinFactory *pFact) void SfxModule::RegisterToolBoxControl( const SfxTbxCtrlFactory& rFact ) { if (!pImpl->pTbxCtrlFac) - pImpl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl; + pImpl->pTbxCtrlFac.reset( new SfxTbxCtrlFactArr_Impl ); #ifdef DBG_UTIL for ( size_t n=0; n<pImpl->pTbxCtrlFac->size(); n++ ) @@ -159,7 +155,7 @@ void SfxModule::RegisterToolBoxControl( const SfxTbxCtrlFactory& rFact ) void SfxModule::RegisterStatusBarControl( const SfxStbCtrlFactory& rFact ) { if (!pImpl->pStbCtrlFac) - pImpl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl; + pImpl->pStbCtrlFac.reset( new SfxStbCtrlFactArr_Impl ); #ifdef DBG_UTIL for ( size_t n=0; n<pImpl->pStbCtrlFac->size(); n++ ) @@ -179,18 +175,18 @@ void SfxModule::RegisterStatusBarControl( const SfxStbCtrlFactory& rFact ) SfxTbxCtrlFactArr_Impl* SfxModule::GetTbxCtrlFactories_Impl() const { - return pImpl->pTbxCtrlFac; + return pImpl->pTbxCtrlFac.get(); } SfxStbCtrlFactArr_Impl* SfxModule::GetStbCtrlFactories_Impl() const { - return pImpl->pStbCtrlFac; + return pImpl->pStbCtrlFac.get(); } SfxChildWinFactArr_Impl* SfxModule::GetChildWinFactories_Impl() const { - return pImpl->pFactArr; + return pImpl->pFactArr.get(); } VclPtr<SfxTabPage> SfxModule::CreateTabPage( sal_uInt16, vcl::Window*, const SfxItemSet& ) commit 177a44100b7dc571c00996fbdffe5258ab174311 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:38:18 2018 +0200 loplugin:useuniqueptr in SfxChildWindowContext Change-Id: Ida7807742f298a2e8acedd4d5edf404c8b3f6440 diff --git a/include/sfx2/childwin.hxx b/include/sfx2/childwin.hxx index f68fa9fbf740..3059d38a5cbb 100644 --- a/include/sfx2/childwin.hxx +++ b/include/sfx2/childwin.hxx @@ -148,7 +148,7 @@ class SFX2_DLLPUBLIC SfxChildWindow VclPtr<vcl::Window> pWindow; // actual contents SfxChildAlignment eChildAlignment; // Current css::drawing::Alignment std::unique_ptr< SfxChildWindow_Impl> pImpl; // Implementation data - SfxChildWindowContext* pContext; // With context-sensitive ChildWindows: + std::unique_ptr<SfxChildWindowContext> pContext; // With context-sensitive ChildWindows: // Another window in pWindow SAL_DLLPRIVATE void ClearWorkwin(); @@ -206,7 +206,7 @@ public: SAL_DLLPRIVATE SfxChildWindowContext* GetContext_Impl() const - { return pContext; } + { return pContext.get(); } SAL_DLLPRIVATE void SetFactory_Impl( SfxChildWinFactory* ); }; diff --git a/sfx2/source/appl/childwin.cxx b/sfx2/source/appl/childwin.cxx index c6f56ee27a78..372d722bdfa2 100644 --- a/sfx2/source/appl/childwin.cxx +++ b/sfx2/source/appl/childwin.cxx @@ -193,8 +193,7 @@ void SfxChildWindow::ClearWorkwin() SfxChildWindow::~SfxChildWindow() { - delete pContext; - pContext = nullptr; + pContext.reset(); ClearWorkwin(); pWindow.disposeAndClear(); } @@ -420,7 +419,7 @@ void SfxChildWindow::InitializeChildWinFactory_Impl(sal_uInt16 nId, SfxChildWinI void SfxChildWindow::CreateContext( sal_uInt16 nContextId, SfxBindings& rBindings ) { - SfxChildWindowContext *pCon = nullptr; + std::unique_ptr<SfxChildWindowContext> pCon; SfxChildWinFactory* pFact=nullptr; SfxApplication *pApp = SfxGetpApp(); SfxDispatcher *pDisp = rBindings.GetDispatcher_Impl(); @@ -447,7 +446,7 @@ void SfxChildWindow::CreateContext( sal_uInt16 nContextId, SfxBindings& rBinding if ( pConFact->nContextId == nContextId ) { SfxChildWinInfo aInfo = pFact->aInfo; - pCon = pConFact->pCtor( GetWindow(), &rBindings, &aInfo ); + pCon.reset( pConFact->pCtor( GetWindow(), &rBindings, &aInfo ) ); pCon->nContextId = pConFact->nContextId; pImpl->pContextModule = pMod; } @@ -478,7 +477,7 @@ void SfxChildWindow::CreateContext( sal_uInt16 nContextId, SfxBindings& rBinding if ( pConFact->nContextId == nContextId ) { SfxChildWinInfo aInfo = pFact->aInfo; - pCon = pConFact->pCtor( GetWindow(), &rBindings, &aInfo ); + pCon.reset( pConFact->pCtor( GetWindow(), &rBindings, &aInfo ) ); pCon->nContextId = pConFact->nContextId; pImpl->pContextModule = nullptr; } @@ -495,9 +494,7 @@ void SfxChildWindow::CreateContext( sal_uInt16 nContextId, SfxBindings& rBinding return; } - if ( pContext ) - delete( pContext ); - pContext = pCon; + pContext = std::move( pCon ); pContext->GetWindow()->SetSizePixel( pWindow->GetOutputSizePixel() ); pContext->GetWindow()->Show(); } commit add35c57d462ed3a2788367eb8e6e7cd9a09ff44 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:28:46 2018 +0200 loplugin:useuniqueptr in HelpInterceptor_Impl Change-Id: I75c1ca2d6b0e03604bb6c96d2613261a1a05b988 diff --git a/sfx2/source/appl/helpinterceptor.cxx b/sfx2/source/appl/helpinterceptor.cxx index 03f81a25e358..a41fc472a02b 100644 --- a/sfx2/source/appl/helpinterceptor.cxx +++ b/sfx2/source/appl/helpinterceptor.cxx @@ -47,29 +47,20 @@ HelpInterceptor_Impl::HelpInterceptor_Impl() : HelpInterceptor_Impl::~HelpInterceptor_Impl() { - if ( m_pHistory ) - { - for (HelpHistoryEntry_Impl* p : *m_pHistory) - delete p; - delete m_pHistory; - } } void HelpInterceptor_Impl::addURL( const OUString& rURL ) { if ( !m_pHistory ) - m_pHistory = new HelpHistoryList_Impl; + m_pHistory.reset( new std::vector<std::unique_ptr<HelpHistoryEntry_Impl>> ); size_t nCount = m_pHistory->size(); if ( nCount && m_nCurPos < ( nCount - 1 ) ) { for ( size_t i = nCount - 1; i > m_nCurPos; i-- ) { - delete m_pHistory->at( i ); - HelpHistoryList_Impl::iterator it = m_pHistory->begin(); - ::std::advance( it, i ); - m_pHistory->erase( it ); + m_pHistory->erase( m_pHistory->begin() + i ); } } Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY); @@ -83,7 +74,7 @@ void HelpInterceptor_Impl::addURL( const OUString& rURL ) m_aCurrentURL = rURL; Any aEmptyViewData; - m_pHistory->push_back( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ) ); + m_pHistory->emplace_back( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ) ); m_nCurPos = m_pHistory->size() - 1; // TODO ? if ( m_xListener.is() ) @@ -229,9 +220,8 @@ void SAL_CALL HelpInterceptor_Impl::dispatch( if ( nPos < ULONG_MAX ) { - HelpHistoryEntry_Impl* pEntry = m_pHistory->at( nPos ); - if ( pEntry ) - m_pWindow->loadHelpContent(pEntry->aURL, false); // false => don't add item to history again! + HelpHistoryEntry_Impl* pEntry = m_pHistory->at( nPos ).get(); + m_pWindow->loadHelpContent(pEntry->aURL, false); // false => don't add item to history again! } m_pWindow->UpdateToolbox(); diff --git a/sfx2/source/appl/helpinterceptor.hxx b/sfx2/source/appl/helpinterceptor.hxx index 41d9665f264b..460e480329b4 100644 --- a/sfx2/source/appl/helpinterceptor.hxx +++ b/sfx2/source/appl/helpinterceptor.hxx @@ -39,8 +39,6 @@ struct HelpHistoryEntry_Impl aURL( rURL ), aViewData(rViewData) {} }; -typedef ::std::vector< HelpHistoryEntry_Impl* > HelpHistoryList_Impl; - class SfxHelpWindow_Impl; class HelpInterceptor_Impl : public ::cppu::WeakImplHelper< css::frame::XDispatchProviderInterceptor, @@ -61,7 +59,7 @@ friend class SfxHelpWindow_Impl; css::uno::Reference< css::frame::XStatusListener > m_xListener; - HelpHistoryList_Impl* m_pHistory; + std::unique_ptr<std::vector<std::unique_ptr<HelpHistoryEntry_Impl>>> m_pHistory; VclPtr<SfxHelpWindow_Impl> m_pWindow; sal_uIntPtr m_nCurPos; OUString m_aCurrentURL; commit 50dcbaf1c586c7146948a0060818da17cfe14424 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:22:48 2018 +0200 loplugin:useuniqueptr in SfxRequest Change-Id: Id2b2a1ac9803b0caa2d28163160d85be5253dd9e diff --git a/include/sfx2/request.hxx b/include/sfx2/request.hxx index 72d98071007f..eb6e1fb0832a 100644 --- a/include/sfx2/request.hxx +++ b/include/sfx2/request.hxx @@ -51,7 +51,7 @@ class SFX2_DLLPUBLIC SfxRequest: public SfxHint friend struct SfxRequest_Impl; sal_uInt16 nSlot; - SfxAllItemSet* pArgs; + std::unique_ptr<SfxAllItemSet> pArgs; std::unique_ptr< SfxRequest_Impl > pImpl; public: @@ -78,7 +78,7 @@ public: void SetModifier( sal_uInt16 nModi ); SAL_DLLPRIVATE void SetInternalArgs_Impl( const SfxAllItemSet& rArgs ); SAL_DLLPRIVATE const SfxItemSet* GetInternalArgs_Impl() const; - const SfxItemSet* GetArgs() const { return pArgs; } + const SfxItemSet* GetArgs() const { return pArgs.get(); } void SetArgs( const SfxAllItemSet& rArgs ); void AppendItem(const SfxPoolItem &); void RemoveItem( sal_uInt16 nSlotId ); diff --git a/sfx2/source/control/request.cxx b/sfx2/source/control/request.cxx index d7e6e6af1346..086aa45ec38c 100644 --- a/sfx2/source/control/request.cxx +++ b/sfx2/source/control/request.cxx @@ -123,7 +123,7 @@ SfxRequest::~SfxRequest() pImpl->Record( uno::Sequence < beans::PropertyValue >() ); // Clear object - delete pArgs; + pArgs.reset(); if ( pImpl->pRetVal ) DeleteItemOnIdle(pImpl->pRetVal); } @@ -408,8 +408,7 @@ void SfxRequest::Record_Impl void SfxRequest::SetArgs( const SfxAllItemSet& rArgs ) { - delete pArgs; - pArgs = new SfxAllItemSet(rArgs); + pArgs.reset(new SfxAllItemSet(rArgs)); pImpl->SetPool( pArgs->GetPool() ); } @@ -417,7 +416,7 @@ void SfxRequest::SetArgs( const SfxAllItemSet& rArgs ) void SfxRequest::AppendItem(const SfxPoolItem &rItem) { if(!pArgs) - pArgs = new SfxAllItemSet(*pImpl->pPool); + pArgs.reset( new SfxAllItemSet(*pImpl->pPool) ); pArgs->Put(rItem, rItem.Which()); } @@ -428,7 +427,7 @@ void SfxRequest::RemoveItem( sal_uInt16 nID ) { pArgs->ClearItem(nID); if ( !pArgs->Count() ) - DELETEZ(pArgs); + pArgs.reset(); } } @@ -480,7 +479,7 @@ void SfxRequest::Done // Keep items if possible, so they can be queried by StarDraw. if ( !pArgs ) { - pArgs = new SfxAllItemSet( rSet ); + pArgs.reset( new SfxAllItemSet( rSet ) ); pImpl->SetPool( pArgs->GetPool() ); } else @@ -500,15 +499,15 @@ void SfxRequest::Done void SfxRequest::Done( bool bRelease ) // [<SfxRequest::Done(SfxItemSet&)>] { - Done_Impl( pArgs ); + Done_Impl( pArgs.get() ); if( bRelease ) - DELETEZ( pArgs ); + pArgs.reset(); } void SfxRequest::ForgetAllArgs() { - DELETEZ( pArgs ); + pArgs.reset(); pImpl->pInternalArgs.reset(); } @@ -530,7 +529,7 @@ void SfxRequest::Cancel() { pImpl->bCancelled = true; pImpl->SetPool( nullptr ); - DELETEZ( pArgs ); + pArgs.reset(); } @@ -757,7 +756,7 @@ bool SfxRequest::AllowsRecording() const void SfxRequest::ReleaseArgs() { - DELETEZ( pArgs ); + pArgs.reset(); pImpl->pInternalArgs.reset(); } commit 28f55a1cff69459e9c583221d39b19ba57ab55da Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:22:36 2018 +0200 loplugin:useuniqueptr in SfxItemDisruptor_Impl Change-Id: Ie85c1a8fd699f68ffcc8853be4bf8a86cfec06e7 diff --git a/sfx2/source/control/itemdel.cxx b/sfx2/source/control/itemdel.cxx index 9ee76fd6a2bb..c6d53ef45936 100644 --- a/sfx2/source/control/itemdel.cxx +++ b/sfx2/source/control/itemdel.cxx @@ -26,7 +26,7 @@ class SfxItemDisruptor_Impl { - SfxPoolItem * pItem; + std::unique_ptr<SfxPoolItem> pItem; Idle m_Idle; private: @@ -64,7 +64,7 @@ SfxItemDisruptor_Impl::~SfxItemDisruptor_Impl() // reset RefCount (was set to SFX_ITEMS_SPECIAL before!) pItem->SetRefCount( 0 ); - delete pItem; + pItem.reset(); } IMPL_LINK_NOARG(SfxItemDisruptor_Impl, Delete, Timer*, void) commit 1dbc2a5cde8d8463b17478cc407227c547c352c6 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:20:30 2018 +0200 loplugin:useuniqueptr in SvBaseLink Change-Id: Iaa133fa7f3b4bc4adea1c1568015327b1694161b diff --git a/include/sfx2/lnkbase.hxx b/include/sfx2/lnkbase.hxx index eaeebe466f40..6809a1d5ded6 100644 --- a/include/sfx2/lnkbase.hxx +++ b/include/sfx2/lnkbase.hxx @@ -88,7 +88,7 @@ protected: // Set LinkSourceName without action void SetName( const OUString & rLn ); - ImplBaseLinkData* pImplData; + std::unique_ptr<ImplBaseLinkData> pImplData; bool m_bIsReadOnly; css::uno::Reference<css::io::XInputStream> diff --git a/sfx2/source/appl/lnkbase2.cxx b/sfx2/source/appl/lnkbase2.cxx index faf9e92957c4..b912cf8d88bb 100644 --- a/sfx2/source/appl/lnkbase2.cxx +++ b/sfx2/source/appl/lnkbase2.cxx @@ -125,7 +125,7 @@ SvBaseLink::SvBaseLink() m_bIsReadOnly(false) { nObjType = OBJECT_CLIENT_SO; - pImplData = new ImplBaseLinkData; + pImplData.reset( new ImplBaseLinkData ); bVisible = bSynchron = true; bWasLastEditOK = false; } @@ -136,7 +136,7 @@ SvBaseLink::SvBaseLink( SfxLinkUpdateMode nUpdateMode, SotClipboardFormatId nCon m_bIsReadOnly(false) { nObjType = OBJECT_CLIENT_SO; - pImplData = new ImplBaseLinkData; + pImplData.reset( new ImplBaseLinkData ); bVisible = bSynchron = true; bWasLastEditOK = false; @@ -231,7 +231,7 @@ SvBaseLink::~SvBaseLink() break; } - delete pImplData; + pImplData.reset(); } IMPL_LINK( SvBaseLink, EndEditHdl, const OUString&, _rNewName, void ) commit 9499ba009faf73769827aa53809c9b5133d9e3b5 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:20:17 2018 +0200 loplugin:useuniqueptr in SvDDEObject Change-Id: Ia7f98a84bd42289ef0673b52e5e74a6a24554402 diff --git a/sfx2/source/appl/impldde.cxx b/sfx2/source/appl/impldde.cxx index 2ed6388bbe97..4428f875bd08 100644 --- a/sfx2/source/appl/impldde.cxx +++ b/sfx2/source/appl/impldde.cxx @@ -126,9 +126,9 @@ SvDDEObject::SvDDEObject() SvDDEObject::~SvDDEObject() { - delete pLink; - delete pRequest; - delete pConnection; + pLink.reset(); + pRequest.reset(); + pConnection.reset(); } bool SvDDEObject::GetData( css::uno::Any & rData /*out param*/, @@ -143,8 +143,7 @@ bool SvDDEObject::GetData( css::uno::Any & rData /*out param*/, OUString sServer( pConnection->GetServiceName() ); OUString sTopic( pConnection->GetTopicName() ); - delete pConnection; - pConnection = new DdeConnection( sServer, sTopic ); + pConnection.reset( new DdeConnection( sServer, sTopic ) ); } if( bWaitForData ) // we are in an rekursive loop, get out again @@ -172,9 +171,7 @@ bool SvDDEObject::GetData( css::uno::Any & rData /*out param*/, { // otherwise it will be executed asynchronously { - delete pRequest; - - pRequest = new DdeRequest( *pConnection, sItem ); + pRequest.reset( new DdeRequest( *pConnection, sItem ) ); pRequest->SetDataHdl( LINK( this, SvDDEObject, ImplGetDDEData ) ); pRequest->SetDoneHdl( LINK( this, SvDDEObject, ImplDoneDDEData ) ); pRequest->SetFormat( SotExchange::GetFormatIdFromMimeType( @@ -213,7 +210,7 @@ bool SvDDEObject::Connect( SvBaseLink * pSvLink ) if( sServer.isEmpty() || sTopic.isEmpty() || sItem.isEmpty() ) return false; - pConnection = new DdeConnection( sServer, sTopic ); + pConnection.reset( new DdeConnection( sServer, sTopic ) ); if( pConnection->GetError() ) { // check if the DDE server knows the "SYSTEM" topic @@ -234,7 +231,7 @@ bool SvDDEObject::Connect( SvBaseLink * pSvLink ) if( SfxLinkUpdateMode::ALWAYS == nLinkType && !pLink && !pConnection->GetError() ) { // Setting up Hot Link, Data will be available at some point later on - pLink = new DdeHotLink( *pConnection, sItem ); + pLink.reset( new DdeHotLink( *pConnection, sItem ) ); pLink->SetDataHdl( LINK( this, SvDDEObject, ImplGetDDEData ) ); pLink->SetDoneHdl( LINK( this, SvDDEObject, ImplDoneDDEData ) ); pLink->SetFormat( pSvLink->GetContentType() ); @@ -347,9 +344,9 @@ IMPL_LINK( SvDDEObject, ImplDoneDDEData, bool, bValid, void ) { DdeTransaction* pReq = nullptr; if( !pLink || ( pLink && pLink->IsBusy() )) - pReq = pRequest; // only the one that is ready + pReq = pRequest.get(); // only the one that is ready else if( pRequest && pRequest->IsBusy() ) - pReq = pLink; // only the one that is ready + pReq = pLink.get(); // only the one that is ready if( pReq ) { @@ -357,7 +354,7 @@ IMPL_LINK( SvDDEObject, ImplDoneDDEData, bool, bValid, void ) { pReq->Execute(); } - else if( pReq == pRequest ) + else if( pReq == pRequest.get() ) { bWaitForData = false; } diff --git a/sfx2/source/appl/impldde.hxx b/sfx2/source/appl/impldde.hxx index 5c2bc3a014c4..d161a783fa61 100644 --- a/sfx2/source/appl/impldde.hxx +++ b/sfx2/source/appl/impldde.hxx @@ -35,9 +35,9 @@ class SvDDEObject : public SvLinkSource { OUString sItem; - DdeConnection* pConnection; - DdeLink* pLink; - DdeRequest* pRequest; + std::unique_ptr<DdeConnection> pConnection; + std::unique_ptr<DdeLink> pLink; + std::unique_ptr<DdeRequest> pRequest; css::uno::Any * pGetData; bool bWaitForData; // waiting for data? commit cc503a8666b239f5301ded96fc97539efffb5962 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:09:56 2018 +0200 loplugin:useuniqueptr in EditFieldInfo Change-Id: I8c4cc4ab212409bce54b64d59d07d77a924ed11c diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx index f6bba5cc89b6..2c2ca5f1285f 100644 --- a/include/editeng/outliner.hxx +++ b/include/editeng/outliner.hxx @@ -500,8 +500,8 @@ private: Outliner* pOutliner; const SvxFieldItem& rFldItem; - Color* pTxtColor; - Color* pFldColor; + std::unique_ptr<Color> pTxtColor; + std::unique_ptr<Color> pFldColor; OUString aRepresentation; @@ -518,28 +518,22 @@ public: { pOutliner = pOutl; nPara = nPa; nPos = nPo; - pTxtColor = nullptr; pFldColor = nullptr; mpSdrPage = nullptr; } - ~EditFieldInfo() - { - delete pTxtColor; - delete pFldColor; - } Outliner* GetOutliner() const { return pOutliner; } const SvxFieldItem& GetField() const { return rFldItem; } - Color* GetTextColor() const { return pTxtColor; } + Color* GetTextColor() const { return pTxtColor.get(); } void SetTextColor( const Color& rColor ) - { delete pTxtColor; pTxtColor = new Color( rColor ); } + { pTxtColor.reset( new Color( rColor ) ); } - Color* GetFieldColor() const { return pFldColor; } + Color* GetFieldColor() const { return pFldColor.get(); } void SetFieldColor( const Color& rColor ) - { delete pFldColor; pFldColor = new Color( rColor ); } + { pFldColor.reset( new Color( rColor ) ); } void ClearFieldColor() - { delete pFldColor; pFldColor = nullptr; } + { pFldColor.reset(); } sal_Int32 GetPara() const { return nPara; } sal_Int32 GetPos() const { return nPos; } commit c3158ef830b10868690aac0cb13c620c5942ae50 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:07:47 2018 +0200 loplugin:useuniqueptr in SfxAppData_Impl Change-Id: Ic8b02f5c6582a992b64f31435332ee37d826ad48 diff --git a/sfx2/source/appl/appdata.cxx b/sfx2/source/appl/appdata.cxx index 920cbdaaea6c..4a277865d830 100644 --- a/sfx2/source/appl/appdata.cxx +++ b/sfx2/source/appl/appdata.cxx @@ -122,11 +122,11 @@ SfxAppData_Impl::SfxAppData_Impl() SfxAppData_Impl::~SfxAppData_Impl() { DeInitDDE(); - delete pBasicManager; + pBasicManager.reset(); #if HAVE_FEATURE_SCRIPTING BasicManagerRepository::revokeCreationListener( *pBasMgrListener ); - delete pBasMgrListener; + pBasMgrListener.reset(); #endif } diff --git a/sfx2/source/inc/appdata.hxx b/sfx2/source/inc/appdata.hxx index 334abf539179..ac5815731d82 100644 --- a/sfx2/source/inc/appdata.hxx +++ b/sfx2/source/inc/appdata.hxx @@ -106,8 +106,9 @@ public: SfxViewFrameArr_Impl* pViewFrames; SfxViewShellArr_Impl* pViewShells; SfxObjectShellArr_Impl* pObjShells; - SfxBasicManagerHolder* pBasicManager; - SfxBasicManagerCreationListener* + std::unique_ptr<SfxBasicManagerHolder> + pBasicManager; + std::unique_ptr<SfxBasicManagerCreationListener> pBasMgrListener; SfxViewFrame* pViewFrame; SfxSlotPool* pSlotPool; commit cbd1f82de7eb945578f3e34894d2c37170a0790f Author: Noel Grandin <[email protected]> Date: Tue Jan 16 15:05:33 2018 +0200 loplugin:useuniqeptr in SbxVariable Change-Id: I788ec594589d9708e12db83a7371b5a8d9fed38c diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index de486209750a..f0ee0f7f7f56 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -2080,7 +2080,7 @@ ErrCode SbMethod::Call( SbxValue* pRet, SbxVariable* pCaller ) // #100883 Own Broadcast for SbMethod void SbMethod::Broadcast( SfxHintId nHintId ) { - if( pCst && !IsSet( SbxFlagBits::NoBroadcast ) ) + if( mpBroadcaster && !IsSet( SbxFlagBits::NoBroadcast ) ) { // Because the method could be called from outside, test here once again // the authorisation @@ -2095,8 +2095,7 @@ void SbMethod::Broadcast( SfxHintId nHintId ) pMod->Compile(); // Block broadcasts while creating new method - SfxBroadcaster* pSave = pCst; - pCst = nullptr; + std::unique_ptr<SfxBroadcaster> pSaveBroadcaster = std::move(mpBroadcaster); SbMethod* pThisCopy = new SbMethod( *this ); SbMethodRef xHolder = pThisCopy; if( mpPar.is() ) @@ -2108,14 +2107,14 @@ void SbMethod::Broadcast( SfxHintId nHintId ) SetParameters( nullptr ); } - pCst = pSave; - pSave->Broadcast( SbxHint( nHintId, pThisCopy ) ); + mpBroadcaster = std::move(pSaveBroadcaster); + mpBroadcaster->Broadcast( SbxHint( nHintId, pThisCopy ) ); SbxFlagBits nSaveFlags = GetFlags(); SetFlag( SbxFlagBits::ReadWrite ); - pCst = nullptr; + pSaveBroadcaster = std::move(mpBroadcaster); Put( pThisCopy->GetValues_Impl() ); - pCst = pSave; + mpBroadcaster = std::move(pSaveBroadcaster); SetFlags( nSaveFlags ); } } diff --git a/basic/source/sbx/sbxvar.cxx b/basic/source/sbx/sbxvar.cxx index 17db37db5c37..30088e0746f9 100644 --- a/basic/source/sbx/sbxvar.cxx +++ b/basic/source/sbx/sbxvar.cxx @@ -56,7 +56,6 @@ class SbxVariableImpl SbxVariable::SbxVariable() : SbxValue() { - pCst = nullptr; pParent = nullptr; nUserData = 0; nHash = 0; @@ -78,7 +77,6 @@ SbxVariable::SbxVariable( const SbxVariable& r ) } #endif } - pCst = nullptr; if( r.CanRead() ) { pParent = r.pParent; @@ -111,7 +109,6 @@ void SbxEnsureParentVariable::SetParent(SbxObject* p) SbxVariable::SbxVariable( SbxDataType t ) : SbxValue( t ) { - pCst = nullptr; pParent = nullptr; nUserData = 0; nHash = 0; @@ -125,18 +122,18 @@ SbxVariable::~SbxVariable() removeDimAsNewRecoverItem( this ); } #endif - delete pCst; + mpBroadcaster.reset(); } // Broadcasting SfxBroadcaster& SbxVariable::GetBroadcaster() { - if( !pCst ) + if( !mpBroadcaster ) { - pCst = new SfxBroadcaster; + mpBroadcaster.reset( new SfxBroadcaster ); } - return *pCst; + return *mpBroadcaster; } SbxArray* SbxVariable::GetParameters() const @@ -150,7 +147,7 @@ SbxArray* SbxVariable::GetParameters() const void SbxVariable::Broadcast( SfxHintId nHintId ) { - if( pCst && !IsSet( SbxFlagBits::NoBroadcast ) ) + if( mpBroadcaster && !IsSet( SbxFlagBits::NoBroadcast ) ) { // Because the method could be called from outside, check the // rights here again @@ -174,8 +171,7 @@ void SbxVariable::Broadcast( SfxHintId nHintId ) SbxVariableRef aBroadcastGuard(this); // Avoid further broadcasting - SfxBroadcaster* pSave = pCst; - pCst = nullptr; + std::unique_ptr<SfxBroadcaster> pSave = std::move(mpBroadcaster); SbxFlagBits nSaveFlags = GetFlags(); SetFlag( SbxFlagBits::ReadWrite ); if( mpPar.is() ) @@ -184,8 +180,7 @@ void SbxVariable::Broadcast( SfxHintId nHintId ) mpPar->GetRef( 0 ) = this; } pSave->Broadcast( SbxHint( nHintId, this ) ); - delete pCst; // who knows already, onto which thoughts someone comes? - pCst = pSave; + mpBroadcaster = std::move(pSave); SetFlags( nSaveFlags ); } } diff --git a/include/basic/sbxvar.hxx b/include/basic/sbxvar.hxx index f90dc939b768..b189d4e32c26 100644 --- a/include/basic/sbxvar.hxx +++ b/include/basic/sbxvar.hxx @@ -224,7 +224,7 @@ class BASIC_DLLPUBLIC SbxVariable : public SbxValue friend class SbMethod; std::unique_ptr<SbxVariableImpl> mpImpl; // Impl data - SfxBroadcaster* pCst; // Broadcaster, if needed + std::unique_ptr<SfxBroadcaster> mpBroadcaster; // Broadcaster, if needed OUString maName; // Name, if available SbxArrayRef mpPar; // Parameter-Array, if set sal_uInt16 nHash; // Hash-ID for search @@ -268,7 +268,7 @@ public: // Sfx-Broadcasting-Support: // Due to data reduction and better DLL-hierarchy currently via casting SfxBroadcaster& GetBroadcaster(); - bool IsBroadcaster() const { return pCst != nullptr; } + bool IsBroadcaster() const { return mpBroadcaster != nullptr; } virtual void Broadcast( SfxHintId nHintId ) override; const SbxObject* GetParent() const { return pParent; } commit 5ce29c328f77e00bbf979699eb23fa85e830cbb1 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:51:22 2018 +0200 loplugin:useuniqueptr in SbiStdObject Change-Id: Ic66d817746de423549c87f58068e47f9942d04fd diff --git a/basic/source/inc/stdobj.hxx b/basic/source/inc/stdobj.hxx index 12eb8dc31234..d7bc4c176493 100644 --- a/basic/source/inc/stdobj.hxx +++ b/basic/source/inc/stdobj.hxx @@ -27,7 +27,7 @@ class SbStdFactory; class SbiStdObject : public SbxObject { - SbStdFactory* pStdFactory; + std::unique_ptr<SbStdFactory> pStdFactory; virtual ~SbiStdObject() override; using SbxVariable::GetInfo; diff --git a/basic/source/runtime/stdobj.cxx b/basic/source/runtime/stdobj.cxx index 23c00519214b..d6349e0000a0 100644 --- a/basic/source/runtime/stdobj.cxx +++ b/basic/source/runtime/stdobj.cxx @@ -724,16 +724,16 @@ SbiStdObject::SbiStdObject( const OUString& r, StarBASIC* pb ) : SbxObject( r ) SetParent( pb ); - pStdFactory = new SbStdFactory; - SbxBase::AddFactory( pStdFactory ); + pStdFactory.reset( new SbStdFactory ); + SbxBase::AddFactory( pStdFactory.get() ); Insert( new SbStdClipboard ); } SbiStdObject::~SbiStdObject() { - SbxBase::RemoveFactory( pStdFactory ); - delete pStdFactory; + SbxBase::RemoveFactory( pStdFactory.get() ); + pStdFactory.reset(); } // Finding an element: commit 9b2754e6797e5903fba147c0f8504c8ccf8ef7ce Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:50:19 2018 +0200 loplugin:useuniqueptr in SbUnoMethod Change-Id: Ibeae1754a18152c3a17379c95e3caa536a8822db diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index fc2b6fac29ef..034ee01d0bba 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -2493,7 +2493,7 @@ SbUnoMethod::SbUnoMethod SbUnoMethod::~SbUnoMethod() { - delete pParamInfoSeq; + pParamInfoSeq.reset(); if( this == pFirst ) pFirst = pNext; @@ -2535,7 +2535,7 @@ const Sequence<ParamInfo>& SbUnoMethod::getParamInfos() Sequence<ParamInfo> aTmp; if (m_xUnoMethod.is()) aTmp = m_xUnoMethod->getParameterInfos(); - pParamInfoSeq = new Sequence<ParamInfo>(aTmp); + pParamInfoSeq.reset( new Sequence<ParamInfo>(aTmp) ); } return *pParamInfoSeq; } diff --git a/basic/source/inc/sbunoobj.hxx b/basic/source/inc/sbunoobj.hxx index b31e34966d4e..2df319ffbb21 100644 --- a/basic/source/inc/sbunoobj.hxx +++ b/basic/source/inc/sbunoobj.hxx @@ -154,7 +154,7 @@ class SbUnoMethod : public SbxMethod friend void clearUnoMethodsForBasic( StarBASIC const * pBasic ); css::uno::Reference< css::reflection::XIdlMethod > m_xUnoMethod; - css::uno::Sequence< css::reflection::ParamInfo >* pParamInfoSeq; + std::unique_ptr<css::uno::Sequence< css::reflection::ParamInfo >> pParamInfoSeq; // #67781 reference to the previous and the next method in the method list SbUnoMethod* pPrev; commit 92ee1858b7865c5f0e256230e494cd8dca1ec3c1 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:48:12 2018 +0200 loplugin:useuniqueptr in SbiGlobals Change-Id: I0ebec3193b4369039f90be4223ebdf6d048b8478 diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx index 6562a3fc9d69..524b392a6e98 100644 --- a/basic/source/classes/sb.cxx +++ b/basic/source/classes/sb.cxx @@ -915,8 +915,8 @@ StarBASIC::StarBASIC( StarBASIC* p, bool bIsDocBasic ) if( !GetSbData()->nInst++ ) { - GetSbData()->pSbFac = new SbiFactory; - AddFactory( GetSbData()->pSbFac ); + GetSbData()->pSbFac.reset( new SbiFactory ); + AddFactory( GetSbData()->pSbFac.get() ); GetSbData()->pTypeFac = new SbTypeFactory; AddFactory( GetSbData()->pTypeFac ); GetSbData()->pClassFac = new SbClassFactory; @@ -925,8 +925,8 @@ StarBASIC::StarBASIC( StarBASIC* p, bool bIsDocBasic ) AddFactory( GetSbData()->pOLEFac ); GetSbData()->pFormFac = new SbFormFactory; AddFactory( GetSbData()->pFormFac ); - GetSbData()->pUnoFac = new SbUnoFactory; - AddFactory( GetSbData()->pUnoFac ); + GetSbData()->pUnoFac.reset( new SbUnoFactory ); + AddFactory( GetSbData()->pUnoFac.get() ); } pRtl = new SbiStdObject(RTLNAME, this ); // Search via StarBasic is always global @@ -954,10 +954,10 @@ StarBASIC::~StarBASIC() if( !--GetSbData()->nInst ) { - RemoveFactory( GetSbData()->pSbFac ); - delete GetSbData()->pSbFac; GetSbData()->pSbFac = nullptr; - RemoveFactory( GetSbData()->pUnoFac ); - delete GetSbData()->pUnoFac; GetSbData()->pUnoFac = nullptr; + RemoveFactory( GetSbData()->pSbFac.get() ); + GetSbData()->pSbFac.reset(); + RemoveFactory( GetSbData()->pUnoFac.get() ); + GetSbData()->pUnoFac.reset(); RemoveFactory( GetSbData()->pTypeFac ); delete GetSbData()->pTypeFac; GetSbData()->pTypeFac = nullptr; RemoveFactory( GetSbData()->pClassFac ); diff --git a/basic/source/classes/sbintern.cxx b/basic/source/classes/sbintern.cxx index dc5d7b697fbe..1c4af0f5fa9b 100644 --- a/basic/source/classes/sbintern.cxx +++ b/basic/source/classes/sbintern.cxx @@ -60,9 +60,9 @@ SbiGlobals::SbiGlobals() SbiGlobals::~SbiGlobals() { - delete pSbFac; - delete pUnoFac; - delete pTransliterationWrapper; + pSbFac.reset(); + pUnoFac.reset(); + pTransliterationWrapper.reset(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basic/source/inc/sbintern.hxx b/basic/source/inc/sbintern.hxx index 4ff2d7ad547c..70e6e69a1e23 100644 --- a/basic/source/inc/sbintern.hxx +++ b/basic/source/inc/sbintern.hxx @@ -80,8 +80,8 @@ struct SbiGlobals { static SbiGlobals* pGlobals; SbiInstance* pInst; // all active runtime instances - SbiFactory* pSbFac; // StarBASIC-Factory - SbUnoFactory* pUnoFac; // Factory for Uno-Structs at DIM AS NEW + std::unique_ptr<SbiFactory> pSbFac; // StarBASIC-Factory + std::unique_ptr<SbUnoFactory> pUnoFac; // Factory for Uno-Structs at DIM AS NEW SbTypeFactory* pTypeFac; // Factory for user defined types SbClassFactory* pClassFac; // Factory for user defined classes (based on class modules) SbOLEFactory* pOLEFac; // Factory for OLE types @@ -98,7 +98,7 @@ struct SbiGlobals bool bGlobalInitErr; bool bRunInit; // true, if RunInit active from the Basic OUString aErrMsg; // buffer for GetErrorText() - ::utl::TransliterationWrapper* pTransliterationWrapper; // For StrComp + std::unique_ptr<::utl::TransliterationWrapper> pTransliterationWrapper; // For StrComp bool bBlockCompilerError; BasicManager* pAppBasMgr; StarBASIC* pMSOMacroRuntimLib; // Lib containing MSO Macro Runtime API entry symbols diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 17ee2b4f969d..58c8b35c9cb1 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -1536,15 +1536,16 @@ void SbRtl_StrComp(StarBASIC *, SbxArray & rPar, bool) sal_Int32 nRetValue = 0; if( bTextCompare ) { - ::utl::TransliterationWrapper* pTransliterationWrapper = GetSbData()->pTransliterationWrapper; + ::utl::TransliterationWrapper* pTransliterationWrapper = GetSbData()->pTransliterationWrapper.get(); if( !pTransliterationWrapper ) { uno::Reference< uno::XComponentContext > xContext = getProcessComponentContext(); - pTransliterationWrapper = GetSbData()->pTransliterationWrapper = + GetSbData()->pTransliterationWrapper.reset( new ::utl::TransliterationWrapper( xContext, TransliterationFlags::IGNORE_CASE | TransliterationFlags::IGNORE_KANA | - TransliterationFlags::IGNORE_WIDTH ); + TransliterationFlags::IGNORE_WIDTH ) ); + pTransliterationWrapper = GetSbData()->pTransliterationWrapper.get(); } LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType(); commit eb8cf9bb9dd6ef2a5fa976230e229997552f8b64 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:41:21 2018 +0200 loplugin:useuniqueptr in SbModule Change-Id: I20525bd69c91ff35c9e569525a0d4556bc184982 diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx index 85ea6d902ec1..6562a3fc9d69 100644 --- a/basic/source/classes/sb.cxx +++ b/basic/source/classes/sb.cxx @@ -626,8 +626,8 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule ) { aOUSource = pClassModule->aOUSource; aComment = pClassModule->aComment; - pImage = pClassModule->pImage; - pBreaks = pClassModule->pBreaks; + pImage = std::move(pClassModule->pImage); + pBreaks = std::move(pClassModule->pBreaks); SetClassName( pClassModule->GetName() ); diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index d83cd2b59874..de486209750a 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -461,9 +461,9 @@ SbModule::SbModule( const OUString& rName, bool bVBACompat ) SbModule::~SbModule() { SAL_INFO("basic","Module named " << GetName() << " is destructing"); - delete pImage; - delete pBreaks; - delete pClassData; + pImage.reset(); + pBreaks.reset(); + pClassData.reset(); mxWrapper = nullptr; } @@ -492,7 +492,7 @@ const SbxObject* SbModule::FindType( const OUString& aTypeName ) const void SbModule::StartDefinitions() { - delete pImage; pImage = nullptr; + pImage.reset(); if( pClassData ) pClassData->clear(); @@ -642,7 +642,7 @@ void SbModule::EndDefinitions( bool bNewState ) void SbModule::Clear() { - delete pImage; pImage = nullptr; + pImage.reset(); if( pClassData ) pClassData->clear(); SbxObject::Clear(); @@ -1524,7 +1524,7 @@ bool SbModule::SetBP( sal_uInt16 nLine ) if( !IsBreakable( nLine ) ) return false; if( !pBreaks ) - pBreaks = new SbiBreakpoints; + pBreaks.reset( new SbiBreakpoints ); size_t i; for( i = 0; i < pBreaks->size(); i++ ) { @@ -1562,8 +1562,7 @@ bool SbModule::ClearBP( sal_uInt16 nLine ) } if( pBreaks->empty() ) { - delete pBreaks; - pBreaks = nullptr; + pBreaks.reset(); } } return bRes; @@ -1571,15 +1570,14 @@ bool SbModule::ClearBP( sal_uInt16 nLine ) void SbModule::ClearAllBP() { - delete pBreaks; - pBreaks = nullptr; + pBreaks.reset(); } void SbModule::fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg ) const { if ( !pImg ) - pImg = pImage; + pImg = pImage.get(); for( sal_uInt32 i = 0; i < pMethods->Count(); i++ ) { SbMethod* pMeth = dynamic_cast<SbMethod*>( pMethods->Get( static_cast<sal_uInt16>(i) ) ); @@ -1606,18 +1604,17 @@ bool SbModule::LoadData( SvStream& rStrm, sal_uInt16 nVer ) rStrm.ReadUChar( bImage ); if( bImage ) { - SbiImage* p = new SbiImage; + std::unique_ptr<SbiImage> p( new SbiImage ); sal_uInt32 nImgVer = 0; if( !p->Load( rStrm, nImgVer ) ) { - delete p; return false; } // If the image is in old format, we fix up the method start offsets if ( nImgVer < B_EXT_IMG_VERSION ) { - fixUpMethodStart( false, p ); + fixUpMethodStart( false, p.get() ); p->ReleaseLegacyBuffer(); } aComment = p->aComment; @@ -1629,15 +1626,13 @@ bool SbModule::LoadData( SvStream& rStrm, sal_uInt16 nVer ) if( nVer == 1 ) { SetSource32( p->aOUSource ); - delete p; } else - pImage = p; + pImage = std::move(p); } else { SetSource32( p->aOUSource ); - delete p; } } return true; diff --git a/basic/source/comp/codegen.cxx b/basic/source/comp/codegen.cxx index aa587ba0e5b5..8b7a0a8142e4 100644 --- a/basic/source/comp/codegen.cxx +++ b/basic/source/comp/codegen.cxx @@ -133,7 +133,7 @@ void SbiCodeGen::Save() if( pParser->IsCodeCompleting() ) return; - SbiImage* p = new SbiImage; + std::unique_ptr<SbiImage> p( new SbiImage ); rMod.StartDefinitions(); // OPTION BASE-Value: p->nDimBase = pParser->nBase; @@ -150,7 +150,7 @@ void SbiCodeGen::Save() nIfaceCount = pParser->aIfaceVector.size(); if( !rMod.pClassData ) - rMod.pClassData = new SbClassData; + rMod.pClassData.reset( new SbClassData ); if( nIfaceCount ) { for( int i = 0 ; i < nIfaceCount ; i++ ) @@ -375,11 +375,7 @@ void SbiCodeGen::Save() } if( !p->IsError() ) { - rMod.pImage = p; - } - else - { - delete p; + rMod.pImage = std::move(p); } rMod.EndDefinitions(); } diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index db68c4988f98..4c2b52d1ca81 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -561,7 +561,7 @@ SbMethod* SbiInstance::GetCaller( sal_uInt16 nLevel ) SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, sal_uInt32 nStart ) : rBasic( *static_cast<StarBASIC*>(pm->pParent) ), pInst( GetSbData()->pInst ), - pMod( pm ), pMeth( pe ), pImg( pMod->pImage ), mpExtCaller(nullptr), m_nLastTime(0) + pMod( pm ), pMeth( pe ), pImg( pMod->pImage.get() ), mpExtCaller(nullptr), m_nLastTime(0) { nFlags = pe ? pe->GetDebugFlags() : BasicDebugFlags::NONE; pIosys = pInst->GetIoSystem(); @@ -3149,10 +3149,9 @@ bool SbiRuntime::implIsClass( SbxObject const * pObj, const OUString& aClass ) { OUString aObjClass = pObj->GetClassName(); SbModule* pClassMod = GetSbData()->pClassFac->FindClass( aObjClass ); - SbClassData* pClassData; - if( pClassMod && (pClassData=pClassMod->pClassData) != nullptr ) + if( pClassMod && pClassMod->pClassData ) { - SbxVariable* pClassVar = pClassData->mxIfaces->Find( aClass, SbxClassType::DontCare ); + SbxVariable* pClassVar = pClassMod->pClassData->mxIfaces->Find( aClass, SbxClassType::DontCare ); bRet = (pClassVar != nullptr); } } diff --git a/include/basic/sbmod.hxx b/include/basic/sbmod.hxx index 56a139e23e59..c38c7435ccef 100644 --- a/include/basic/sbmod.hxx +++ b/include/basic/sbmod.hxx @@ -28,6 +28,7 @@ #include <rtl/ustring.hxx> #include <vector> #include <deque> +#include <memory> #include <basic/basicdllapi.h> #include <basic/codecompletecache.hxx> @@ -62,9 +63,9 @@ protected: css::uno::Reference< css::script::XInvocation > mxWrapper; OUString aOUSource; OUString aComment; - SbiImage* pImage; // the Image - SbiBreakpoints* pBreaks; // Breakpoints - SbClassData* pClassData; + std::unique_ptr<SbiImage> pImage; // the Image + std::unique_ptr<SbiBreakpoints> pBreaks; // Breakpoints + std::unique_ptr<SbClassData> pClassData; bool mbVBACompat; sal_Int32 mnType; SbxObjectRef pDocObject; // an impl object ( used by Document Modules ) commit 4ee6a54dd46aa8f7324a146d24bfb7168f8543cc Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:40:59 2018 +0200 loplugin:useuniqueptr in EMFPBrush Change-Id: I86622a13583137605bf2b6468113da2eb5e4ee0b diff --git a/drawinglayer/source/tools/emfpbrush.cxx b/drawinglayer/source/tools/emfpbrush.cxx index 68ec151a6fe8..c454c940dc03 100644 --- a/drawinglayer/source/tools/emfpbrush.cxx +++ b/drawinglayer/source/tools/emfpbrush.cxx @@ -64,35 +64,6 @@ namespace emfplushelper EMFPBrush::~EMFPBrush() { - if (blendPositions != nullptr) - { - delete[] blendPositions; - blendPositions = nullptr; - } - - if (colorblendPositions != nullptr) - { - delete[] colorblendPositions; - colorblendPositions = nullptr; - } - - if (colorblendColors != nullptr) - { - delete[] colorblendColors; - colorblendColors = nullptr; - } - - if (surroundColors != nullptr) - { - delete[] surroundColors; - surroundColors = nullptr; - } - - if (path) - { - delete path; - path = nullptr; - } } void EMFPBrush::Read(SvStream& s, EmfPlusHelperData const & rR) @@ -153,7 +124,7 @@ namespace emfplushelper surroundColorsNumber = SAL_MAX_INT32 / sizeof(::Color); } - surroundColors = new ::Color[surroundColorsNumber]; + surroundColors.reset( new ::Color[surroundColorsNumber] ); for (int i = 0; i < surroundColorsNumber; i++) { @@ -180,7 +151,7 @@ namespace emfplushelper SAL_INFO("drawinglayer", "EMF+\tpath (brush path gradient)"); SAL_INFO("drawinglayer", "EMF+\theader: 0x" << std::hex << pathHeader << " points: " << std::dec << pathPoints << " additional flags: 0x" << std::hex << pathFlags << std::dec); - path = new EMFPPath(pathPoints); + path.reset( new EMFPPath(pathPoints) ); path->Read(s, pathFlags); s.Seek(pos + pathLength); @@ -197,7 +168,7 @@ namespace emfplushelper sal_uInt64 const pos = s.Tell(); SAL_INFO("drawinglayer", "EMF+\t use boundary, points: " << boundaryPointCount); - path = new EMFPPath(boundaryPointCount); + path.reset( new EMFPPath(boundaryPointCount) ); path->Read(s, 0x0); s.Seek(pos + 8 * boundaryPointCount); @@ -221,8 +192,8 @@ namespace emfplushelper SAL_INFO("drawinglayer", "EMF+\tuse blend, points: " << blendPoints); if (blendPoints<0 || sal_uInt32(blendPoints)>SAL_MAX_INT32 / (2 * sizeof(float))) blendPoints = SAL_MAX_INT32 / (2 * sizeof(float)); - blendPositions = new float[2 * blendPoints]; - blendFactors = blendPositions + blendPoints; + blendPositions.reset( new float[2 * blendPoints] ); + blendFactors = blendPositions.get() + blendPoints; for (int i = 0; i < blendPoints; i++) { @@ -252,8 +223,8 @@ namespace emfplushelper colorblendPoints = SAL_MAX_INT32 / sizeof(::Color); } - colorblendPositions = new float[colorblendPoints]; - colorblendColors = new ::Color[colorblendPoints]; + colorblendPositions.reset( new float[colorblendPoints] ); + colorblendColors.reset( new ::Color[colorblendPoints] ); for (int i = 0; i < colorblendPoints; i++) { @@ -302,8 +273,8 @@ namespace emfplushelper SAL_INFO("drawinglayer", "EMF+\tuse blend, points: " << blendPoints); if (blendPoints<0 || sal_uInt32(blendPoints)>SAL_MAX_INT32 / (2 * sizeof(float))) blendPoints = SAL_MAX_INT32 / (2 * sizeof(float)); - blendPositions = new float[2 * blendPoints]; - blendFactors = blendPositions + blendPoints; + blendPositions.reset( new float[2 * blendPoints] ); + blendFactors = blendPositions.get() + blendPoints; for (int i = 0; i < blendPoints; i++) { @@ -333,8 +304,8 @@ namespace emfplushelper colorblendPoints = sal_uInt32(SAL_MAX_INT32) / sizeof(::Color); } - colorblendPositions = new float[colorblendPoints]; - colorblendColors = new ::Color[colorblendPoints]; + colorblendPositions.reset( new float[colorblendPoints] ); + colorblendColors.reset( new ::Color[colorblendPoints] ); for (int i = 0; i < colorblendPoints; i++) { diff --git a/drawinglayer/source/tools/emfpbrush.hxx b/drawinglayer/source/tools/emfpbrush.hxx index 6a03f6f50e51..b73507817de7 100644 --- a/drawinglayer/source/tools/emfpbrush.hxx +++ b/drawinglayer/source/tools/emfpbrush.hxx @@ -107,14 +107,14 @@ namespace emfplushelper basegfx::B2DHomMatrix brush_transformation; bool hasTransformation; sal_Int32 blendPoints; - float* blendPositions; + std::unique_ptr<float[]> blendPositions; float* blendFactors; sal_Int32 colorblendPoints; - float* colorblendPositions; - ::Color* colorblendColors; + std::unique_ptr<float[]> colorblendPositions; + std::unique_ptr<::Color[]> colorblendColors; sal_Int32 surroundColorsNumber; - ::Color* surroundColors; - EMFPPath *path; + std::unique_ptr<::Color[]> surroundColors; + std::unique_ptr<EMFPPath> path; EmfPlusHatchStyle hatchStyle; EMFPBrush(); commit 6886d51669647cb033c5a857749fa5f6deb9c6fd Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:11:21 2018 +0200 loplugin:useuniqueptr in EMFPPen Change-Id: I2c3c7be4bc3b43f03c45724e7a002e862b50f24b diff --git a/drawinglayer/source/tools/emfppen.cxx b/drawinglayer/source/tools/emfppen.cxx index ac9d63a202d9..096380ee8307 100644 --- a/drawinglayer/source/tools/emfppen.cxx +++ b/drawinglayer/source/tools/emfppen.cxx @@ -82,8 +82,6 @@ namespace emfplushelper EMFPPen::~EMFPPen() { - delete customStartCap; - delete customEndCap; } void EMFPPen::SetStrokeWidth(rendering::StrokeAttributes& rStrokeAttributes, EmfPlusHelperData const & rR, const ::basegfx::B2DHomMatrix& mapModeTransform) @@ -297,7 +295,7 @@ namespace emfplushelper SAL_INFO("drawinglayer", "EMF+\t\tcustomStartCapLen: " << customStartCapLen); sal_uInt64 const pos = s.Tell(); - customStartCap = new EMFPCustomLineCap(); + customStartCap.reset( new EMFPCustomLineCap() ); customStartCap->Read(s, rR); // maybe we don't read everything yet, play it safe ;-) @@ -314,7 +312,7 @@ namespace emfplushelper SAL_INFO("drawinglayer", "EMF+\t\tcustomEndCapLen: " << customEndCapLen); sal_uInt64 const pos = s.Tell(); - customEndCap = new EMFPCustomLineCap(); + customEndCap.reset( new EMFPCustomLineCap() ); customEndCap->Read(s, rR); // maybe we don't read everything yet, play it safe ;-) diff --git a/drawinglayer/source/tools/emfppen.hxx b/drawinglayer/source/tools/emfppen.hxx index d3087bdd5412..5c0818bf8ba5 100644 --- a/drawinglayer/source/tools/emfppen.hxx +++ b/drawinglayer/source/tools/emfppen.hxx @@ -60,9 +60,9 @@ namespace emfplushelper sal_Int32 alignment; std::vector<float> compoundArray; sal_Int32 customStartCapLen; - EMFPCustomLineCap *customStartCap; + std::unique_ptr<EMFPCustomLineCap> customStartCap; sal_Int32 customEndCapLen; - EMFPCustomLineCap *customEndCap; + std::unique_ptr<EMFPCustomLineCap> customEndCap; EMFPPen(); commit 9f077074c3c95f276a419598d95778935f488951 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:10:21 2018 +0200 loplugin:useuniqueptr in GeoTexSvxMultiHatch Change-Id: I3d25a50ed7ebf78214c0d358243f7e286503b8f8 diff --git a/drawinglayer/source/texture/texture3d.cxx b/drawinglayer/source/texture/texture3d.cxx index 9b03362d19e9..069759533cd5 100644 --- a/drawinglayer/source/texture/texture3d.cxx +++ b/drawinglayer/source/texture/texture3d.cxx @@ -327,36 +327,33 @@ namespace drawinglayer const double fAngleA(rHatch.getAngle()); maColor = rHatch.getColor(); mbFillBackground = rHatch.isFillBackground(); - mp0 = new GeoTexSvxHatch( + mp0.reset( new GeoTexSvxHatch( aOutlineRange, aOutlineRange, rHatch.getDistance(), - fAngleA); + fAngleA) ); if(attribute::HatchStyle::Double == rHatch.getStyle() || attribute::HatchStyle::Triple == rHatch.getStyle()) { - mp1 = new GeoTexSvxHatch( + mp1.reset( new GeoTexSvxHatch( aOutlineRange, aOutlineRange, rHatch.getDistance(), - fAngleA + F_PI2); + fAngleA + F_PI2) ); } if(attribute::HatchStyle::Triple == rHatch.getStyle()) { - mp2 = new GeoTexSvxHatch( + mp2.reset( new GeoTexSvxHatch( aOutlineRange, aOutlineRange, rHatch.getDistance(), - fAngleA + F_PI4); + fAngleA + F_PI4) ); } } GeoTexSvxMultiHatch::~GeoTexSvxMultiHatch() { - delete mp0; - delete mp1; - delete mp2; } bool GeoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint& rUV) const diff --git a/include/drawinglayer/texture/texture3d.hxx b/include/drawinglayer/texture/texture3d.hxx index 1c197473824a..628edb1ec670 100644 --- a/include/drawinglayer/texture/texture3d.hxx +++ b/include/drawinglayer/texture/texture3d.hxx @@ -123,9 +123,9 @@ namespace drawinglayer { basegfx::BColor maColor; double mfLogicPixelSize; - GeoTexSvxHatch* mp0; - GeoTexSvxHatch* mp1; - GeoTexSvxHatch* mp2; + std::unique_ptr<GeoTexSvxHatch> mp0; + std::unique_ptr<GeoTexSvxHatch> mp1; + std::unique_ptr<GeoTexSvxHatch> mp2; bool mbFillBackground : 1; commit 280fbe728705d0f55d09b3fd878ca6908a9bbd6c Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:09:06 2018 +0200 loplugin:useuniqueptr in ZBufferProcessor3D Change-Id: I73005afdaf20efe15321a2a073beb3ae4f7a63e3 diff --git a/drawinglayer/source/processor3d/zbufferprocessor3d.cxx b/drawinglayer/source/processor3d/zbufferprocessor3d.cxx index ba12a85ecf12..ab25e329a8b8 100644 --- a/drawinglayer/source/processor3d/zbufferprocessor3d.cxx +++ b/drawinglayer/source/processor3d/zbufferprocessor3d.cxx @@ -430,7 +430,7 @@ namespace drawinglayer // back to front if(!mpRasterPrimitive3Ds) { - const_cast< ZBufferProcessor3D* >(this)->mpRasterPrimitive3Ds = new std::vector< RasterPrimitive3D >; + const_cast< ZBufferProcessor3D* >(this)->mpRasterPrimitive3Ds.reset( new std::vector< RasterPrimitive3D > ); } mpRasterPrimitive3Ds->push_back(RasterPrimitive3D( @@ -494,7 +494,7 @@ namespace drawinglayer // back to front if(!mpRasterPrimitive3Ds) { - const_cast< ZBufferProcessor3D* >(this)->mpRasterPrimitive3Ds = new std::vector< RasterPrimitive3D >; + const_cast< ZBufferProcessor3D* >(this)->mpRasterPrimitive3Ds.reset( new std::vector< RasterPrimitive3D > ); } mpRasterPrimitive3Ds->push_back(RasterPrimitive3D( @@ -598,18 +598,18 @@ namespace drawinglayer maRasterRange.expand(basegfx::B2DPoint(mrBZPixelRaster.getWidth(), nStopLine)); // create the raster converter - mpZBufferRasterConverter3D = new ZBufferRasterConverter3D(mrBZPixelRaster, *this); + mpZBufferRasterConverter3D.reset( new ZBufferRasterConverter3D(mrBZPixelRaster, *this) ); } ZBufferProcessor3D::~ZBufferProcessor3D() { - delete mpZBufferRasterConverter3D; + mpZBufferRasterConverter3D.reset(); if(mpRasterPrimitive3Ds) { OSL_FAIL("ZBufferProcessor3D: destructed, but there are unrendered transparent geometries. Use ZBufferProcessor3D::finish() to render these (!)"); - delete mpRasterPrimitive3Ds; } + mpRasterPrimitive3Ds.reset(); } void ZBufferProcessor3D::finish() @@ -653,8 +653,7 @@ namespace drawinglayer // delete them to signal the destructor that all is done and // to allow asserting there - delete mpRasterPrimitive3Ds; - mpRasterPrimitive3Ds = nullptr; + mpRasterPrimitive3Ds.reset(); } } } // end of namespace processor3d diff --git a/include/drawinglayer/processor3d/zbufferprocessor3d.hxx b/include/drawinglayer/processor3d/zbufferprocessor3d.hxx index 9c1109eecaac..173c0415c29c 100644 --- a/include/drawinglayer/processor3d/zbufferprocessor3d.hxx +++ b/include/drawinglayer/processor3d/zbufferprocessor3d.hxx @@ -24,6 +24,7 @@ #include <drawinglayer/processor3d/defaultprocessor3d.hxx> #include <vcl/bitmapex.hxx> +#include <memory> namespace basegfx { class BZPixelRaster; @@ -62,7 +63,7 @@ namespace drawinglayer basegfx::B3DHomMatrix maInvEyeToView; /// The raster converter for Z-Buffer - ZBufferRasterConverter3D* mpZBufferRasterConverter3D; + std::unique_ptr<ZBufferRasterConverter3D> mpZBufferRasterConverter3D; /* AA value. Defines how many oversamples will be used in X and Y. Values 0, 1 will switch it off while e.g. 2 will use 2x2 pixels for each pixel to create @@ -72,7 +73,7 @@ namespace drawinglayer /* remembered RasterPrimitive3D's which need to be painted back to front for transparent 3D parts */ - std::vector< RasterPrimitive3D >* mpRasterPrimitive3Ds; + std::unique_ptr<std::vector< RasterPrimitive3D >> mpRasterPrimitive3Ds; sal_uInt32 mnStartLine; sal_uInt32 mnStopLine; commit 2feb8b8e60a7a6c63e43eeafac562e2ea43cf523 Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:07:11 2018 +0200 loplugin:useuniqueptr in SvgRadialAtomPrimitive2D Change-Id: I00d1772732075848b25eb34d7c4b0386551c7e5f diff --git a/drawinglayer/source/primitive2d/svggradientprimitive2d.cxx b/drawinglayer/source/primitive2d/svggradientprimitive2d.cxx index 54b750d3df14..0197b4199fb2 100644 --- a/drawinglayer/source/primitive2d/svggradientprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/svggradientprimitive2d.cxx @@ -1049,7 +1049,7 @@ namespace drawinglayer // check and evtl. set translations if(!rTranslateA.equal(rTranslateB)) { - mpTranslate = new VectorPair(rTranslateA, rTranslateB); + mpTranslate.reset( new VectorPair(rTranslateA, rTranslateB) ); } // scale A and B have to be positive @@ -1093,11 +1093,6 @@ namespace drawinglayer SvgRadialAtomPrimitive2D::~SvgRadialAtomPrimitive2D() { - if(mpTranslate) - { - delete mpTranslate; - mpTranslate = nullptr; - } } bool SvgRadialAtomPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const diff --git a/include/drawinglayer/primitive2d/svggradientprimitive2d.hxx b/include/drawinglayer/primitive2d/svggradientprimitive2d.hxx index 8bef69e49825..47322f35e0ec 100644 --- a/include/drawinglayer/primitive2d/svggradientprimitive2d.hxx +++ b/include/drawinglayer/primitive2d/svggradientprimitive2d.hxx @@ -377,7 +377,7 @@ namespace drawinglayer }; /// Only used when focal is set - VectorPair* mpTranslate; + std::unique_ptr<VectorPair> mpTranslate; protected: commit 1f377282dd313bfd85bead0d4ee6394c81b42a6f Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:04:57 2018 +0200 loplugin:useuniqueptr in EMFPPen Change-Id: Icc50b2ff1d6c7490b67d39aed7c3621b74c03bac diff --git a/cppcanvas/source/mtfrenderer/emfppen.cxx b/cppcanvas/source/mtfrenderer/emfppen.cxx index 2bd005e4aab4..aa34a527a33d 100644 --- a/cppcanvas/source/mtfrenderer/emfppen.cxx +++ b/cppcanvas/source/mtfrenderer/emfppen.cxx @@ -91,8 +91,6 @@ namespace cppcanvas EMFPPen::~EMFPPen() { - delete customStartCap; - delete customEndCap; } void EMFPPen::SetStrokeWidth(rendering::StrokeAttributes& rStrokeAttributes, ImplRenderer const & rR, const OutDevState& rState) @@ -267,7 +265,7 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+\t\tcustomStartCapLen: " << customStartCapLen); sal_uInt64 const pos = s.Tell(); - customStartCap = new EMFPCustomLineCap(); + customStartCap.reset( new EMFPCustomLineCap() ); customStartCap->Read(s, rR); // maybe we don't read everything yet, play it safe ;-) @@ -282,7 +280,7 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+\t\tcustomEndCapLen: " << customEndCapLen); sal_uInt64 const pos = s.Tell(); - customEndCap = new EMFPCustomLineCap(); + customEndCap.reset( new EMFPCustomLineCap() ); customEndCap->Read(s, rR); // maybe we don't read everything yet, play it safe ;-) diff --git a/cppcanvas/source/mtfrenderer/emfppen.hxx b/cppcanvas/source/mtfrenderer/emfppen.hxx index d5abfa7e823c..75878df4805d 100644 --- a/cppcanvas/source/mtfrenderer/emfppen.hxx +++ b/cppcanvas/source/mtfrenderer/emfppen.hxx @@ -52,9 +52,9 @@ namespace cppcanvas sal_Int32 alignment; std::vector<float> compoundArray; sal_Int32 customStartCapLen; - EMFPCustomLineCap *customStartCap; + std::unique_ptr<EMFPCustomLineCap> customStartCap; sal_Int32 customEndCapLen; - EMFPCustomLineCap *customEndCap; + std::unique_ptr<EMFPCustomLineCap> customEndCap; EMFPPen(); commit ae745d3c8bd9e9af86a49d13ff401a5f28a7b32d Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:04:01 2018 +0200 loplugin:useuniqueptr in EMFPRegion Change-Id: I19107173318180ec08864e523f4065181eac00cc diff --git a/cppcanvas/source/mtfrenderer/emfpregion.cxx b/cppcanvas/source/mtfrenderer/emfpregion.cxx index efb7effe9800..6c548cd2e9be 100644 --- a/cppcanvas/source/mtfrenderer/emfpregion.cxx +++ b/cppcanvas/source/mtfrenderer/emfpregion.cxx @@ -58,10 +58,6 @@ namespace cppcanvas EMFPRegion::~EMFPRegion() { - if (combineMode) { - delete[] combineMode; - combineMode = nullptr; - } } void EMFPRegion::Read(SvStream& s) @@ -77,7 +73,7 @@ namespace cppcanvas if (parts<0 || sal_uInt32(parts)>SAL_MAX_INT32 / sizeof(sal_Int32)) parts = SAL_MAX_INT32 / sizeof(sal_Int32); - combineMode = new sal_Int32[parts]; + combineMode.reset( new sal_Int32[parts] ); for (int i = 0; i < parts; i++) { s.ReadInt32(combineMode[i]); diff --git a/cppcanvas/source/mtfrenderer/emfpregion.hxx b/cppcanvas/source/mtfrenderer/emfpregion.hxx index 876aebcdbd67..5df1639f63d1 100644 --- a/cppcanvas/source/mtfrenderer/emfpregion.hxx +++ b/cppcanvas/source/mtfrenderer/emfpregion.hxx @@ -27,7 +27,7 @@ namespace cppcanvas struct EMFPRegion : public EMFPObject { sal_Int32 parts; - sal_Int32 *combineMode; + std::unique_ptr<sal_Int32[]> combineMode; sal_Int32 initialState; float ix, iy, iw, ih; commit 9cc88c41d9b950d6e19d15945eff894d4d18a3dc Author: Noel Grandin <[email protected]> Date: Tue Jan 16 14:03:13 2018 +0200 loplugin:useuniqueptr in EMFPBrush Change-Id: I17fc33cfd7c15734fd961fa76c676424900a4373 diff --git a/cppcanvas/source/mtfrenderer/emfpbrush.cxx b/cppcanvas/source/mtfrenderer/emfpbrush.cxx index fb8a41c5d846..d46ddd4698cd 100644 --- a/cppcanvas/source/mtfrenderer/emfpbrush.cxx +++ b/cppcanvas/source/mtfrenderer/emfpbrush.cxx @@ -67,26 +67,7 @@ namespace cppcanvas EMFPBrush::~EMFPBrush() { - if (blendPositions != nullptr) { - delete[] blendPositions; - blendPositions = nullptr; - } ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
