]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
[Partial load] shared_ptr instead of raw pointer
authorAnida Khizar <anida.khizar@cea.fr>
Wed, 1 Feb 2023 14:20:07 +0000 (15:20 +0100)
committerAnida Khizar <anida.khizar@cea.fr>
Wed, 1 Feb 2023 14:20:07 +0000 (15:20 +0100)
src/MEDLoader/MEDFilterEntity.hxx

index 4a61d6ee68aa1562f519f20b84b96d742aa37249..d806a22603cdbafc6b8816a479e4d8d80b280ea5 100644 (file)
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anida Khizar (CEA/DES)
 
 #ifndef __MEDFILTERENTITY_HXX__
 #define __MEDFILTERENTITY_HXX__
 
 #include "MEDCouplingPartDefinition.hxx"
 #include "med.h"
+#include <memory>
 
 namespace MEDCoupling
 {
   class MEDFilterEntity
   {
   public:
-    MEDFilterEntity() { _filter = new med_filter; }
-    ~MEDFilterEntity() { delete _filter; }
+    MEDFilterEntity() { _filter = std::make_shared<med_filter>(); }
     void init() { *_filter = MED_FILTER_INIT; }
     inline void fill(med_idt fid, mcIdType nbOfEntity, mcIdType nbOfValuesPerEntity, mcIdType nbOfConstituentPerValue,
                      const med_int constituentSelect, const med_switch_mode switchMode, const med_storage_mode storageMode, const char * const profileName,
                      const PartDefinition* pd);
-    const med_filter *getPtr() const { return _filter; }
-    void close() { MEDfilterClose(_filter); }
+    const med_filter *getPtr() const { return _filter.get(); }
+    void close() { MEDfilterClose(_filter.get()); }
   private:
-    med_filter *_filter;
+    std::shared_ptr<med_filter> _filter;
   };
 }
 
@@ -61,7 +61,7 @@ void MEDCoupling::MEDFilterEntity::fill(med_idt fid, mcIdType nbOfEntity, mcIdTy
       MEDfilterBlockOfEntityCr(fid,ToMedInt(nbOfEntity),ToMedInt(nbOfValuesPerEntity),ToMedInt(nbOfConstituentPerValue),
                                constituentSelect,switchMode,storageMode,profileName,
                                /*start*/ToMedInt(strt+1),/*stride*/ToMedInt(step),/*count*/1,/*blocksize*/ToMedInt(nbOfEltsToLoad),
-                               /*lastblocksize=useless because count=1*/0,_filter);
+                               /*lastblocksize=useless because count=1*/0,_filter.get());
       return;
     }
   const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
@@ -79,7 +79,7 @@ void MEDCoupling::MEDFilterEntity::fill(med_idt fid, mcIdType nbOfEntity, mcIdTy
       MEDfilterEntityCr(fid,ToMedInt(nbOfEntity),ToMedInt(nbOfValuesPerEntity),ToMedInt(nbOfConstituentPerValue),
                             constituentSelect,switchMode,storageMode,profileName,
                             ToMedInt(nbOfEltsToLoad), dpdPlus1.data(),
-                            _filter);
+                            _filter.get());
       return;
     }
   throw INTERP_KERNEL::Exception("MEDFilterEntity::fill : empty part definition !");