[Libreoffice-commits] core.git: 2 commits - sot/source sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Dec 5 06:50:23 UTC 2018


 sot/source/unoolestorage/xolesimplestorage.cxx |   48 +++++++-----------
 sot/source/unoolestorage/xolesimplestorage.hxx |    2 
 sw/source/filter/ww8/docxexport.cxx            |    5 -
 sw/source/filter/ww8/rtfexport.cxx             |    2 
 sw/source/filter/ww8/wrtww8.cxx                |   64 ++++++++++---------------
 sw/source/filter/ww8/wrtww8.hxx                |   26 +++++-----
 sw/source/filter/ww8/ww8atr.cxx                |   16 +++---
 7 files changed, 70 insertions(+), 93 deletions(-)

New commits:
commit b06abdb3ddfa1337b7433f02689fa9f0f9c7cf09
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Dec 4 14:49:22 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Dec 5 07:50:05 2018 +0100

    use unique_ptr in OLESimpleStorage
    
    Change-Id: I5ef95846640efac00055336435356efdd0a8326d
    Reviewed-on: https://gerrit.libreoffice.org/64524
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sot/source/unoolestorage/xolesimplestorage.cxx b/sot/source/unoolestorage/xolesimplestorage.cxx
index 8804c4318fad..c61b643811f0 100644
--- a/sot/source/unoolestorage/xolesimplestorage.cxx
+++ b/sot/source/unoolestorage/xolesimplestorage.cxx
@@ -45,7 +45,6 @@ OLESimpleStorage::OLESimpleStorage(
         css::uno::Reference<css::uno::XComponentContext> const & xContext,
         css::uno::Sequence<css::uno::Any> const &aArguments)
 : m_bDisposed( false )
-, m_pStorage( nullptr )
 , m_pListenersContainer( nullptr )
 , m_xContext( xContext )
 , m_bNoTemporaryCopy( false )
@@ -135,7 +134,7 @@ OLESimpleStorage::OLESimpleStorage(
     if ( !m_pStream || m_pStream->GetError() )
         throw io::IOException(); // TODO
 
-    m_pStorage = new Storage( *m_pStream, false );
+    m_pStorage.reset(new Storage( *m_pStream, false ));
 }
 
 OLESimpleStorage::~OLESimpleStorage()
@@ -187,11 +186,10 @@ void OLESimpleStorage::InsertInputStreamToStorage_Impl( BaseStorage* pStorage, c
     if ( pStorage->IsContained( aName ) )
         throw container::ElementExistException(); // TODO:
 
-    BaseStorageStream* pNewStream = pStorage->OpenStream( aName );
+    std::unique_ptr<BaseStorageStream> pNewStream(pStorage->OpenStream( aName ));
     if ( !pNewStream || pNewStream->GetError() || pStorage->GetError() )
     {
-        if ( pNewStream )
-            DELETEZ( pNewStream );
+        pNewStream.reset();
         pStorage->ResetError();
         throw io::IOException(); // TODO
     }
@@ -211,13 +209,11 @@ void OLESimpleStorage::InsertInputStreamToStorage_Impl( BaseStorage* pStorage, c
     }
     catch( uno::Exception& )
     {
-        DELETEZ( pNewStream );
+        pNewStream.reset();
         pStorage->Remove( aName );
 
         throw;
     }
-
-    DELETEZ( pNewStream );
 }
 
 
@@ -229,11 +225,10 @@ void OLESimpleStorage::InsertNameAccessToStorage_Impl( BaseStorage* pStorage, co
     if ( pStorage->IsContained( aName ) )
         throw container::ElementExistException(); // TODO:
 
-    BaseStorage* pNewStorage = pStorage->OpenStorage( aName );
+    std::unique_ptr<BaseStorage> pNewStorage(pStorage->OpenStorage( aName ));
     if ( !pNewStorage || pNewStorage->GetError() || pStorage->GetError() )
     {
-        if ( pNewStorage )
-            DELETEZ( pNewStorage );
+        pNewStorage.reset();
         pStorage->ResetError();
         throw io::IOException(); // TODO
     }
@@ -247,20 +242,18 @@ void OLESimpleStorage::InsertNameAccessToStorage_Impl( BaseStorage* pStorage, co
             uno::Reference< container::XNameAccess > xSubNameAccess;
             uno::Any aAny = xNameAccess->getByName( aElements[nInd] );
             if ( aAny >>= xInputStream )
-                InsertInputStreamToStorage_Impl( pNewStorage, aElements[nInd], xInputStream );
+                InsertInputStreamToStorage_Impl( pNewStorage.get(), aElements[nInd], xInputStream );
             else if ( aAny >>= xSubNameAccess )
-                InsertNameAccessToStorage_Impl( pNewStorage, aElements[nInd], xSubNameAccess );
+                InsertNameAccessToStorage_Impl( pNewStorage.get(), aElements[nInd], xSubNameAccess );
         }
     }
     catch( uno::Exception& )
     {
-        DELETEZ( pNewStorage );
+        pNewStorage.reset();
         pStorage->Remove( aName );
 
         throw;
     }
