[Libreoffice-commits] core.git: include/o3tl sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Oct 4 10:46:58 UTC 2018


 include/o3tl/sorted_vector.hxx               |   20 ++++++++++++++++++++
 sw/source/core/crsr/crstrvl.cxx              |    4 ++--
 sw/source/core/doc/DocumentFieldsManager.cxx |    5 ++---
 sw/source/core/doc/doc.cxx                   |    4 ++--
 sw/source/core/doc/docfld.cxx                |   19 ++++++++-----------
 sw/source/core/fields/docufld.cxx            |   11 +++++------
 sw/source/core/fields/fldlst.cxx             |    8 ++++----
 sw/source/core/inc/docfld.hxx                |    4 +---
 8 files changed, 44 insertions(+), 31 deletions(-)

New commits:
commit 04c5f27e8f904f01b1dbfba2b95ed57a9e439f91
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Oct 3 14:04:28 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Oct 4 12:46:33 2018 +0200

    loplugin:useuniqueptr in SetGetExpFields
    
    and a couple more utility methods to o3tl::sorted_vector to make this
    easier
    
    Change-Id: Iebbbb8899b67fffa1ac98ae46b7fa70a7e35f866
    Reviewed-on: https://gerrit.libreoffice.org/61344
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 7c95a1ace24e..6e245353fe70 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -243,6 +243,26 @@ public:
         tmp.release();
         return ret;
     }
+    /**
+     * implement upper_bound for sorted_vectors containing std::unique_ptr
+     */
+    typename super_sorted_vector::const_iterator upper_bound( typename Value::element_type const * x ) const
+    {
+        Value tmp(const_cast<typename Value::element_type*>(x));
+        auto ret = super_sorted_vector::upper_bound(tmp);
+        tmp.release();
+        return ret;
+    }
+    /**
+     * implement lower_bound for sorted_vectors containing std::unique_ptr
+     */
+    typename super_sorted_vector::const_iterator lower_bound( typename Value::element_type const * x ) const
+    {
+        Value tmp(const_cast<typename Value::element_type*>(x));
+        auto ret = super_sorted_vector::lower_bound(tmp);
+        tmp.release();
+        return ret;
+    }
 };
 
 
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 1cedfc908ec8..b93ab75d4718 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -674,9 +674,9 @@ static void lcl_MakeFieldLst(
             if ( pCFrame != nullptr
                  && ( bInReadOnly || !pCFrame->IsProtected() ) )
             {
-                SetGetExpField* pNew = new SetGetExpField( SwNodeIndex( rTextNode ), pTextField );
+                std::unique_ptr<SetGetExpField> pNew(new SetGetExpField( SwNodeIndex( rTextNode ), pTextField ));
                 pNew->SetBodyPos( *pCFrame );
-                rLst.insert( pNew );
+                rLst.insert( std::move(pNew) );
             }
         }
     }
diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx
index d1e5f78af255..208b467a41c0 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -1446,7 +1446,7 @@ void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, const SetGetExpField& r
     {
         SetGetExpFields::const_iterator const itLast =
             mpUpdateFields->GetSortLst()->upper_bound(
-                const_cast<SetGetExpField*>(&rToThisField));
+                &rToThisField);
         for( SetGetExpFields::const_iterator it = mpUpdateFields->GetSortLst()->begin(); it != itLast; ++it )
             lcl_CalcField( m_rDoc, rCalc, **it, pMgr );
     }
