[Libreoffice-commits] core.git: sc/source

Noel Grandin noel.grandin at collabora.co.uk
Fri Jul 6 08:47:22 UTC 2018


 sc/source/filter/excel/excrecds.cxx |    4 +--
 sc/source/filter/excel/xeescher.cxx |   13 ++++-----
 sc/source/filter/inc/xcl97rec.hxx   |   19 ++++++--------
 sc/source/filter/inc/xeescher.hxx   |    4 +--
 sc/source/filter/xcl97/xcl97esc.cxx |   10 +++----
 sc/source/filter/xcl97/xcl97rec.cxx |   48 ++++++++++++++++--------------------
 6 files changed, 45 insertions(+), 53 deletions(-)

New commits:
commit df8589bd49d7eb1bb42ae78abcb91d33cf9255ce
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Jul 5 15:01:31 2018 +0200

    loplugin:useuniqueptr in XclExpObjList
    
    Change-Id: Ia7f2be93d6306d72773ab611de2945c8a711a2d9
    Reviewed-on: https://gerrit.libreoffice.org/57010
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx
index 61daa9295ee6..49988ed954a6 100644
--- a/sc/source/filter/excel/excrecds.cxx
+++ b/sc/source/filter/excel/excrecds.cxx
@@ -1013,8 +1013,8 @@ void ExcAutoFilterRecs::AddObjRecs()
         ScAddress aAddr( m_pFilterInfo->GetStartPos() );
         for( SCCOL nObj = 0, nCount = m_pFilterInfo->GetColCount(); nObj < nCount; nObj++ )
         {
-            XclObj* pObjRec = new XclObjDropDown( GetObjectManager(), aAddr, IsFiltered( nObj ) );
-            GetObjectManager().AddObj( pObjRec );
+            std::unique_ptr<XclObj> pObjRec(new XclObjDropDown( GetObjectManager(), aAddr, IsFiltered( nObj ) ));
+            GetObjectManager().AddObj( std::move(pObjRec) );
             aAddr.IncCol();
         }
     }
diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx
index c2e9aba3b175..971eb25998f6 100644
--- a/sc/source/filter/excel/xeescher.cxx
+++ b/sc/source/filter/excel/xeescher.cxx
@@ -39,6 +39,7 @@
 #include <svx/svdocapt.hxx>
 #include <editeng/outlobj.hxx>
 #include <editeng/editobj.hxx>
+#include <o3tl/make_unique.hxx>
 #include <unotools/tempfile.hxx>
 #include <unotools/ucbstreamhelper.hxx>
 #include <svtools/embedhlp.hxx>
