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 @@
#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 );
......
......@@ -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);
}
......
......@@ -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(
......
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