-
-    DELETEZ( pNewStorage );
 }
 
 
@@ -292,9 +285,9 @@ void SAL_CALL OLESimpleStorage::insertByName( const OUString& aName, const uno::
             throw lang::IllegalArgumentException(); // TODO:
 
         if ( xInputStream.is() )
-            InsertInputStreamToStorage_Impl( m_pStorage, aName, xInputStream );
+            InsertInputStreamToStorage_Impl( m_pStorage.get(), aName, xInputStream );
         else if ( xNameAccess.is() )
-            InsertNameAccessToStorage_Impl( m_pStorage, aName, xNameAccess );
+            InsertNameAccessToStorage_Impl( m_pStorage.get(), aName, xNameAccess );
         else
             throw uno::RuntimeException();
     }
@@ -391,7 +384,7 @@ uno::Any SAL_CALL OLESimpleStorage::getByName( const OUString& aName )
 
     if ( m_pStorage->IsStorage( aName ) )
     {
-        BaseStorage* pStrg = m_pStorage->OpenStorage( aName );
+        std::unique_ptr<BaseStorage> pStrg(m_pStorage->OpenStorage( aName ));
         m_pStorage->ResetError();
         if ( !pStrg )
             throw lang::WrappedTargetException(); // io::IOException(); // TODO
@@ -400,12 +393,12 @@ uno::Any SAL_CALL OLESimpleStorage::getByName( const OUString& aName )
         if ( !pStream )
             throw uno::RuntimeException();
 
-        BaseStorage* pNewStor = new Storage( *pStream, false );
-        bool bSuccess = ( pStrg->CopyTo( pNewStor ) && pNewStor->Commit() &&
+        std::unique_ptr<BaseStorage> pNewStor(new Storage( *pStream, false ));
+        bool bSuccess = ( pStrg->CopyTo( pNewStor.get() ) && pNewStor->Commit() &&
                           !pNewStor->GetError() && !pStrg->GetError() );
 
-        DELETEZ( pNewStor );
-        DELETEZ( pStrg );
+        pNewStor.reset();
+        pStrg.reset();
         pStream.reset();
 
         if ( !bSuccess )
@@ -419,13 +412,12 @@ uno::Any SAL_CALL OLESimpleStorage::getByName( const OUString& aName )
     }
     else
     {
-        BaseStorageStream* pStream = m_pStorage->OpenStream( aName, StreamMode::READ | StreamMode::SHARE_DENYALL | StreamMode::NOCREATE );
+        std::unique_ptr<BaseStorageStream> pStream(m_pStorage->OpenStream( aName, StreamMode::READ | StreamMode::SHARE_DENYALL | StreamMode::NOCREATE ));
         try
         {
             if ( !pStream || pStream->GetError() || m_pStorage->GetError() )
             {
                 m_pStorage->ResetError();
-                DELETEZ( pStream );
                 throw io::IOException(); // TODO
             }
 
@@ -451,18 +443,16 @@ uno::Any SAL_CALL OLESimpleStorage::getByName( const OUString& aName )
         }
         catch (const uno::RuntimeException&)
         {
-            DELETEZ( pStream );
             throw;
         }
         catch (const uno::Exception& ex)
         {
             css::uno::Any anyEx = cppu::getCaughtException();
-            DELETEZ( pStream );
             throw css::lang::WrappedTargetException( ex.Message,
                     nullptr, anyEx );
         }
 
-        DELETEZ( pStream );
+        pStream.reset();
 
         aResult <<= xInputStream;
     }
@@ -570,7 +560,7 @@ void SAL_CALL OLESimpleStorage::dispose()
         m_pListenersContainer->disposeAndClear( aSource );
     }
 
-    DELETEZ( m_pStorage );
+    m_pStorage.reset();
     m_pStream.reset();
 
     m_xStream.clear();
