From a492501fcd5c53b630e941cb6832b4037d52717e Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@cnes.fr>
Date: Tue, 21 Feb 2017 13:25:28 +0100
Subject: [PATCH] STY: Use std::auto_ptr instead of bare * (from RFC review)

---
 .../include/otbSarSensorModelAdapter.h           |  4 +++-
 .../src/otbSarSensorModelAdapter.cxx             | 16 +++++-----------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/Modules/Adapters/OSSIMAdapters/include/otbSarSensorModelAdapter.h b/Modules/Adapters/OSSIMAdapters/include/otbSarSensorModelAdapter.h
index b3276c5aa7..8f89563125 100644
--- a/Modules/Adapters/OSSIMAdapters/include/otbSarSensorModelAdapter.h
+++ b/Modules/Adapters/OSSIMAdapters/include/otbSarSensorModelAdapter.h
@@ -18,6 +18,8 @@
 #ifndef otbSarSensorModelAdapter_h
 #define otbSarSensorModelAdapter_h
 
+#include <memory>
+
 #include "otbDEMHandler.h"
 
 namespace ossimplugins
@@ -55,7 +57,7 @@ public:
   typedef itk::SmartPointer<Self>       Pointer;
   typedef itk::SmartPointer<const Self> ConstPointer;
 
-  typedef ossimplugins::ossimSarSensorModel* InternalModelPointer;
+  typedef std::auto_ptr<ossimplugins::ossimSarSensorModel> InternalModelPointer;
 
   /** Method for creation through the object factory. */
   itkNewMacro(Self);
diff --git a/Modules/Adapters/OSSIMAdapters/src/otbSarSensorModelAdapter.cxx b/Modules/Adapters/OSSIMAdapters/src/otbSarSensorModelAdapter.cxx
index 929bdef3cc..7cda57a0cc 100644
--- a/Modules/Adapters/OSSIMAdapters/src/otbSarSensorModelAdapter.cxx
+++ b/Modules/Adapters/OSSIMAdapters/src/otbSarSensorModelAdapter.cxx
@@ -46,9 +46,7 @@ SarSensorModelAdapter::SarSensorModelAdapter():
 }
 
 SarSensorModelAdapter::~SarSensorModelAdapter()
-{
-    delete m_SensorModel;
-}
+{}
 
 bool SarSensorModelAdapter::LoadState(const ImageKeywordlist& image_kwl)
 {
@@ -57,19 +55,15 @@ bool SarSensorModelAdapter::LoadState(const ImageKeywordlist& image_kwl)
    ossimKeywordlist geom;
    image_kwl.convertToOSSIMKeywordlist(geom);
 
-   if(m_SensorModel != ITK_NULLPTR)
-     {
-     delete m_SensorModel;
-     }
    
-   m_SensorModel =  dynamic_cast<ossimplugins::ossimSarSensorModel* >(ossimplugins::ossimPluginProjectionFactory::instance()->createProjection(geom));
+   m_SensorModel.reset(dynamic_cast<ossimplugins::ossimSarSensorModel* >(ossimplugins::ossimPluginProjectionFactory::instance()->createProjection(geom)));
 
    return IsValidSensorModel();
 }
 
 bool SarSensorModelAdapter::SaveState(ImageKeywordlist & image_kwl)
 {
-  if(m_SensorModel != ITK_NULLPTR)
+  if(m_SensorModel.get() != ITK_NULLPTR)
     {
     ossimKeywordlist geom;
 
@@ -89,12 +83,12 @@ bool SarSensorModelAdapter::SaveState(ImageKeywordlist & image_kwl)
 
 bool SarSensorModelAdapter::IsValidSensorModel() const
 {
-  return m_SensorModel != ITK_NULLPTR;
+  return m_SensorModel.get() != ITK_NULLPTR;
 }
 
 bool SarSensorModelAdapter::Deburst(std::vector<std::pair<unsigned long, unsigned long>> & lines)
 {
-  if(m_SensorModel != ITK_NULLPTR)
+  if(m_SensorModel.get() != ITK_NULLPTR)
     {
     return m_SensorModel->deburst(lines);
     }
-- 
GitLab