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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Dec 21 11:22:41 UTC 2018


 filter/source/xsltdialog/typedetectionexport.cxx     |    2 +-
 filter/source/xsltdialog/typedetectionexport.hxx     |    2 +-
 filter/source/xsltdialog/typedetectionimport.cxx     |   18 ++++++++----------
 filter/source/xsltdialog/typedetectionimport.hxx     |    7 ++++---
 filter/source/xsltdialog/xmlfilterjar.cxx            |   15 ++++++++-------
 filter/source/xsltdialog/xmlfilterjar.hxx            |    6 ++----
 filter/source/xsltdialog/xmlfiltersettingsdialog.cxx |   10 +++++-----
 7 files changed, 29 insertions(+), 31 deletions(-)

New commits:
commit 93d1d7b0b600d021ccbb2169b4bb4bacca44dd30
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Dec 20 11:15:28 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Dec 21 12:22:08 2018 +0100

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

diff --git a/filter/source/xsltdialog/typedetectionexport.cxx b/filter/source/xsltdialog/typedetectionexport.cxx
index a9677ddf16fe..bcd379e47be2 100644
--- a/filter/source/xsltdialog/typedetectionexport.cxx
+++ b/filter/source/xsltdialog/typedetectionexport.cxx
@@ -73,7 +73,7 @@ static OUString createRelativeURL( const OUString& rFilterName, const OUString&
     }
 }
 
