From 634175764a9fc7dd9aca437fa9bb5681f551f59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= <cedric.traizet@c-s.fr> Date: Fri, 2 Aug 2019 17:43:46 +0200 Subject: [PATCH] ENH: use smart pointer to manage the watcher list --- .../SWIG/src/python/otbProgressReporterManager.cxx | 9 ++------- .../SWIG/src/python/otbProgressReporterManager.h | 4 +++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx index e3a6ac5417..ff53453bbe 100644 --- a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx +++ b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx @@ -38,11 +38,6 @@ ProgressReporterManager::~ProgressReporterManager() void ProgressReporterManager::DeleteWatcherList() { - //Delete all stored progress reporter - for (auto watcher: m_WatcherList) - { - delete watcher; - } m_WatcherList.clear(); } @@ -52,9 +47,9 @@ void ProgressReporterManager::LinkWatchers(itk::Object* itkNotUsed(caller), cons { const Wrapper::AddProcessToWatchEvent* eventToWatch = dynamic_cast<const Wrapper::AddProcessToWatchEvent*>(&event); - auto watch = new WatcherType(eventToWatch->GetProcess(), eventToWatch->GetProcessDescription()); + auto watch = std::make_unique< WatcherType>(eventToWatch->GetProcess(), eventToWatch->GetProcessDescription()); watch->SetCallback(m_Callback); - m_WatcherList.push_back(watch); + m_WatcherList.push_back(std::move(watch)); } } } diff --git a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h index ec15926fd2..59d0cafd26 100644 --- a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h +++ b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h @@ -27,6 +27,8 @@ #include "otbSwigPrintCallback.h" #include "otbStandardOneLineFilterWatcher.h" +#include <memory> + namespace otb { @@ -54,7 +56,7 @@ public: typedef StandardOneLineFilterWatcher<CallbackType> WatcherType; /** Filter watcher list type */ - typedef std::vector<WatcherType *> WatcherListType; + typedef std::vector<std::unique_ptr <WatcherType> > WatcherListType; /** Command Member */ typedef itk::MemberCommand<Self> AddProcessCommandType; -- GitLab