editeng/source/rtf/rtfitem.cxx | 24 ++++++++--------- editeng/source/rtf/svxrtf.cxx | 49 ++++++++++++++---------------------- include/editeng/svxrtf.hxx | 8 +---- sfx2/source/appl/workwin.cxx | 55 +++++++++++++++++++---------------------- sfx2/source/inc/workwin.hxx | 2 - 5 files changed, 60 insertions(+), 78 deletions(-)
New commits: commit c30bdfbd22807e3f0c77f13a246ec243153ad7ae Author: Noel Grandin <[email protected]> AuthorDate: Wed Sep 19 11:59:41 2018 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Tue Sep 25 12:48:57 2018 +0200 loplugin:useuniqueptr in SfxWorkWindow Change-Id: I30ae51c05dfbee5fc754d26d3de3e41c30834b31 Reviewed-on: https://gerrit.libreoffice.org/60952 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/sfx2/source/appl/workwin.cxx b/sfx2/source/appl/workwin.cxx index b6906eea72ad..cbf98e721a26 100644 --- a/sfx2/source/appl/workwin.cxx +++ b/sfx2/source/appl/workwin.cxx @@ -585,9 +585,8 @@ void SfxWorkWindow::DeleteControllers_Impl() // Delete Child-Windows while(!aChildWins.empty()) { - auto itr = aChildWins.begin(); - SfxChildWin_Impl* pCW = *itr; - aChildWins.erase(itr); + std::unique_ptr<SfxChildWin_Impl> pCW = std::move(*aChildWins.begin()); + aChildWins.erase(aChildWins.begin()); SfxChildWindow *pChild = pCW->pWin; if (pChild) { @@ -604,8 +603,6 @@ void SfxWorkWindow::DeleteControllers_Impl() pChild->Destroy(); } - delete pCW; - // ATTENTION: The array itself is cleared after this loop!! // Therefore we have to set every array entry to zero as it could be // accessed by calling pChild->Destroy(). @@ -871,7 +868,7 @@ SvBorder SfxWorkWindow::Arrange_Impl() bool SfxWorkWindow::PrepareClose_Impl() { - for (SfxChildWin_Impl* pCW : aChildWins) + for (std::unique_ptr<SfxChildWin_Impl> &pCW : aChildWins) { SfxChildWindow *pChild = pCW->pWin; if ( pChild && !pChild->QueryClose() ) @@ -955,12 +952,12 @@ void SfxWorkWindow::ShowChildren_Impl() { // We have to find the SfxChildWin_Impl to retrieve the // SFX_CHILDWIN flags that can influence visibility. - for (SfxChildWin_Impl* pCWin : aChildWins) + for (std::unique_ptr<SfxChildWin_Impl>& pCWin : aChildWins) { SfxChild_Impl* pChild = pCWin->pCli; if ( pChild == pCli ) { - pCW = pCWin; + pCW = pCWin.get(); break; } } @@ -1248,7 +1245,7 @@ void SfxWorkWindow::UpdateChildWindows_Impl() for ( size_t n=0; n<aChildWins.size(); n++ ) { // any current or in the context available Childwindows - SfxChildWin_Impl *pCW = aChildWins[n]; + SfxChildWin_Impl *pCW = aChildWins[n].get(); SfxChildWindow *pChildWin = pCW->pWin; bool bCreate = false; if ( pCW->nId && (pCW->aInfo.nFlags & SfxChildWindowFlags::ALWAYSAVAILABLE || IsVisible_Impl( pCW->nVisibility ) ) ) @@ -1486,7 +1483,7 @@ void SfxWorkWindow::HidePopups_Impl(bool bHide, bool bParent, sal_uInt16 nId ) if (comphelper::LibreOfficeKit::isActive() && bHide) return; - for (SfxChildWin_Impl* i : aChildWins) + for (std::unique_ptr<SfxChildWin_Impl>& i : aChildWins) { SfxChildWindow *pCW = i->pWin; if (pCW && pCW->GetAlignment() == SfxChildAlignment::NOALIGNMENT && pCW->GetType() != nId) @@ -1522,9 +1519,9 @@ void SfxWorkWindow::ConfigChild_Impl(SfxChildIdentifier eChild, SfxChildWin_Impl *pCW = nullptr; // configure direct childwindow - for (SfxChildWin_Impl* i : aChildWins) + for (std::unique_ptr<SfxChildWin_Impl>& i : aChildWins) { - pCW = i; + pCW = i.get(); SfxChildWindow *pChild = pCW->pWin; if ( pChild && (pChild->GetType() == nId )) { @@ -1758,7 +1755,7 @@ void SfxWorkWindow::SetChildWindowVisible_Impl( sal_uInt32 lId, bool bEnabled, S for (sal_uInt16 n=0; n<nCount; n++) if (pWork->aChildWins[n]->nSaveId == nId) { - pCW = pWork->aChildWins[n]; + pCW = pWork->aChildWins[n].get(); break; } } @@ -1770,7 +1767,7 @@ void SfxWorkWindow::SetChildWindowVisible_Impl( sal_uInt32 lId, bool bEnabled, S for (sal_uInt16 n=0; n<nCount; n++) if (aChildWins[n]->nSaveId == nId) { - pCW = aChildWins[n]; + pCW = aChildWins[n].get(); break; } } @@ -1783,9 +1780,9 @@ void SfxWorkWindow::SetChildWindowVisible_Impl( sal_uInt32 lId, bool bEnabled, S pCW->nId = nId; InitializeChild_Impl( pCW ); if ( pWork && !( pCW->aInfo.nFlags & SfxChildWindowFlags::TASK ) ) - pWork->aChildWins.push_back( pCW ); + pWork->aChildWins.push_back( std::unique_ptr<SfxChildWin_Impl>(pCW) ); else - aChildWins.push_back( pCW ); + aChildWins.push_back( std::unique_ptr<SfxChildWin_Impl>(pCW) ); } pCW->nId = nId; @@ -1809,7 +1806,7 @@ void SfxWorkWindow::ToggleChildWindow_Impl(sal_uInt16 nId, bool bSetFocus) if ( n<nCount ) { // The Window is already known - SfxChildWin_Impl *pCW = aChildWins[n]; + SfxChildWin_Impl *pCW = aChildWins[n].get(); SfxChildWindow *pChild = pCW->pWin; bool bCreationAllowed( true ); @@ -1908,7 +1905,7 @@ bool SfxWorkWindow::HasChildWindow_Impl(sal_uInt16 nId) if (n<nCount) { - SfxChildWin_Impl *pCW = aChildWins[n]; + SfxChildWin_Impl *pCW = aChildWins[n].get(); SfxChildWindow *pChild = pCW->pWin; return ( pChild && pCW->bCreate ); } @@ -1936,7 +1933,7 @@ bool SfxWorkWindow::IsFloating( sal_uInt16 nId ) for (sal_uInt16 n=0; n<nCount; n++) if (pWork->aChildWins[n]->nSaveId == nId) { - pCW = pWork->aChildWins[n]; + pCW = pWork->aChildWins[n].get(); break; } } @@ -1948,7 +1945,7 @@ bool SfxWorkWindow::IsFloating( sal_uInt16 nId ) for (sal_uInt16 n=0; n<nCount; n++) if (aChildWins[n]->nSaveId == nId) { - pCW = aChildWins[n]; + pCW = aChildWins[n].get(); break; } } @@ -1963,9 +1960,9 @@ bool SfxWorkWindow::IsFloating( sal_uInt16 nId ) pCW->nVisibility = SfxVisibilityFlags::Invisible; InitializeChild_Impl( pCW ); if ( pWork && !( pCW->aInfo.nFlags & SfxChildWindowFlags::TASK ) ) - pWork->aChildWins.push_back( pCW ); + pWork->aChildWins.push_back( std::unique_ptr<SfxChildWin_Impl>(pCW) ); else - aChildWins.push_back( pCW ); + aChildWins.push_back( std::unique_ptr<SfxChildWin_Impl>(pCW) ); } SfxChildAlignment eAlign; @@ -1983,7 +1980,7 @@ bool SfxWorkWindow::KnowsChildWindow_Impl(sal_uInt16 nId) sal_uInt16 n; for (n=0; n<nCount; n++) { - pCW = aChildWins[n]; + pCW = aChildWins[n].get(); if ( pCW->nSaveId == nId) break; } @@ -2018,7 +2015,7 @@ void SfxWorkWindow::SetChildWindow_Impl(sal_uInt16 nId, bool bOn, bool bSetFocus for (sal_uInt16 n=0; n<nCount; n++) if (pWork->aChildWins[n]->nSaveId == nId) { - pCW = pWork->aChildWins[n]; + pCW = pWork->aChildWins[n].get(); break; } } @@ -2030,7 +2027,7 @@ void SfxWorkWindow::SetChildWindow_Impl(sal_uInt16 nId, bool bOn, bool bSetFocus for (sal_uInt16 n=0; n<nCount; n++) if (aChildWins[n]->nSaveId == nId) { - pCW = aChildWins[n]; + pCW = aChildWins[n].get(); pWork = this; break; } @@ -2044,7 +2041,7 @@ void SfxWorkWindow::SetChildWindow_Impl(sal_uInt16 nId, bool bOn, bool bSetFocus InitializeChild_Impl( pCW ); if ( !pWork || pCW->aInfo.nFlags & SfxChildWindowFlags::TASK ) pWork = this; - pWork->aChildWins.push_back( pCW ); + pWork->aChildWins.push_back( std::unique_ptr<SfxChildWin_Impl>(pCW) ); } if ( pCW->bCreate != bOn ) @@ -2059,7 +2056,7 @@ void SfxWorkWindow::ShowChildWindow_Impl(sal_uInt16 nId, bool bVisible, bool bSe sal_uInt16 n; for (n=0; n<nCount; n++) { - pCW = aChildWins[n]; + pCW = aChildWins[n].get(); if (pCW->nId == nId) break; } @@ -2157,7 +2154,7 @@ SfxChildWindow* SfxWorkWindow::GetChildWindow_Impl(sal_uInt16 nId) void SfxWorkWindow::ResetChildWindows_Impl() { - for (SfxChildWin_Impl* pChildWin : aChildWins) + for (std::unique_ptr<SfxChildWin_Impl>& pChildWin : aChildWins) { pChildWin->nId = 0; pChildWin->bEnable = false; @@ -2523,7 +2520,7 @@ void SfxWorkWindow::DataChanged_Impl() sal_uInt16 nCount = aChildWins.size(); for (n=0; n<nCount; n++) { - SfxChildWin_Impl*pCW = aChildWins[n]; + SfxChildWin_Impl*pCW = aChildWins[n].get(); if ( pCW && pCW->pWin ) pCW->pWin->GetWindow()->UpdateSettings( Application::GetSettings() ); } diff --git a/sfx2/source/inc/workwin.hxx b/sfx2/source/inc/workwin.hxx index cf332f74c3bd..00abb7d53f1f 100644 --- a/sfx2/source/inc/workwin.hxx +++ b/sfx2/source/inc/workwin.hxx @@ -190,7 +190,7 @@ class SfxWorkWindow final VclPtr<SfxSplitWindow> pSplit[SFX_SPLITWINDOWS_MAX]; std::vector<SfxChild_Impl*> aChildren; - std::vector<SfxChildWin_Impl*> + std::vector<std::unique_ptr<SfxChildWin_Impl>> aChildWins; SfxBindings* pBindings; VclPtr<vcl::Window> pWorkWin; commit c6b8587eef3ead53418312c43012f4322789a33a Author: Noel Grandin <[email protected]> AuthorDate: Wed Sep 19 16:35:10 2018 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Tue Sep 25 12:48:47 2018 +0200 loplugin:useuniqueptr in SvxRTFParser Change-Id: Ib759d5bcc7ce7cd9ea8ad752e5363375fa24e8f0 Reviewed-on: https://gerrit.libreoffice.org/60957 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/editeng/source/rtf/rtfitem.cxx b/editeng/source/rtf/rtfitem.cxx index ef0586291479..9579b8e9eaa2 100644 --- a/editeng/source/rtf/rtfitem.cxx +++ b/editeng/source/rtf/rtfitem.cxx @@ -214,7 +214,7 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) if( !bChkStkPos ) break; - SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); + SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); if( !pCurrent || (pCurrent->pSttNd->GetIdx() == pInsPos->GetNodeIdx() && pCurrent->nSttCnt == pInsPos->GetCntIdx() )) break; @@ -227,17 +227,17 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) pCurrent->nStyleNo ) { // Open a new Group - SvxRTFItemStackType* pNew = new SvxRTFItemStackType( - *pCurrent, *pInsPos, true ); + std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( + *pCurrent, *pInsPos, true )); pNew->SetRTFDefaults( GetRTFDefaults() ); // "Set" all valid attributes up until this point AttrGroupEnd(); - pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); // can be changed after AttrGroupEnd! + pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd! pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr ); - aAttrStack.push_back( pNew ); - pCurrent = pNew; + aAttrStack.push_back( std::move(pNew) ); + pCurrent = aAttrStack.back().get(); } else // continue to use this entry as a new one @@ -268,7 +268,7 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) { sal_uInt16 nStyleNo = -1 == nTokenValue ? 0 : sal_uInt16(nTokenValue); // set StyleNo to the current style on the AttrStack - SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); + SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); if( !pCurrent ) break; @@ -1686,7 +1686,7 @@ void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet ) { if( !bNewGroup && !aAttrStack.empty() ) // not at the beginning of a new group { - SvxRTFItemStackType* pCurrent = aAttrStack.back(); + SvxRTFItemStackType* pCurrent = aAttrStack.back().get(); int nLastToken = GetStackPtr(-1)->nTokenId; bool bNewStkEntry = true; @@ -1697,15 +1697,15 @@ void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet ) if (pCurrent->aAttrSet.Count() || pCurrent->m_pChildList || pCurrent->nStyleNo) { // open a new group - SvxRTFItemStackType* pNew = new SvxRTFItemStackType( *pCurrent, *pInsPos, true ); + std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( *pCurrent, *pInsPos, true )); pNew->SetRTFDefaults( GetRTFDefaults() ); // Set all until here valid attributes AttrGroupEnd(); - pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); // can be changed after AttrGroupEnd! + pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd! pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr ); - aAttrStack.push_back( pNew ); - pCurrent = pNew; + aAttrStack.push_back( std::move(pNew) ); + pCurrent = aAttrStack.back().get(); } else { diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx index 5864354802cd..bfd67ed4ced4 100644 --- a/editeng/source/rtf/svxrtf.cxx +++ b/editeng/source/rtf/svxrtf.cxx @@ -585,12 +585,7 @@ void SvxRTFParser::ClearColorTbl() void SvxRTFParser::ClearAttrStack() { - for( size_t nCnt = aAttrStack.size(); nCnt; --nCnt ) - { - SvxRTFItemStackType* pTmp = aAttrStack.back(); - aAttrStack.pop_back(); - delete pTmp; - } + aAttrStack.clear(); } OUString& SvxRTFParser::DelCharAtEnd( OUString& rStr, const sal_Unicode cDel ) @@ -621,18 +616,18 @@ const vcl::Font& SvxRTFParser::GetFont( sal_uInt16 nId ) SvxRTFItemStackType* SvxRTFParser::GetAttrSet_() { - SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); - SvxRTFItemStackType* pNew; + SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); + std::unique_ptr<SvxRTFItemStackType> pNew; if( pCurrent ) - pNew = new SvxRTFItemStackType( *pCurrent, *pInsPos, false/*bCopyAttr*/ ); + pNew.reset(new SvxRTFItemStackType( *pCurrent, *pInsPos, false/*bCopyAttr*/ )); else - pNew = new SvxRTFItemStackType( *pAttrPool, &aWhichMap[0], - *pInsPos ); + pNew.reset(new SvxRTFItemStackType( *pAttrPool, &aWhichMap[0], + *pInsPos )); pNew->SetRTFDefaults( GetRTFDefaults() ); - aAttrStack.push_back( pNew ); + aAttrStack.push_back( std::move(pNew) ); bNewGroup = false; - return pNew; + return aAttrStack.back().get(); } @@ -684,9 +679,8 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack { if( !aAttrStack.empty() ) { - SvxRTFItemStackType *pOld = aAttrStack.empty() ? nullptr : aAttrStack.back(); - aAttrStack.pop_back(); - SvxRTFItemStackType *pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); + std::unique_ptr<SvxRTFItemStackType> pOld = std::move(aAttrStack.back()); + SvxRTFItemStackType *pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); do { // middle check loop sal_Int32 nOldSttNdIdx = pOld->pSttNd->GetIdx(); @@ -778,7 +772,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack if( pCurrent ) { - pCurrent->Add(std::unique_ptr<SvxRTFItemStackType>(pOld)); + pCurrent->Add(std::move(pOld)); pCurrent->Add(std::move(pNew)); } else @@ -786,10 +780,9 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack // Last off the stack, thus cache it until the next text was // read. (Span no attributes!) - m_AttrSetList.push_back(std::unique_ptr<SvxRTFItemStackType>(pOld)); + m_AttrSetList.push_back(std::move(pOld)); m_AttrSetList.push_back(std::move(pNew)); } - pOld = nullptr; // Do not delete pOld break; } } @@ -813,7 +806,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack if( pCurrent ) { - pCurrent->Add(std::unique_ptr<SvxRTFItemStackType>(pOld)); + pCurrent->Add(std::move(pOld)); // split up and create new entry, because it make no sense // to create a "so long" depend list. Bug 95010 if (bCrsrBack && 50 < pCurrent->m_pChildList->size()) @@ -823,23 +816,21 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack bCrsrBack = false; // Open a new Group. - SvxRTFItemStackType* pNew = new SvxRTFItemStackType( - *pCurrent, *pInsPos, true ); + std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( + *pCurrent, *pInsPos, true )); pNew->SetRTFDefaults( GetRTFDefaults() ); // Set all until here valid Attributes AttrGroupEnd(); - pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); // can be changed after AttrGroupEnd! + pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd! pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr ); - aAttrStack.push_back( pNew ); + aAttrStack.push_back( std::move(pNew) ); } } else // Last off the stack, thus cache it until the next text was // read. (Span no attributes!) - m_AttrSetList.push_back(std::unique_ptr<SvxRTFItemStackType>(pOld)); - - pOld = nullptr; + m_AttrSetList.push_back(std::move(pOld)); } if( bCrsrBack ) @@ -848,8 +839,6 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack } while( false ); - delete pOld; - bNewGroup = false; } } @@ -889,7 +878,7 @@ void SvxRTFParser::SetAttrSet( SvxRTFItemStackType &rSet ) // Has no text been inserted yet? (SttPos from the top Stack entry!) bool SvxRTFParser::IsAttrSttPos() { - SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); + SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); return !pCurrent || (pCurrent->pSttNd->GetIdx() == pInsPos->GetNodeIdx() && pCurrent->nSttCnt == pInsPos->GetCntIdx()); } diff --git a/include/editeng/svxrtf.hxx b/include/editeng/svxrtf.hxx index 89f1cdc4bfae..73634f515e97 100644 --- a/include/editeng/svxrtf.hxx +++ b/include/editeng/svxrtf.hxx @@ -90,10 +90,6 @@ public: typedef std::map<short, std::unique_ptr<vcl::Font>> SvxRTFFontTbl; typedef std::map<sal_uInt16, std::unique_ptr<SvxRTFStyleType>> SvxRTFStyleTbl; -// SvxRTFItemStack can't be "std::stack< SvxRTFItemStackType* >" type, because -// the methods are using operator[] in sw/source/filter/rtf/rtftbl.cxx file -typedef std::deque< SvxRTFItemStackType* > SvxRTFItemStack; - // own helper classes for the RTF Parser struct SvxRTFStyleType { @@ -180,7 +176,7 @@ class EDITENG_DLLPUBLIC SvxRTFParser : public SvRTFParser std::deque< Color* > aColorTbl; SvxRTFFontTbl m_FontTable; SvxRTFStyleTbl m_StyleTable; - SvxRTFItemStack aAttrStack; + std::deque< std::unique_ptr<SvxRTFItemStackType> > aAttrStack; SvxRTFItemStackList m_AttrSetList; RTFPlainAttrMapIds aPlainMap; @@ -364,7 +360,7 @@ inline const Color& SvxRTFParser::GetColor( size_t nId ) const inline SfxItemSet& SvxRTFParser::GetAttrSet() { SvxRTFItemStackType* pTmp; - if( bNewGroup || nullptr == ( pTmp = aAttrStack.empty() ? nullptr : aAttrStack.back()) ) + if( bNewGroup || nullptr == ( pTmp = aAttrStack.empty() ? nullptr : aAttrStack.back().get()) ) pTmp = GetAttrSet_(); return pTmp->aAttrSet; } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
