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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Sep 20 13:16:24 UTC 2018


 include/xmloff/XMLEventExport.hxx       |    8 ++++++--
 xmloff/source/core/xmlexp.cxx           |    5 +++--
 xmloff/source/script/XMLEventExport.cxx |   13 +++----------
 3 files changed, 12 insertions(+), 14 deletions(-)

New commits:
commit 35e1658e7275777ee94902b5014fd93b8daf975c
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Sep 17 09:39:45 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Sep 20 15:15:58 2018 +0200

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

diff --git a/include/xmloff/XMLEventExport.hxx b/include/xmloff/XMLEventExport.hxx
index 797fc4a6dde3..8dba84465ace 100644
--- a/include/xmloff/XMLEventExport.hxx
+++ b/include/xmloff/XMLEventExport.hxx
@@ -29,6 +29,7 @@
 #include <xmloff/xmlevent.hxx>
 
 #include <map>
+#include <memory>
 
 class SvXMLExport;
 namespace com { namespace sun { namespace star {
@@ -38,7 +39,7 @@ namespace com { namespace sun { namespace star {
     namespace beans { struct PropertyValue; }
 } } }
 
-typedef ::std::map< OUString, XMLEventExportHandler* > HandlerMap;
+typedef ::std::map< OUString, std::unique_ptr<XMLEventExportHandler> > HandlerMap;
 typedef ::std::map< OUString, XMLEventName > NameMap;
 
 /**
@@ -69,13 +70,16 @@ public:
     XMLEventExport(SvXMLExport& rExport);
     ~XMLEventExport();
 
+    XMLEventExport& operator=( XMLEventExport const & ) = delete; // MSVC2017 workaround
+    XMLEventExport( XMLEventExport const & ) = delete; // MSVC2017 workaround
+
     /// register an EventExportHandler for a particular script type
     ///
     /// The handlers will be deleted when the object is destroyed, hence
     /// no pointers to a handler registered with AddHandler() should be
     /// held by anyone.
     void AddHandler( const OUString& rName,
-                     XMLEventExportHandler* rHandler );
+                     std::unique_ptr<XMLEventExportHandler> pHandler );
 
     /// register additional event names
     void AddTranslationTable( const XMLEventNameTranslation* pTransTable );
diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx
index fc30db7b8bb2..c3b82f214246 100644
--- a/xmloff/source/core/xmlexp.cxx
+++ b/xmloff/source/core/xmlexp.cxx
@@ -95,6 +95,7 @@
 
 #include <comphelper/xmltools.hxx>
 #include <comphelper/graphicmimetype.hxx>
+#include <o3tl/make_unique.hxx>
 
 using namespace ::osl;
 using namespace ::com::sun::star;
@@ -2010,8 +2011,8 @@ XMLEventExport& SvXMLExport::GetEventExport()
         mpEventExport.reset( new XMLEventExport(*this) );
 
         // and register standard handlers + names
-        mpEventExport->AddHandler("StarBasic", new XMLStarBasicExportHandler());
-        mpEventExport->AddHandler("Script", new XMLScriptExportHandler());
+        mpEventExport->AddHandler("StarBasic", o3tl::make_unique<XMLStarBasicExportHandler>());
+        mpEventExport->AddHandler("Script", o3tl::make_unique<XMLScriptExportHandler>());
         mpEventExport->AddTranslationTable(aStandardEventTable);
     }
 
diff --git a/xmloff/source/script/XMLEventExport.cxx b/xmloff/source/script/XMLEventExport.cxx
index 64e47a45919c..72d550527bd1 100644
--- a/xmloff/source/script/XMLEventExport.cxx
+++ b/xmloff/source/script/XMLEventExport.cxx
@@ -52,21 +52,14 @@ XMLEventExport::XMLEventExport(SvXMLExport& rExp) :
 XMLEventExport::~XMLEventExport()
 {
     // delete all handlers
-    for( auto& rEntry : aHandlerMap )
-    {
-        delete rEntry.second;
-    }
     aHandlerMap.clear();
 }
 
 void XMLEventExport::AddHandler( const OUString& rName,
-                                 XMLEventExportHandler* pHandler )
+                                 std::unique_ptr<XMLEventExportHandler> pHandler )
 {
-    DBG_ASSERT(pHandler != nullptr, "Need EventExportHandler");
-    if (pHandler != nullptr)
-    {
-        aHandlerMap[rName] = pHandler;
-    }
+    assert(pHandler);
+    aHandlerMap[rName] = std::move(pHandler);
 }
 
 void XMLEventExport::AddTranslationTable(


More information about the Libreoffice-commits mailing list