@@ -1200,7 +1201,7 @@ XclExpNote::XclExpNote(const XclExpRoot& rRoot, const ScAddress& rScPos,
                 {
                     lcl_GetFromTo( rRoot, pCaption->GetLogicRect(), maScPos.Tab(), maCommentFrom, maCommentTo );
                     if( const OutlinerParaObject* pOPO = pCaption->GetOutlinerParaObject() )
-                        mnObjId = rRoot.GetObjectManager().AddObj( new XclObjComment( rRoot.GetObjectManager(), pCaption->GetLogicRect(), pOPO->GetTextObject(), pCaption, mbVisible, maScPos, maCommentFrom, maCommentTo ) );
+                        mnObjId = rRoot.GetObjectManager().AddObj( o3tl::make_unique<XclObjComment>( rRoot.GetObjectManager(), pCaption->GetLogicRect(), pOPO->GetTextObject(), pCaption, mbVisible, maScPos, maCommentFrom, maCommentTo ) );
 
                     SfxItemSet aItemSet = pCaption->GetMergedItemSet();
                     meTVA       = pCaption->GetTextVerticalAdjust();
@@ -1556,16 +1557,14 @@ bool XclExpObjectManager::HasObj() const
     return !mxObjList->empty();
 }
 
-sal_uInt16 XclExpObjectManager::AddObj( XclObj* pObjRec )
+sal_uInt16 XclExpObjectManager::AddObj( std::unique_ptr<XclObj> pObjRec )
 {
-    return mxObjList->Add( pObjRec );
+    return mxObjList->Add( std::move(pObjRec) );
 }
 
-XclObj* XclExpObjectManager::RemoveLastObj()
+std::unique_ptr<XclObj> XclExpObjectManager::RemoveLastObj()
 {
-    XclObj* pLastObj = mxObjList->back();
-    mxObjList->pop_back();
-    return pLastObj;
+    return mxObjList->pop_back();
 }
 
 void XclExpObjectManager::InitStream( bool bTempFile )
diff --git a/sc/source/filter/inc/xcl97rec.hxx b/sc/source/filter/inc/xcl97rec.hxx
index d078128859b5..8efaf9768ca7 100644
--- a/sc/source/filter/inc/xcl97rec.hxx
+++ b/sc/source/filter/inc/xcl97rec.hxx
@@ -37,24 +37,21 @@ class XclExpObjList : public ExcEmptyRec, protected XclExpRoot
 {
 public:
 
-    typedef std::vector<XclObj*>::iterator iterator;
+    typedef std::vector<std::unique_ptr<XclObj>>::iterator iterator;
 
     explicit            XclExpObjList( const XclExpRoot& rRoot, XclEscherEx& rEscherEx );
     virtual             ~XclExpObjList() override;
 
     /// return: 1-based ObjId
     ///! count>=0xFFFF: Obj will be deleted, return 0
-    sal_uInt16              Add( XclObj* );
+    sal_uInt16              Add( std::unique_ptr<XclObj> );
 
-    XclObj* back () { return maObjs.empty() ? nullptr : maObjs.back(); }
+    XclObj* back () { return maObjs.empty() ? nullptr : maObjs.back().get(); }
 
     /**
-     *
      * @brief Remove last element in the list.
-     *
      */
-
-    void pop_back ();
+    std::unique_ptr<XclObj> pop_back ();
 
     bool empty () const { return maObjs.empty(); }
 
@@ -64,7 +61,7 @@ public:
 
     iterator end () { return maObjs.end(); }
 
-    XclExpMsoDrawing* GetMsodrawingPerSheet() { return pMsodrawingPerSheet; }
+    XclExpMsoDrawing* GetMsodrawingPerSheet() { return pMsodrawingPerSheet.get(); }
 
                                 /// close groups and DgContainer opened in ctor
     void                EndSheet();
@@ -79,10 +76,10 @@ private:
     SCTAB               mnScTab;
 
     XclEscherEx&        mrEscherEx;
-    XclExpMsoDrawing*   pMsodrawingPerSheet;
-    XclExpMsoDrawing*   pSolverContainer;
+    std::unique_ptr<XclExpMsoDrawing> pMsodrawingPerSheet;
+    std::unique_ptr<XclExpMsoDrawing> pSolverContainer;
 
-    std::vector<XclObj*> maObjs;
+    std::vector<std::unique_ptr<XclObj>> maObjs;
 };
 
 // --- class XclObj --------------------------------------------------
diff --git a/sc/source/filter/inc/xeescher.hxx b/sc/source/filter/inc/xeescher.hxx
index 46cc7519fbcc..3f5fa308e261 100644
--- a/sc/source/filter/inc/xeescher.hxx
+++ b/sc/source/filter/inc/xeescher.hxx
@@ -407,8 +407,8 @@ public:
     XclEscherEx& GetEscherEx() { return *mxEscherEx; }
     XclExpMsoDrawing*   GetMsodrawingPerSheet();
     bool                HasObj() const;
-    sal_uInt16          AddObj( XclObj* pObjRec );
-    XclObj*             RemoveLastObj();
+    sal_uInt16          AddObj( std::unique_ptr<XclObj> pObjRec );
+    std::unique_ptr<XclObj> RemoveLastObj();
 
 protected:
     explicit            XclExpObjectManager( const XclExpObjectManager& rParent );
diff --git a/sc/source/filter/xcl97/xcl97esc.cxx b/sc/source/filter/xcl97/xcl97esc.cxx
index 198b23ef5c33..b5030ce78304 100644
--- a/sc/source/filter/xcl97/xcl97esc.cxx
+++ b/sc/source/filter/xcl97/xcl97esc.cxx
@@ -27,6 +27,7 @@
 
 #include <svx/svdpage.hxx>
 #include <editeng/outlobj.hxx>
+#include <o3tl/make_unique.hxx>
 #include <svx/svdotext.hxx>
 #include <svx/svdobj.hxx>
 #include <svx/svdoole2.hxx>
@@ -222,7 +223,7 @@ EscherExHostAppData* XclEscherEx::StartShape( const Reference< XShape >& rxShape
                     SvGlobalName aObjClsId( xObj->getClassID() );
                     if ( SotExchange::IsChart( aObjClsId ) )
                     {   // yes, it's a chart diagram
-                        mrObjMgr.AddObj( new XclExpChartObj( mrObjMgr, rxShape, pChildAnchor ) );
+                        mrObjMgr.AddObj( o3tl::make_unique<XclExpChartObj>( mrObjMgr, rxShape, pChildAnchor ) );
                         pCurrXclObj = nullptr;     // no metafile or whatsoever
                     }
                     else    // metafile and OLE object
@@ -265,7 +266,7 @@ EscherExHostAppData* XclEscherEx::StartShape( const Reference< XShape >& rxShape
     }
     if ( pCurrXclObj )
     {
-        if ( !mrObjMgr.AddObj( pCurrXclObj ) )
+        if ( !mrObjMgr.AddObj( std::unique_ptr<XclObj>(pCurrXclObj) ) )
         {   // maximum count reached, object got deleted
             pCurrXclObj = nullptr;
         }
@@ -353,9 +354,8 @@ void XclEscherEx::EndShape( sal_uInt16 nShapeType, sal_uInt32 nShapeID )
         // escher data of last shape not written? -> delete it from object list
         if( nShapeID == 0 )
         {
-            XclObj* pLastObj = mrObjMgr.RemoveLastObj();
-            OSL_ENSURE( pLastObj == pCurrXclObj, "XclEscherEx::EndShape - wrong object" );
-            DELETEZ( pLastObj );
+            std::unique_ptr<XclObj> pLastObj = mrObjMgr.RemoveLastObj();
+            OSL_ENSURE( pLastObj.get() == pCurrXclObj, "XclEscherEx::EndShape - wrong object" );
             pCurrXclObj = nullptr;
         }
 
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index 2eb32f70f558..b8a9919ca5dd 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -98,10 +98,9 @@ sal_Int32 XclExpObjList::mnVmlCount;
 XclExpObjList::XclExpObjList( const XclExpRoot& rRoot, XclEscherEx& rEscherEx ) :
     XclExpRoot( rRoot ),
     mnScTab( rRoot.GetCurrScTab() ),
-    mrEscherEx( rEscherEx ),
-    pSolverContainer( nullptr )
+    mrEscherEx( rEscherEx )
 {
-    pMsodrawingPerSheet = new XclExpMsoDrawing( rEscherEx );
+    pMsodrawingPerSheet.reset( new XclExpMsoDrawing( rEscherEx ) );
     // open the DGCONTAINER and the patriarch group shape
     mrEscherEx.OpenContainer( ESCHER_DgContainer );
     tools::Rectangle aRect( 0, 0, 0, 0 );
@@ -111,12 +110,12 @@ XclExpObjList::XclExpObjList( const XclExpRoot& rRoot, XclEscherEx& rEscherEx )
 
 XclExpObjList::~XclExpObjList()
 {
-    std::for_each(maObjs.begin(), maObjs.end(), std::default_delete<XclObj>());
-    delete pMsodrawingPerSheet;
-    delete pSolverContainer;
+    maObjs.clear();
+    pMsodrawingPerSheet.reset();
+    pSolverContainer.reset();
 }
 
-sal_uInt16 XclExpObjList::Add( XclObj* pObj )
+sal_uInt16 XclExpObjList::Add( std::unique_ptr<XclObj> pObj )
 {
     OSL_ENSURE( maObjs.size() < 0xFFFF, "XclExpObjList::Add: too much for Xcl" );
 
@@ -124,30 +123,31 @@ sal_uInt16 XclExpObjList::Add( XclObj* pObj )
 
     if ( nSize < 0xFFFF )
     {
-        maObjs.push_back(pObj);
-        ++nSize;
-        pObj->SetId( nSize );
+        pObj->SetId( nSize+1 );
         pObj->SetTab( mnScTab );
+        maObjs.push_back(std::move(pObj));
+        ++nSize;
     }
     else
     {
-        delete pObj;
         nSize = 0;
     }
 
     return nSize;
 }
 
-void XclExpObjList::pop_back ()
+std::unique_ptr<XclObj> XclExpObjList::pop_back ()
 {
+    auto ret = std::move(maObjs.back());
     maObjs.pop_back();
+    return ret;
 }
 
 void XclExpObjList::EndSheet()
 {
     // Is there still something in the stream? -> The solver container
     if( mrEscherEx.HasPendingDffData() )
-        pSolverContainer = new XclExpMsoDrawing( mrEscherEx );
+        pSolverContainer.reset( new XclExpMsoDrawing( mrEscherEx ) );
 
     // close the DGCONTAINER created by XclExpObjList ctor MSODRAWING
     mrEscherEx.CloseContainer();
@@ -158,8 +158,7 @@ void XclExpObjList::Save( XclExpStream& rStrm )
     //! Escher must be written, even if there are no objects
     pMsodrawingPerSheet->Save( rStrm );
 
-    std::vector<XclObj*>::iterator pIter;
-    for ( pIter = maObjs.begin(); pIter != maObjs.end(); ++pIter )
+    for ( auto pIter = maObjs.begin(); pIter != maObjs.end(); ++pIter )
         (*pIter)->Save( rStrm );
 
     if( pSolverContainer )
@@ -183,9 +182,8 @@ sal_Int32 GetVmlObjectCount( XclExpObjList& rList )
 {
     sal_Int32 nNumVml = 0;
 
-    std::vector<XclObj*>::iterator pIter;
-    for ( pIter = rList.begin(); pIter != rList.end(); ++pIter )
-        if( IsVmlObject( *pIter ) )
+    for ( auto pIter = rList.begin(); pIter != rList.end(); ++pIter )
+        if( IsVmlObject( pIter->get() ) )
             ++nNumVml;
 
     return nNumVml;
@@ -236,13 +234,12 @@ void SaveDrawingMLObjects( XclExpObjList& rList, XclExpXmlStream& rStrm, sal_Int
 {
     std::vector<XclObj*> aList;
     aList.reserve(rList.size());
-    std::vector<XclObj*>::iterator it = rList.begin(), itEnd = rList.end();
-    for (; it != itEnd; ++it)
+    for (auto it = rList.begin(), itEnd = rList.end(); it != itEnd; ++it)
     {
-        if (IsVmlObject(*it) || !IsValidObject(**it))
+        if (IsVmlObject(it->get()) || !IsValidObject(**it))
             continue;
 
-        aList.push_back(*it);
+        aList.push_back(it->get());
     }
 
     if (aList.empty())
@@ -269,7 +266,7 @@ void SaveDrawingMLObjects( XclExpObjList& rList, XclExpXmlStream& rStrm, sal_Int
             FSNS( XML_xmlns, XML_r ),   XclXmlUtils::ToOString(rStrm.getNamespaceURL(OOX_NS(officeRel))).getStr(),
             FSEND );
 
-    for (it = aList.begin(), itEnd = aList.end(); it != itEnd; ++it)
+    for (auto it = aList.begin(), itEnd = aList.end(); it != itEnd; ++it)
         (*it)->SaveXml(rStrm);
 
     pDrawing->endElement( FSNS( XML_xdr, XML_wsDr ) );
@@ -304,10 +301,9 @@ void SaveVmlObjects( XclExpObjList& rList, XclExpXmlStream& rStrm, sal_Int32& nV
             FSNS( XML_xmlns, XML_w10 ), XclXmlUtils::ToOString(rStrm.getNamespaceURL(OOX_NS(vmlWord))).getStr(),
             FSEND );
 
-    std::vector<XclObj*>::iterator pIter;
-    for ( pIter = rList.begin(); pIter != rList.end(); ++pIter )
+    for ( auto pIter = rList.begin(); pIter != rList.end(); ++pIter )
     {
-        if( !IsVmlObject( *pIter ) )
+        if( !IsVmlObject( pIter->get() ) )
             continue;
         (*pIter)->SaveXml( rStrm );
     }


More information about the Libreoffice-commits mailing list