diff --git a/sot/source/unoolestorage/xolesimplestorage.hxx b/sot/source/unoolestorage/xolesimplestorage.hxx
index 3cd4d86c011e..0dc2c6160a58 100644
--- a/sot/source/unoolestorage/xolesimplestorage.hxx
+++ b/sot/source/unoolestorage/xolesimplestorage.hxx
@@ -47,7 +47,7 @@ class OLESimpleStorage : public cppu::WeakImplHelper<css::embed::XOLESimpleStora
     css::uno::Reference< css::io::XStream > m_xStream;
     css::uno::Reference< css::io::XStream > m_xTempStream;
     std::unique_ptr<SvStream> m_pStream;
-    BaseStorage* m_pStorage;
+    std::unique_ptr<BaseStorage> m_pStorage;
 
     ::comphelper::OInterfaceContainerHelper2* m_pListenersContainer; // list of listeners
     css::uno::Reference<css::uno::XComponentContext> m_xContext;
commit c77a81224da71aaee6ca4351c49274293241f88c
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Dec 4 14:46:06 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Dec 5 07:49:56 2018 +0100

    use unique_ptr in ww8 export code
    
    Change-Id: I505c8005aebec40b8e812aea10deaf79eb7223ab
    Reviewed-on: https://gerrit.libreoffice.org/64523
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 91e485eaa980..e311e7855ae3 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -534,8 +534,7 @@ ErrCode DocxExport::ExportDocument_Impl()
     WriteVBA();
 
     m_aLinkedTextboxesHelper.clear();   //final cleanup
-    delete m_pStyles;
-    m_pStyles = nullptr;
+    m_pStyles.reset();
     m_pSections.reset();
 
     return ERRCODE_NONE;
