From 7ec60cdc3a6ca76d96411288ad55435de39c4b0c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 11 Aug 2018 10:22:05 +0200 Subject: loplugin:useuniqueptr pass XEditAttribute around by std::unique_ptr Change-Id: Idaf02002cecb1300a5fc3bcb0e298b11a1958bb1 Reviewed-on: https://gerrit.libreoffice.org/59008 Tested-by: Jenkins Reviewed-by: Noel Grandin --- editeng/source/editeng/editobj.cxx | 13 ++++++------- editeng/source/editeng/editobj2.hxx | 4 ++-- editeng/source/editeng/impedit4.cxx | 6 +++--- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'editeng') diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx index 9b7fa07924d6..57eea220c5a8 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -60,12 +60,12 @@ using std::endl; using namespace com::sun::star; -XEditAttribute* MakeXEditAttribute( SfxItemPool& rPool, const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd ) +std::unique_ptr MakeXEditAttribute( SfxItemPool& rPool, const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd ) { // Create thw new attribute in the pool const SfxPoolItem& rNew = rPool.Put( rItem ); - XEditAttribute* pNew = new XEditAttribute( rNew, nStart, nEnd ); + std::unique_ptr pNew(new XEditAttribute( rNew, nStart, nEnd )); return pNew; } @@ -130,9 +130,9 @@ ContentInfo::ContentInfo( const ContentInfo& rCopyFrom, SfxItemPool& rPoolToUse for (const auto & aAttrib : rCopyFrom.maCharAttribs) { const XEditAttribute& rAttr = *aAttrib.get(); - XEditAttribute* pMyAttr = MakeXEditAttribute( + std::unique_ptr pMyAttr = MakeXEditAttribute( rPoolToUse, *rAttr.GetItem(), rAttr.GetStart(), rAttr.GetEnd()); - maCharAttribs.push_back(std::unique_ptr(pMyAttr)); + maCharAttribs.push_back(std::move(pMyAttr)); } if ( rCopyFrom.GetWrongList() ) @@ -644,15 +644,14 @@ void EditTextObjectImpl::SetScriptType( SvtScriptType nType ) nScriptType = nType; } -XEditAttribute* EditTextObjectImpl::CreateAttrib( const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd ) +std::unique_ptr EditTextObjectImpl::CreateAttrib( const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd ) { return MakeXEditAttribute( *pPool, rItem, nStart, nEnd ); } -void EditTextObjectImpl::DestroyAttrib( XEditAttribute* pAttr ) +void EditTextObjectImpl::DestroyAttrib( std::unique_ptr pAttr ) { pPool->Remove( *pAttr->GetItem() ); - delete pAttr; } diff --git a/editeng/source/editeng/editobj2.hxx b/editeng/source/editeng/editobj2.hxx index b30fadb3fe63..7da37fc2f31d 100644 --- a/editeng/source/editeng/editobj2.hxx +++ b/editeng/source/editeng/editobj2.hxx @@ -219,8 +219,8 @@ public: void SetScriptType( SvtScriptType nType ); ContentInfo* CreateAndInsertContent(); - XEditAttribute* CreateAttrib( const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd ); - void DestroyAttrib( XEditAttribute* pAttr ); + std::unique_ptr CreateAttrib( const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd ); + void DestroyAttrib( std::unique_ptr pAttr ); ContentInfosType& GetContents() { return aContents;} const ContentInfosType& GetContents() const { return aContents;} diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index b9b55534b37e..5c2378917381 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -1060,7 +1060,7 @@ std::unique_ptr ImpEditEngine::CreateTextObject( EditSelection a if ( bEmptyPara || ( ( pAttr->GetEnd() > nStartPos ) && ( pAttr->GetStart() < nEndPos ) ) ) { - XEditAttribute* pX = pTxtObj->mpImpl->CreateAttrib(*pAttr->GetItem(), pAttr->GetStart(), pAttr->GetEnd()); + std::unique_ptr pX = pTxtObj->mpImpl->CreateAttrib(*pAttr->GetItem(), pAttr->GetStart(), pAttr->GetEnd()); // Possibly Correct ... if ( ( nNode == nStartNode ) && ( nStartPos != 0 ) ) { @@ -1075,9 +1075,9 @@ std::unique_ptr ImpEditEngine::CreateTextObject( EditSelection a } DBG_ASSERT( pX->GetEnd() <= (nEndPos-nStartPos), "CreateBinTextObject: Attribute too long!" ); if ( !pX->GetLen() && !bEmptyPara ) - pTxtObj->mpImpl->DestroyAttrib(pX); + pTxtObj->mpImpl->DestroyAttrib(std::move(pX)); else - pC->GetCharAttribs().push_back(std::unique_ptr(pX)); + pC->GetCharAttribs().push_back(std::move(pX)); } nAttr++; pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr ); -- cgit