-void TypeDetectionExporter::doExport( const Reference< XOutputStream >& xOS,  const XMLFilterVector& rFilters )
+void TypeDetectionExporter::doExport( const Reference< XOutputStream >& xOS,  const std::vector<filter_info_impl*>& rFilters )
 {
     try
     {
diff --git a/filter/source/xsltdialog/typedetectionexport.hxx b/filter/source/xsltdialog/typedetectionexport.hxx
index 2f2ed5732810..b38b3306dca6 100644
--- a/filter/source/xsltdialog/typedetectionexport.hxx
+++ b/filter/source/xsltdialog/typedetectionexport.hxx
@@ -30,7 +30,7 @@ class TypeDetectionExporter
 public:
     explicit TypeDetectionExporter( css::uno::Reference< css::uno::XComponentContext > const & mxContext );
 
-    void doExport(const css::uno::Reference < css::io::XOutputStream >& xOS,  const XMLFilterVector& rFilters );
+    void doExport(const css::uno::Reference < css::io::XOutputStream >& xOS,  const std::vector<filter_info_impl*>& rFilters );
 
 private:
     static void addProperty( const css::uno::Reference< css::xml::sax::XWriter >& xWriter, const OUString& rName, const OUString& rValue );
diff --git a/filter/source/xsltdialog/typedetectionimport.cxx b/filter/source/xsltdialog/typedetectionimport.cxx
index c52917eda7c9..e1c3d8147b9d 100644
--- a/filter/source/xsltdialog/typedetectionimport.cxx
+++ b/filter/source/xsltdialog/typedetectionimport.cxx
@@ -42,7 +42,8 @@ TypeDetectionImporter::~TypeDetectionImporter()
 {
 }
 
-void TypeDetectionImporter::doImport( const Reference< XComponentContext >& rxContext, const Reference< XInputStream >& xIS, XMLFilterVector& rFilters )
+void TypeDetectionImporter::doImport( const Reference< XComponentContext >& rxContext, const Reference< XInputStream >& xIS,
+                                      std::vector< std::unique_ptr<filter_info_impl> >& rFilters )
 {
     try
     {
@@ -66,14 +67,14 @@ void TypeDetectionImporter::doImport( const Reference< XComponentContext >& rxCo
     }
 }
 
-void TypeDetectionImporter::fillFilterVector(  XMLFilterVector& rFilters )
+void TypeDetectionImporter::fillFilterVector(  std::vector< std::unique_ptr<filter_info_impl> >& rFilters )
 {
     // create filter infos from imported filter nodes
     for (auto const& filterNode : maFilterNodes)
     {
-        filter_info_impl* pFilter = createFilterForNode(filterNode.get());
+        std::unique_ptr<filter_info_impl> pFilter = createFilterForNode(filterNode.get());
         if( pFilter )
-            rFilters.push_back( pFilter );
+            rFilters.push_back( std::move(pFilter) );
     }
     maFilterNodes.clear();
 
@@ -123,9 +124,9 @@ Node* TypeDetectionImporter::findTypeNode( const OUString& rType )
     return nullptr;
 }
 
-filter_info_impl* TypeDetectionImporter::createFilterForNode( Node * pNode )
+std::unique_ptr<filter_info_impl> TypeDetectionImporter::createFilterForNode( Node * pNode )
 {
-    filter_info_impl* pFilter = new filter_info_impl;
+    std::unique_ptr<filter_info_impl> pFilter(new filter_info_impl);
 
     pFilter->maFilterName = pNode->maName;
     pFilter->maInterfaceName = pNode->maPropertyMap["UIName"];
@@ -193,10 +194,7 @@ filter_info_impl* TypeDetectionImporter::createFilterForNode( Node * pNode )
         bOk = false;
 
     if( !bOk )
-    {
-        delete pFilter;
-        pFilter = nullptr;
-    }
+        return nullptr;
 
     return pFilter;
 }
diff --git a/filter/source/xsltdialog/typedetectionimport.hxx b/filter/source/xsltdialog/typedetectionimport.hxx
index 440e650db9ae..507419ff0ae1 100644
--- a/filter/source/xsltdialog/typedetectionimport.hxx
+++ b/filter/source/xsltdialog/typedetectionimport.hxx
@@ -63,7 +63,8 @@ public:
     TypeDetectionImporter();
     virtual ~TypeDetectionImporter() override;
 
-    static void doImport( const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Reference < css::io::XInputStream >& xOS, XMLFilterVector& rFilters );
+    static void doImport( const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Reference < css::io::XInputStream >& xOS,
+                          std::vector< std::unique_ptr<filter_info_impl> >& rFilters );
 
     virtual void SAL_CALL startDocument(  ) override;
     virtual void SAL_CALL endDocument(  ) override;
@@ -75,8 +76,8 @@ public:
     virtual void SAL_CALL setDocumentLocator( const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override;
 
 private:
-    void fillFilterVector(  XMLFilterVector& rFilters );
-    filter_info_impl* createFilterForNode( Node * pNode );
+    void fillFilterVector(  std::vector< std::unique_ptr<filter_info_impl> >& rFilters );
+    std::unique_ptr<filter_info_impl> createFilterForNode( Node * pNode );
     Node* findTypeNode( const OUString& rType );
 
     std::stack< ImportState > maStack;
diff --git a/filter/source/xsltdialog/xmlfilterjar.cxx b/filter/source/xsltdialog/xmlfilterjar.cxx
index c04170ee0126..5ab09745f583 100644
--- a/filter/source/xsltdialog/xmlfilterjar.cxx
+++ b/filter/source/xsltdialog/xmlfilterjar.cxx
@@ -137,7 +137,7 @@ void XMLFilterJarHelper::addFile( Reference< XInterface > const & xRootFolder, R
     }
 }
 
-bool XMLFilterJarHelper::savePackage( const OUString& rPackageURL, const XMLFilterVector& rFilters )
+bool XMLFilterJarHelper::savePackage( const OUString& rPackageURL, const std::vector<filter_info_impl*>& rFilters )
 {
     try
     {
@@ -228,7 +228,8 @@ bool XMLFilterJarHelper::savePackage( const OUString& rPackageURL, const XMLFilt
 }
 
 
-void XMLFilterJarHelper::openPackage( const OUString& rPackageURL, XMLFilterVector& rFilters )
+void XMLFilterJarHelper::openPackage( const OUString& rPackageURL,
+                                      std::vector< std::unique_ptr<filter_info_impl> >& rFilters )
 {
     try
     {
@@ -264,21 +265,21 @@ void XMLFilterJarHelper::openPackage( const OUString& rPackageURL, XMLFilterVect
                 {
                     Reference< XInputStream > xIS( xTypeDetection->getInputStream() );
 
-                    XMLFilterVector aFilters;
+                    std::vector< std::unique_ptr<filter_info_impl> > aFilters;
                     TypeDetectionImporter::doImport( mxContext, xIS, aFilters );
 
                     // copy all files used by the filters imported from the
                     // typedetection to office/user/xslt
-                    for (auto const& filter : aFilters)
+                    for (auto& filter : aFilters)
                     {
-                        if( copyFiles( xIfc, filter ) )
+                        if( copyFiles( xIfc, filter.get() ) )
                         {
-                            rFilters.push_back(filter);
+                            rFilters.push_back(std::move(filter));
                         }
                         else
                         {
                             // failed to copy all files
-                            delete filter;
+                            filter.reset();
                         }
                     }
                 }
diff --git a/filter/source/xsltdialog/xmlfilterjar.hxx b/filter/source/xsltdialog/xmlfilterjar.hxx
index a71f89f9bb41..d9e20cd05847 100644
--- a/filter/source/xsltdialog/xmlfilterjar.hxx
+++ b/filter/source/xsltdialog/xmlfilterjar.hxx
@@ -27,15 +27,13 @@
 
 class filter_info_impl;
 
-typedef std::vector< filter_info_impl* > XMLFilterVector;
-
 class XMLFilterJarHelper
 {
 public:
     explicit XMLFilterJarHelper( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
 
-    bool savePackage( const OUString& rPackageURL, const XMLFilterVector& rFilters );
-    void openPackage( const OUString& rPackageURL, XMLFilterVector& rFilters );
+    bool savePackage( const OUString& rPackageURL, const std::vector<filter_info_impl*>& rFilters );
+    void openPackage( const OUString& rPackageURL, std::vector< std::unique_ptr<filter_info_impl> >& rFilters );
 
 private:
     /// @throws css::uno::Exception
diff --git a/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx b/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx
index 44a2dd30917f..036cfcb95d89 100644
--- a/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx
+++ b/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx
@@ -883,7 +883,7 @@ void XMLFilterSettingsDialog::onDelete()
 
 void XMLFilterSettingsDialog::onSave()
 {
-    XMLFilterVector aFilters;
+    std::vector<filter_info_impl*> aFilters;
 
     int nFilters = 0;
 
@@ -939,7 +939,7 @@ void XMLFilterSettingsDialog::onSave()
 
 void XMLFilterSettingsDialog::onOpen()
 {
-    XMLFilterVector aFilters;
+    std::vector< std::unique_ptr<filter_info_impl> > aFilters;
 
     // Open Fileopen-Dialog
        ::sfx2::FileDialogHelper aDlg(
@@ -960,15 +960,15 @@ void XMLFilterSettingsDialog::onOpen()
         aJarHelper.openPackage( aURL, aFilters );
 
         int nFilters = 0;
-        for (auto const& filter : aFilters)
+        for (auto& filter : aFilters)
         {
-            if( insertOrEdit(filter) )
+            if( insertOrEdit(filter.get()) )
             {
                 aFilterName = filter->maFilterName;
                 nFilters++;
             }
 
-            delete filter;
+            filter.reset();
         }
 
         disposeFilterList();


More information about the Libreoffice-commits mailing list