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

Noel Grandin noel.grandin at collabora.co.uk
Tue Oct 17 12:05:37 UTC 2017


 xmlscript/source/xmldlg_imexp/exp_share.hxx     |    3 ++-
 xmlscript/source/xmldlg_imexp/xmldlg_export.cxx |   14 +++++---------
 2 files changed, 7 insertions(+), 10 deletions(-)

New commits:
commit d6831a8a34257789a920491747e12ebe62f927fe
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Oct 17 12:39:08 2017 +0200

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

diff --git a/xmlscript/source/xmldlg_imexp/exp_share.hxx b/xmlscript/source/xmldlg_imexp/exp_share.hxx
index 661f356c5869..825db80f598c 100644
--- a/xmlscript/source/xmldlg_imexp/exp_share.hxx
+++ b/xmlscript/source/xmldlg_imexp/exp_share.hxx
@@ -31,6 +31,7 @@
 #include <com/sun/star/awt/FontDescriptor.hpp>
 #include <com/sun/star/awt/FontEmphasisMark.hpp>
 #include <com/sun/star/awt/FontRelief.hpp>
+#include <memory>
 #include <vector>
 
 
@@ -75,7 +76,7 @@ struct Style
 };
 class StyleBag
 {
-    ::std::vector< Style * > _styles;
+    ::std::vector< std::unique_ptr<Style> > _styles;
 
 public:
     ~StyleBag() ;
diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx
index 6238f6945e76..9dab7b525b9b 100644
--- a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx
+++ b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx
@@ -1262,7 +1262,7 @@ OUString StyleBag::getStyleId( Style const & rStyle )
     }
 
     // lookup existing style
-    for (Style* pStyle : _styles)
+    for (auto const & pStyle : _styles)
     {
         short demanded_defaults = ~rStyle._set & rStyle._all;
         // test, if defaults are not set
@@ -1324,18 +1324,14 @@ OUString StyleBag::getStyleId( Style const & rStyle )
     }
 
     // no appr style found, append new
-    Style * pStyle = new Style( rStyle );
+    std::unique_ptr<Style> pStyle(new Style( rStyle ));
     pStyle->_id = OUString::number( _styles.size() );
-    _styles.push_back( pStyle );
-    return pStyle->_id;
+    _styles.push_back( std::move(pStyle) );
+    return _styles.back()->_id;
 }
 
 StyleBag::~StyleBag()
 {
-    for (Style* _style : _styles)
-    {
-        delete _style;
-    }
 }
 
 void StyleBag::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOut )
@@ -1346,7 +1342,7 @@ void StyleBag::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOu
         xOut->ignorableWhitespace( OUString() );
         xOut->startElement( aStylesName, Reference< xml::sax::XAttributeList >() );
         // export styles
-        for (Style* _style : _styles)
+        for (auto const & _style : _styles)
         {
             Reference< xml::sax::XAttributeList > xAttr( _style->createElement() );
             static_cast< ElementDescriptor * >( xAttr.get() )->dump( xOut.get() );


More information about the Libreoffice-commits mailing list