Kaydet (Commit) 35e1658e authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in XMLEventExport

Change-Id: I29a7c565db576afa4dbd0e0fbd1dfd99f9c989fc
Reviewed-on: https://gerrit.libreoffice.org/60618
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 3c658d7f
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <xmloff/xmlevent.hxx> #include <xmloff/xmlevent.hxx>
#include <map> #include <map>
#include <memory>
class SvXMLExport; class SvXMLExport;
namespace com { namespace sun { namespace star { namespace com { namespace sun { namespace star {
...@@ -38,7 +39,7 @@ namespace com { namespace sun { namespace star { ...@@ -38,7 +39,7 @@ namespace com { namespace sun { namespace star {
namespace beans { struct PropertyValue; } 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; typedef ::std::map< OUString, XMLEventName > NameMap;
/** /**
...@@ -69,13 +70,16 @@ public: ...@@ -69,13 +70,16 @@ public:
XMLEventExport(SvXMLExport& rExport); XMLEventExport(SvXMLExport& rExport);
~XMLEventExport(); ~XMLEventExport();
XMLEventExport& operator=( XMLEventExport const & ) = delete; // MSVC2017 workaround
XMLEventExport( XMLEventExport const & ) = delete; // MSVC2017 workaround
/// register an EventExportHandler for a particular script type /// register an EventExportHandler for a particular script type
/// ///
/// The handlers will be deleted when the object is destroyed, hence /// The handlers will be deleted when the object is destroyed, hence
/// no pointers to a handler registered with AddHandler() should be /// no pointers to a handler registered with AddHandler() should be
/// held by anyone. /// held by anyone.
void AddHandler( const OUString& rName, void AddHandler( const OUString& rName,
XMLEventExportHandler* rHandler ); std::unique_ptr<XMLEventExportHandler> pHandler );
/// register additional event names /// register additional event names
void AddTranslationTable( const XMLEventNameTranslation* pTransTable ); void AddTranslationTable( const XMLEventNameTranslation* pTransTable );
......
...@@ -95,6 +95,7 @@ ...@@ -95,6 +95,7 @@
#include <comphelper/xmltools.hxx> #include <comphelper/xmltools.hxx>
#include <comphelper/graphicmimetype.hxx> #include <comphelper/graphicmimetype.hxx>
#include <o3tl/make_unique.hxx>
using namespace ::osl; using namespace ::osl;
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -2010,8 +2011,8 @@ XMLEventExport& SvXMLExport::GetEventExport() ...@@ -2010,8 +2011,8 @@ XMLEventExport& SvXMLExport::GetEventExport()
mpEventExport.reset( new XMLEventExport(*this) ); mpEventExport.reset( new XMLEventExport(*this) );
// and register standard handlers + names // and register standard handlers + names
mpEventExport->AddHandler("StarBasic", new XMLStarBasicExportHandler()); mpEventExport->AddHandler("StarBasic", o3tl::make_unique<XMLStarBasicExportHandler>());
mpEventExport->AddHandler("Script", new XMLScriptExportHandler()); mpEventExport->AddHandler("Script", o3tl::make_unique<XMLScriptExportHandler>());
mpEventExport->AddTranslationTable(aStandardEventTable); mpEventExport->AddTranslationTable(aStandardEventTable);
} }
......
...@@ -52,21 +52,14 @@ XMLEventExport::XMLEventExport(SvXMLExport& rExp) : ...@@ -52,21 +52,14 @@ XMLEventExport::XMLEventExport(SvXMLExport& rExp) :
XMLEventExport::~XMLEventExport() XMLEventExport::~XMLEventExport()
{ {
// delete all handlers // delete all handlers
for( auto& rEntry : aHandlerMap )
{
delete rEntry.second;
}
aHandlerMap.clear(); aHandlerMap.clear();
} }
void XMLEventExport::AddHandler( const OUString& rName, void XMLEventExport::AddHandler( const OUString& rName,
XMLEventExportHandler* pHandler ) std::unique_ptr<XMLEventExportHandler> pHandler )
{ {
DBG_ASSERT(pHandler != nullptr, "Need EventExportHandler"); assert(pHandler);
if (pHandler != nullptr) aHandlerMap[rName] = std::move(pHandler);
{
aHandlerMap[rName] = pHandler;
}
} }
void XMLEventExport::AddTranslationTable( void XMLEventExport::AddTranslationTable(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment