From a73884fe79c6336c1f376b53cad0fef891cf802b Mon Sep 17 00:00:00 2001 From: ctraizet <cedric.traizet@c-s.fr> Date: Mon, 11 Mar 2019 11:24:21 +0100 Subject: [PATCH] BUG: use smart pointer to manage the default callback --- .../include/otbStandardOneLineFilterWatcher.h | 4 ++-- .../otbStandardOneLineFilterWatcher.hxx | 19 ++++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.h b/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.h index 68b8173b81..9b49904d56 100644 --- a/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.h +++ b/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.h @@ -68,7 +68,7 @@ public: StandardOneLineFilterWatcher(); /** Destrucotr */ - virtual ~StandardOneLineFilterWatcher(); + virtual ~StandardOneLineFilterWatcher() =default; /** Get/Set number of stars */ void SetStars(int count) @@ -115,7 +115,7 @@ private: /** A default callback created in the constructor and deleted in the * destructor. */ - PrintCallbackType * m_DefaultCallback; + std::shared_ptr<PrintCallbackType> m_DefaultCallback; }; } // end namespace otb diff --git a/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.hxx b/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.hxx index 129ccefa6b..db25082dce 100644 --- a/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.hxx +++ b/Modules/Core/Common/include/otbStandardOneLineFilterWatcher.hxx @@ -38,8 +38,8 @@ StandardOneLineFilterWatcher<PrintCallbackType> m_CurrentNbStars(-1), m_CoutIsConsole( System::IsInteractive(1) ) { - m_DefaultCallback = new PrintCallbackType; - m_Callback = m_DefaultCallback; + m_DefaultCallback = std::make_shared<PrintCallbackType>() ; + m_Callback = m_DefaultCallback.get(); } template<class PrintCallbackType> @@ -51,8 +51,8 @@ StandardOneLineFilterWatcher<PrintCallbackType> m_CurrentNbStars(-1), m_CoutIsConsole( System::IsInteractive(1) ) { - m_DefaultCallback = new PrintCallbackType; - m_Callback = m_DefaultCallback; + m_DefaultCallback = std::make_shared<PrintCallbackType>() ; + m_Callback = m_DefaultCallback.get(); } template<class PrintCallbackType> @@ -64,15 +64,8 @@ StandardOneLineFilterWatcher<PrintCallbackType> m_CurrentNbStars(-1), m_CoutIsConsole( System::IsInteractive(1) ) { - m_DefaultCallback = new PrintCallbackType; - m_Callback = m_DefaultCallback; -} - -template<class PrintCallbackType> -StandardOneLineFilterWatcher<PrintCallbackType> -::~StandardOneLineFilterWatcher() -{ - delete m_DefaultCallback; + m_DefaultCallback = std::make_shared<PrintCallbackType>() ; + m_Callback = m_DefaultCallback.get(); } template<class PrintCallbackType> -- GitLab