diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-01-11 15:38:54 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-01-14 07:02:36 +0100 |
commit | 101cd1b9cfb2b080a838f3253e6d7f37f483a372 (patch) | |
tree | 0dbf69aba00408e7aa9fd4422e3774f10fe09f75 | |
parent | 57cf9acfde03dd4247b4a40ca10bb3fd2f8bed17 (diff) |
use unique_ptr in SwProgress
Change-Id: I7a5d271b2da175e064d50e8b99460e4e024237fb
Reviewed-on: https://gerrit.libreoffice.org/66188
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sw/source/uibase/app/mainwn.cxx | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/sw/source/uibase/app/mainwn.cxx b/sw/source/uibase/app/mainwn.cxx index 36a34038f856..8adb6212e4ad 100644 --- a/sw/source/uibase/app/mainwn.cxx +++ b/sw/source/uibase/app/mainwn.cxx @@ -30,17 +30,17 @@ struct SwProgress long nStartValue, nStartCount; SwDocShell *pDocShell; - SfxProgress *pProgress; + std::unique_ptr<SfxProgress> pProgress; }; -static std::vector<SwProgress*> *pProgressContainer = nullptr; +static std::vector<std::unique_ptr<SwProgress>> *pProgressContainer = nullptr; static SwProgress *lcl_SwFindProgress( SwDocShell const *pDocShell ) { - for (SwProgress* pTmp : *pProgressContainer) + for (auto& pTmp : *pProgressContainer) { if ( pTmp->pDocShell == pDocShell ) - return pTmp; + return pTmp.get(); } return nullptr; } @@ -48,29 +48,31 @@ static SwProgress *lcl_SwFindProgress( SwDocShell const *pDocShell ) void StartProgress( const char* pMessResId, long nStartValue, long nEndValue, SwDocShell *pDocShell ) { - if( !SW_MOD()->IsEmbeddedLoadSave() ) + if( SW_MOD()->IsEmbeddedLoadSave() ) + return; + + SwProgress *pProgress = nullptr; + + if ( !pProgressContainer ) + pProgressContainer = new std::vector<std::unique_ptr<SwProgress>>; + else { - SwProgress *pProgress = nullptr; + pProgress = lcl_SwFindProgress( pDocShell ); + if ( pProgress ) + ++pProgress->nStartCount; + } - if ( !pProgressContainer ) - pProgressContainer = new std::vector<SwProgress*>; - else - { - if ( nullptr != (pProgress = lcl_SwFindProgress( pDocShell )) ) - ++pProgress->nStartCount; - } - if ( !pProgress ) - { - pProgress = new SwProgress; - pProgress->pProgress = new SfxProgress( pDocShell, - SwResId(pMessResId), - nEndValue - nStartValue ); - pProgress->nStartCount = 1; - pProgress->pDocShell = pDocShell; - pProgressContainer->insert( pProgressContainer->begin(), pProgress ); - } - pProgress->nStartValue = nStartValue; + if ( !pProgress ) + { + pProgress = new SwProgress; + pProgress->pProgress.reset( new SfxProgress( pDocShell, + SwResId(pMessResId), + nEndValue - nStartValue ) ); + pProgress->nStartCount = 1; + pProgress->pDocShell = pDocShell; + pProgressContainer->insert( pProgressContainer->begin(), std::unique_ptr<SwProgress>(pProgress) ); } + pProgress->nStartValue = nStartValue; } void SetProgressState( long nPosition, SwDocShell const *pDocShell ) @@ -91,7 +93,7 @@ void EndProgress( SwDocShell const *pDocShell ) std::vector<SwProgress *>::size_type i; for ( i = 0; i < pProgressContainer->size(); ++i ) { - SwProgress *pTmp = (*pProgressContainer)[i]; + SwProgress *pTmp = (*pProgressContainer)[i].get(); if ( pTmp->pDocShell == pDocShell ) { pProgress = pTmp; @@ -103,8 +105,6 @@ void EndProgress( SwDocShell const *pDocShell ) { pProgress->pProgress->Stop(); pProgressContainer->erase( pProgressContainer->begin() + i ); - delete pProgress->pProgress; - delete pProgress; //#112337# it may happen that the container has been removed //while rescheduling if ( pProgressContainer && pProgressContainer->empty() ) |