sw/inc/docary.hxx             |    2 +-
 sw/source/core/doc/docnew.cxx |   18 +++++++++---------
 sw/source/core/doc/doctxm.cxx |    8 ++++----
 sw/source/core/tox/tox.cxx    |    7 +++++--
 4 files changed, 19 insertions(+), 16 deletions(-)

New commits:
commit 42c758281dee346811326cc701a62f5d091db833
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Mar 27 12:59:19 2019 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Mar 28 07:41:52 2019 +0100

    use unique_ptr for SwTOXTypes
    
    Change-Id: I66e6ce7f2d5f2b9ba8bbf6046a87f2d208a9a768
    Reviewed-on: https://gerrit.libreoffice.org/69860
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

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() )
             {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to