@@ -1496,8 +1496,7 @@ void DocumentFieldsManager::FieldsToExpand( SwHashTable<HashStr> & rHashTable,
     rHashTable.resize(nTableSize);
 
     SetGetExpFields::const_iterator const itLast =
-        mpUpdateFields->GetSortLst()->upper_bound(
-            const_cast<SetGetExpField*>(&rToThisField));
+        mpUpdateFields->GetSortLst()->upper_bound(&rToThisField);
 
     for( SetGetExpFields::const_iterator it = mpUpdateFields->GetSortLst()->begin(); it != itLast; ++it )
     {
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index ed90bf3e2fcb..be3f1947d9b9 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -561,8 +561,8 @@ bool sw_GetPostIts(
                 if (pSrtLst)
                 {
                     SwNodeIndex aIdx( pTextField->GetTextNode() );
-                    PostItField_* pNew = new PostItField_( aIdx, pTextField );
-                    pSrtLst->insert( pNew );
+                    std::unique_ptr<PostItField_> pNew(new PostItField_( aIdx, pTextField ));
+                    pSrtLst->insert( std::move(pNew) );
                 }
                 else
                     break;  // we just wanted to check for the existence of postits ...
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 873a69b62cbe..db1d7351e7c3 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -791,7 +791,6 @@ void SwDocUpdateField::InsDelFieldInFieldLst( bool bIns, const SwTextField& rFie
         for( SetGetExpFields::size_type n = 0; n < pFieldSortLst->size(); ++n )
             if( &rField == (*pFieldSortLst)[ n ]->GetPointer() )
             {
-                delete (*pFieldSortLst)[n];
                 pFieldSortLst->erase(n);
                 n--; // one field can occur multiple times
             }
@@ -1001,7 +1000,7 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& rTField, SwFieldIds nFiel
     const SwContentFrame* pFrame = rTextNd.getLayoutFrame(
         rDoc.getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, &tmp);
 
-    SetGetExpField* pNew = nullptr;
+    std::unique_ptr<SetGetExpField> pNew;
     bool bIsInBody = false;
 
     if( !pFrame || pFrame->IsInDocBody() )
@@ -1015,7 +1014,7 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& rTField, SwFieldIds nFiel
         // fields in hidden sections. So: In order to be updated, a field 1)
         // must have a frame, or 2) it must be in the document body.
         if( (pFrame != nullptr) || bIsInBody )
-            pNew = new SetGetExpField( aIdx, &rTField );
+            pNew.reset(new SetGetExpField( aIdx, &rTField ));
     }
     else
     {
@@ -1023,7 +1022,7 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& rTField, SwFieldIds nFiel
         SwPosition aPos( rDoc.GetNodes().GetEndOfPostIts() );
         bool const bResult = GetBodyTextNode( rDoc, aPos, *pFrame );
         OSL_ENSURE(bResult, "where is the Field");
-        pNew = new SetGetExpField( aPos.nNode, &rTField, &aPos.nContent );
+        pNew.reset(new SetGetExpField( aPos.nNode, &rTField, &aPos.nContent ));
     }
 
     // always set the BodyTextFlag in GetExp or DB fields
@@ -1040,14 +1039,13 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& rTField, SwFieldIds nFiel
     }
 #endif
     if( pNew != nullptr )
-        if( !pFieldSortLst->insert( pNew ).second )
-            delete pNew;
+        pFieldSortLst->insert( std::move(pNew) );
 }
 
 void SwDocUpdateField::GetBodyNode( const SwSectionNode& rSectNd )
 {
     const SwDoc& rDoc = *rSectNd.GetDoc();
-    SetGetExpField* pNew = nullptr;
+    std::unique_ptr<SetGetExpField> pNew;
 
     if( rSectNd.GetIndex() < rDoc.GetNodes().GetEndOfExtras().GetIndex() )
     {
@@ -1072,16 +1070,15 @@ void SwDocUpdateField::GetBodyNode( const SwSectionNode& rSectNd )
 
             bool const bResult = GetBodyTextNode( rDoc, aPos, *pFrame );
             OSL_ENSURE(bResult, "where is the Field");
-            pNew = new SetGetExpField( rSectNd, &aPos );
+            pNew.reset(new SetGetExpField( rSectNd, &aPos ));
 
         } while( false );
     }
 
     if( !pNew )
-        pNew = new SetGetExpField( rSectNd );
+        pNew.reset(new SetGetExpField( rSectNd ));
 
-    if( !pFieldSortLst->insert( pNew ).second )
-        delete pNew;
+    pFieldSortLst->insert( std::move(pNew) );
 }
 
 void SwDocUpdateField::InsertFieldType( const SwFieldType& rType )
diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx
index 0281c74a41bd..da1c5b3b1cbc 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -2194,7 +2194,7 @@ bool SwRefPageGetFieldType::MakeSetList( SetGetExpFields& rTmpLst )
                     rTextNd.GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
                     nullptr, &tmp);
 
-                SetGetExpField* pNew;
+                std::unique_ptr<SetGetExpField> pNew;
 
                 if( !pFrame ||
                      pFrame->IsInDocBody() ||
@@ -2204,7 +2204,7 @@ bool SwRefPageGetFieldType::MakeSetList( SetGetExpFields& rTmpLst )
                 {
                     //  create index for determination of the TextNode
                     SwNodeIndex aIdx( rTextNd );
-                    pNew = new SetGetExpField( aIdx, pTField );
+                    pNew.reset( new SetGetExpField( aIdx, pTField ) );
                 }
                 else
                 {
@@ -2212,12 +2212,11 @@ bool SwRefPageGetFieldType::MakeSetList( SetGetExpFields& rTmpLst )
                     SwPosition aPos( m_pDoc->GetNodes().GetEndOfPostIts() );
                     bool const bResult = GetBodyTextNode( *m_pDoc, aPos, *pFrame );
                     OSL_ENSURE(bResult, "where is the Field?");
-                    pNew = new SetGetExpField( aPos.nNode, pTField,
-                                                &aPos.nContent );
+                    pNew.reset( new SetGetExpField( aPos.nNode, pTField,
+                                                &aPos.nContent ) );
                 }
 
-                if( !rTmpLst.insert( pNew ).second)
-                    delete pNew;
+                rTmpLst.insert( std::move(pNew) );
             }
     }
 
diff --git a/sw/source/core/fields/fldlst.cxx b/sw/source/core/fields/fldlst.cxx
index a10a2ead4ed5..02bf47e19b7a 100644
--- a/sw/source/core/fields/fldlst.cxx
+++ b/sw/source/core/fields/fldlst.cxx
@@ -69,8 +69,8 @@ SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
                     else
                     {
                         SwNodeIndex aIdx( rTextNode );
-                        SetGetExpField* pNew = new SetGetExpField(aIdx, pTextField );
-                        mpSrtLst->insert( pNew );
+                        std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
+                        mpSrtLst->insert( std::move(pNew) );
                     }
                 }
             }
@@ -154,8 +154,8 @@ bool SwInputFieldList::BuildSortLst()
                     if( maTmpLst.end() == it )
                     {
                         SwNodeIndex aIdx( rTextNode );
-                        SetGetExpField* pNew = new SetGetExpField(aIdx, pTextField );
-                        mpSrtLst->insert( pNew );
+                        std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
+                        mpSrtLst->insert( std::move(pNew) );
                     }
                     else
                         maTmpLst.erase( it );
diff --git a/sw/source/core/inc/docfld.hxx b/sw/source/core/inc/docfld.hxx
index 33b9a1961108..17704c22448b 100644
--- a/sw/source/core/inc/docfld.hxx
+++ b/sw/source/core/inc/docfld.hxx
@@ -102,10 +102,8 @@ public:
     void SetBodyPos( const SwContentFrame& rFrame );
 };
 
-class SetGetExpFields : public o3tl::sorted_vector<SetGetExpField*, o3tl::less_ptr_to<SetGetExpField> >
+class SetGetExpFields : public o3tl::sorted_vector<std::unique_ptr<SetGetExpField>, o3tl::less_uniqueptr_to<SetGetExpField> >
 {
-public:
-    ~SetGetExpFields() { DeleteAndDestroyAll(); }
 };
 
 // struct for saving strings from the SetExp's string fields


More information about the Libreoffice-commits mailing list