@@ -639,7 +638,7 @@ void DocxExport::PrepareNewPageDesc( const SfxItemSet* pSet,
 
 void DocxExport::InitStyles()
 {
-    m_pStyles = new MSWordStyles( *this, /*bListStyles =*/ true );
+    m_pStyles.reset(new MSWordStyles( *this, /*bListStyles =*/ true ));
 
     // setup word/styles.xml and the relations + content type
     m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index 89a80960da6f..fdfd30e89de3 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -692,7 +692,7 @@ ErrCode RtfExport::ExportDocument_Impl()
     // Font table
     WriteFonts();
 
-    m_pStyles = new MSWordStyles(*this);
+    m_pStyles.reset(new MSWordStyles(*this));
     // Color and stylesheet table
     WriteStyles();
 
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index a6dcefce8a89..371912fba436 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -3333,21 +3333,21 @@ ErrCode WW8Export::ExportDocument_Impl()
     m_pBkmks = new WW8_WrtBookmarks;                          // Bookmarks
     GetWriter().CreateBookmarkTable();
 
-    m_pPapPlc = new WW8_WrPlcPn( *this, PAP, pFib->m_fcMin );
-    m_pChpPlc = new WW8_WrPlcPn( *this, CHP, pFib->m_fcMin );
+    m_pPapPlc.reset(new WW8_WrPlcPn( *this, PAP, pFib->m_fcMin ));
+    m_pChpPlc.reset(new WW8_WrPlcPn( *this, CHP, pFib->m_fcMin ));
     pO = new ww::bytes;
-    m_pStyles = new MSWordStyles( *this );
-    m_pFieldMain = new WW8_WrPlcField( 2, TXT_MAINTEXT );
-    m_pFieldHdFt = new WW8_WrPlcField( 2, TXT_HDFT );
-    m_pFieldFootnote = new WW8_WrPlcField( 2, TXT_FTN );
-    m_pFieldEdn = new WW8_WrPlcField( 2, TXT_EDN );
-    m_pFieldAtn = new WW8_WrPlcField( 2, TXT_ATN );
-    m_pFieldTextBxs = new WW8_WrPlcField( 2, TXT_TXTBOX );
-    m_pFieldHFTextBxs = new WW8_WrPlcField( 2, TXT_HFTXTBOX );
-
-    m_pMagicTable = new WW8_WrMagicTable;
-
-    m_pGrf = new SwWW8WrGrf( *this );
+    m_pStyles.reset(new MSWordStyles( *this ));
+    m_pFieldMain.reset(new WW8_WrPlcField( 2, TXT_MAINTEXT ));
+    m_pFieldHdFt.reset(new WW8_WrPlcField( 2, TXT_HDFT ));
+    m_pFieldFootnote.reset(new WW8_WrPlcField( 2, TXT_FTN ));
+    m_pFieldEdn.reset(new WW8_WrPlcField( 2, TXT_EDN ));
+    m_pFieldAtn.reset(new WW8_WrPlcField( 2, TXT_ATN ));
+    m_pFieldTextBxs.reset(new WW8_WrPlcField( 2, TXT_TXTBOX ));
+    m_pFieldHFTextBxs.reset(new WW8_WrPlcField( 2, TXT_HFTXTBOX ));
+
+    m_pMagicTable.reset(new WW8_WrMagicTable);
+
+    m_pGrf.reset(new SwWW8WrGrf( *this ));
     m_pPiece = new WW8_WrPct( pFib->m_fcMin );
     pDop.reset(new WW8Dop);
 
@@ -3419,19 +3419,19 @@ ErrCode WW8Export::ExportDocument_Impl()
     done:;
     }
 
-    DELETEZ( m_pGrf );
-    DELETEZ( m_pMagicTable );
-    DELETEZ( m_pFieldFootnote );
-    DELETEZ( m_pFieldTextBxs );
-    DELETEZ( m_pFieldHFTextBxs );
-    DELETEZ( m_pFieldAtn );
-    DELETEZ( m_pFieldEdn );
-    DELETEZ( m_pFieldHdFt );
-    DELETEZ( m_pFieldMain );
-    DELETEZ( m_pStyles );
+    m_pGrf.reset();
+    m_pMagicTable.reset();;
+    m_pFieldFootnote.reset();;
+    m_pFieldTextBxs.reset();;
+    m_pFieldHFTextBxs.reset();;
+    m_pFieldAtn.reset();;
+    m_pFieldEdn.reset();;
+    m_pFieldHdFt.reset();;
+    m_pFieldMain.reset();;
+    m_pStyles.reset();;
     DELETEZ( pO );
-    DELETEZ( m_pChpPlc );
-    DELETEZ( m_pPapPlc );
+    m_pChpPlc.reset();;
+    m_pPapPlc.reset();;
     pSepx.reset();
 
     delete m_pRedlAuthors;
@@ -3583,25 +3583,13 @@ MSWordExportBase::MSWordExportBase( SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM
     , m_pCurrentPageDesc(nullptr)
     , m_bPrevTextNodeIsEmpty(false)
     , m_bFirstTOCNodeWithSection(false)
-    , m_pPapPlc(nullptr)
-    , m_pChpPlc(nullptr)
     , m_pChpIter(nullptr)
-    , m_pStyles(nullptr)
     , m_pAtn(nullptr)
     , m_pTextBxs(nullptr)
     , m_pHFTextBxs(nullptr)
     , m_pParentFrame(nullptr)
     , m_pFlyOffset(nullptr)
     , m_eNewAnchorType(RndStdIds::FLY_AS_CHAR)
-    , m_pFieldMain(nullptr)
-    , m_pFieldHdFt(nullptr)
-    , m_pFieldFootnote(nullptr)
-    , m_pFieldEdn(nullptr)
-    , m_pFieldAtn(nullptr)
-    , m_pFieldTextBxs(nullptr)
-    , m_pFieldHFTextBxs(nullptr)
-    , m_pMagicTable(nullptr)
-    , m_pGrf(nullptr)
     , m_pStyAttr(nullptr)
     , m_pOutFormatNode(nullptr)
     , m_pCurrentStyle(nullptr)
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 0766d4df2c39..90e1a815a140 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -486,10 +486,10 @@ public:
     const SwPageDesc *m_pCurrentPageDesc;
     bool m_bPrevTextNodeIsEmpty;
     bool m_bFirstTOCNodeWithSection;
-    WW8_WrPlcPn* m_pPapPlc;
-    WW8_WrPlcPn* m_pChpPlc;
+    std::unique_ptr<WW8_WrPlcPn> m_pPapPlc;
+    std::unique_ptr<WW8_WrPlcPn> m_pChpPlc;
     MSWordAttrIter* m_pChpIter;
-    MSWordStyles* m_pStyles;
+    std::unique_ptr<MSWordStyles> m_pStyles;
     WW8_WrPlcAnnotations* m_pAtn;
     std::unique_ptr<WW8_WrtFactoids> m_pFactoids;
     WW8_WrPlcTextBoxes *m_pTextBxs, *m_pHFTextBxs;
@@ -512,18 +512,18 @@ public:
     Point* m_pFlyOffset;              // for adjusting of character-bound Fly in the Writer,
     RndStdIds m_eNewAnchorType;       // that is paragraph-bound in the WW.
 
-    WW8_WrPlcField* m_pFieldMain;         // fields in MainText
-    WW8_WrPlcField* m_pFieldHdFt;         // fields in Header/Footer
-    WW8_WrPlcField* m_pFieldFootnote;          // fields in FootNotes
-    WW8_WrPlcField* m_pFieldEdn;          // fields in EndNotes
-    WW8_WrPlcField* m_pFieldAtn;          // fields in Annotations
-    WW8_WrPlcField* m_pFieldTextBxs;       // fields in textboxes
-    WW8_WrPlcField* m_pFieldHFTextBxs;     // fields in header/footer textboxes
-    WW8_WrMagicTable *m_pMagicTable;  // keeps track of table cell positions, and
+    std::unique_ptr<WW8_WrPlcField> m_pFieldMain;         // fields in MainText
+    std::unique_ptr<WW8_WrPlcField> m_pFieldHdFt;         // fields in Header/Footer
+    std::unique_ptr<WW8_WrPlcField> m_pFieldFootnote;          // fields in FootNotes
+    std::unique_ptr<WW8_WrPlcField> m_pFieldEdn;          // fields in EndNotes
+    std::unique_ptr<WW8_WrPlcField> m_pFieldAtn;          // fields in Annotations
+    std::unique_ptr<WW8_WrPlcField> m_pFieldTextBxs;       // fields in textboxes
+    std::unique_ptr<WW8_WrPlcField> m_pFieldHFTextBxs;     // fields in header/footer textboxes
+    std::unique_ptr<WW8_WrMagicTable> m_pMagicTable;  // keeps track of table cell positions, and
                                     // marks those that contain graphics,
                                     // which is required to make word display
                                     // graphics inside tables
-    SwWW8WrGrf* m_pGrf;
+    std::unique_ptr<SwWW8WrGrf> m_pGrf;
     const SwAttrSet* m_pStyAttr;      // StyleAttr for Tabs
     const SwModify* m_pOutFormatNode;    // write Format or Node
     const SwFormat *m_pCurrentStyle;     // iff bStyDef=true, then this store the current style
@@ -960,7 +960,7 @@ private:
 class WW8Export : public MSWordExportBase
 {
 public:
-    ww::bytes* pO;                      ///< Buffer
+    ww::bytes *pO;                      ///< Buffer
 
     SvStream *pTableStrm, *pDataStrm;   ///< Streams for WW97 Export
 
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index f48554658ec8..76de5be7b2ec 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -1711,25 +1711,25 @@ WW8_WrPlcField* WW8Export::CurrentFieldPlc() const
     switch (m_nTextTyp)
     {
         case TXT_MAINTEXT:
-            pFieldP = m_pFieldMain;
+            pFieldP = m_pFieldMain.get();
             break;
         case TXT_HDFT:
-            pFieldP = m_pFieldHdFt;
+            pFieldP = m_pFieldHdFt.get();
             break;
         case TXT_FTN:
-            pFieldP = m_pFieldFootnote;
+            pFieldP = m_pFieldFootnote.get();
             break;
         case TXT_EDN:
-            pFieldP = m_pFieldEdn;
+            pFieldP = m_pFieldEdn.get();
             break;
         case TXT_ATN:
-            pFieldP = m_pFieldAtn;
+            pFieldP = m_pFieldAtn.get();
             break;
         case TXT_TXTBOX:
-            pFieldP = m_pFieldTextBxs;
+            pFieldP = m_pFieldTextBxs.get();
             break;
         case TXT_HFTXTBOX:
-            pFieldP = m_pFieldHFTextBxs;
+            pFieldP = m_pFieldHFTextBxs.get();
             break;
         default:
             OSL_ENSURE( false, "what type of SubDoc is that?" );
@@ -3884,7 +3884,7 @@ void WW8AttributeOutput::SectionBreak( sal_uInt8 nC, const WW8_SepInfo* /*pSecti
 
 sal_uInt32 AttributeOutputBase::GridCharacterPitch( const SwTextGridItem& rGrid ) const
 {
-    MSWordStyles * pStyles = GetExport().m_pStyles;
+    MSWordStyles * pStyles = GetExport().m_pStyles.get();
     const SwFormat * pSwFormat = pStyles->GetSwFormat(0);
 
     sal_uInt32 nPageCharSize = 0;


More information about the Libreoffice-commits mailing list