diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-03-27 12:59:19 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-03-28 07:41:52 +0100 |
commit | 42c758281dee346811326cc701a62f5d091db833 (patch) | |
tree | 6ffa5a422004e83ebdeb68d2c915677153e490f4 /sw | |
parent | 9304135b560bbb8c8f197c5a8f7127665aafae47 (diff) |
use unique_ptr for SwTOXTypes
Change-Id: I66e6ce7f2d5f2b9ba8bbf6046a87f2d208a9a768
Reviewed-on: https://gerrit.libreoffice.org/69860
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/docary.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/doc/docnew.cxx | 18 | ||||
-rw-r--r-- | sw/source/core/doc/doctxm.cxx | 8 | ||||
-rw-r--r-- | sw/source/core/tox/tox.cxx | 7 |
4 files changed, 19 insertions, 16 deletions
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx index 53b32d38fad4..5e4ccce81f80 100644 --- a/sw/inc/docary.hxx +++ b/sw/inc/docary.hxx @@ -306,7 +306,7 @@ public: void dumpAsXml(xmlTextWriterPtr pWriter) const; }; -class SwTOXTypes : public SwVectorModifyBase<SwTOXType*> {}; +class SwTOXTypes : public std::vector<std::unique_ptr<SwTOXType>> {}; class SW_DLLPUBLIC SwNumRuleTable : public SwVectorModifyBase<SwNumRule*> { public: diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index e3c9a6b5b116..0ad4588118bc 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -464,7 +464,7 @@ SwDoc::~SwDoc() for( auto n = mpTOXTypes->size(); n; ) { (*mpTOXTypes)[ --n ]->SetInDocDTOR(); - delete (*mpTOXTypes)[ n ]; + (*mpTOXTypes)[ n ].reset(); } mpTOXTypes->clear(); } @@ -816,21 +816,21 @@ void SwDoc::InitTOXTypes() { ShellResource* pShellRes = SwViewShell::GetShellRes(); SwTOXType * pNew = new SwTOXType(TOX_CONTENT, pShellRes->aTOXContentName ); - mpTOXTypes->push_back( pNew ); + mpTOXTypes->emplace_back( pNew ); pNew = new SwTOXType(TOX_INDEX, pShellRes->aTOXIndexName ); - mpTOXTypes->push_back( pNew ); + mpTOXTypes->emplace_back( pNew ); pNew = new SwTOXType(TOX_USER, pShellRes->aTOXUserName ); - mpTOXTypes->push_back( pNew ); + mpTOXTypes->emplace_back( pNew ); pNew = new SwTOXType(TOX_ILLUSTRATIONS, pShellRes->aTOXIllustrationsName ); - mpTOXTypes->push_back( pNew ); + mpTOXTypes->emplace_back( pNew ); pNew = new SwTOXType(TOX_OBJECTS, pShellRes->aTOXObjectsName ); - mpTOXTypes->push_back( pNew ); + mpTOXTypes->emplace_back( pNew ); pNew = new SwTOXType(TOX_TABLES, pShellRes->aTOXTablesName ); - mpTOXTypes->push_back( pNew ); + mpTOXTypes->emplace_back( pNew ); pNew = new SwTOXType(TOX_AUTHORITIES, pShellRes->aTOXAuthoritiesName ); - mpTOXTypes->push_back( pNew ); + mpTOXTypes->emplace_back( pNew ); pNew = new SwTOXType(TOX_CITATION, pShellRes->aTOXCitationName ); - mpTOXTypes->push_back( pNew ); + mpTOXTypes->emplace_back( pNew ); } void SwDoc::ReplaceDefaults(const SwDoc& rSource) diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx index a601054b963e..fbd57a8e1b75 100644 --- a/sw/source/core/doc/doctxm.cxx +++ b/sw/source/core/doc/doctxm.cxx @@ -612,7 +612,7 @@ bool SwDoc::DeleteTOX( const SwTOXBase& rTOXBase, bool bDelNodes ) sal_uInt16 SwDoc::GetTOXTypeCount(TOXTypes eTyp) const { sal_uInt16 nCnt = 0; - for( auto pTOXType : *mpTOXTypes ) + for( auto const & pTOXType : *mpTOXTypes ) if( eTyp == pTOXType->GetType() ) ++nCnt; return nCnt; @@ -621,16 +621,16 @@ sal_uInt16 SwDoc::GetTOXTypeCount(TOXTypes eTyp) const const SwTOXType* SwDoc::GetTOXType( TOXTypes eTyp, sal_uInt16 nId ) const { sal_uInt16 nCnt = 0; - for( auto pTOXType : *mpTOXTypes ) + for( auto const & pTOXType : *mpTOXTypes ) if( eTyp == pTOXType->GetType() && nCnt++ == nId ) - return pTOXType; + return pTOXType.get(); return nullptr; } const SwTOXType* SwDoc::InsertTOXType( const SwTOXType& rTyp ) { SwTOXType * pNew = new SwTOXType( rTyp ); - mpTOXTypes->push_back( pNew ); + mpTOXTypes->emplace_back( pNew ); return pNew; } diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx index 3a3860fb2e53..f72bcc964567 100644 --- a/sw/source/core/tox/tox.cxx +++ b/sw/source/core/tox/tox.cxx @@ -545,14 +545,17 @@ void SwTOXBase::CopyTOXBase( SwDoc* pDoc, const SwTOXBase& rSource ) { maMSTOCExpression = rSource.maMSTOCExpression; SwTOXType* pType = const_cast<SwTOXType*>(rSource.GetTOXType()); - if( pDoc && !pDoc->GetTOXTypes().IsAlive(pType)) + if( pDoc && + std::find_if(pDoc->GetTOXTypes().begin(), pDoc->GetTOXTypes().end(), + [=](const std::unique_ptr<SwTOXType> & p) { return p.get() == pType; }) + == pDoc->GetTOXTypes().end()) { // type not in pDoc, so create it now const SwTOXTypes& rTypes = pDoc->GetTOXTypes(); bool bFound = false; for( size_t n = rTypes.size(); n; ) { - const SwTOXType* pCmp = rTypes[ --n ]; + const SwTOXType* pCmp = rTypes[ --n ].get(); if( pCmp->GetType() == pType->GetType() && pCmp->GetTypeName() == pType->GetTypeName() ) { |