From 03a2be85d9b88a75948da9f4d2d3f01c281fde01 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 29 Aug 2024 10:42:26 +0200 Subject: [PATCH] [EDF30834] : get rid of incrRef / decrRef delete -> use RAII --- src/ShapeRecogn/Nodes.cxx | 7 --- src/ShapeRecogn/Nodes.hxx | 8 ++-- src/ShapeRecogn/NodesBuilder.cxx | 6 +-- src/ShapeRecogn/ShapeRecognMesh.cxx | 42 ++++++----------- src/ShapeRecogn/ShapeRecognMesh.hxx | 54 +++++++++++----------- src/ShapeRecogn/ShapeRecognMeshBuilder.cxx | 54 +++++++++------------- src/ShapeRecogn/ShapeRecognMeshBuilder.hxx | 19 ++++---- src/ShapeRecogn/Test/ConeTest.cxx | 4 +- src/ShapeRecogn/Test/ConeTest.hxx | 6 ++- src/ShapeRecogn/Test/CylinderTest.cxx | 4 +- src/ShapeRecogn/Test/CylinderTest.hxx | 6 ++- src/ShapeRecogn/Test/PlaneTest.cxx | 4 +- src/ShapeRecogn/Test/PlaneTest.hxx | 6 ++- src/ShapeRecogn/Test/SphereTest.cxx | 4 +- src/ShapeRecogn/Test/SphereTest.hxx | 6 ++- src/ShapeRecogn/Test/TorusTest.cxx | 4 +- src/ShapeRecogn/Test/TorusTest.hxx | 6 ++- 17 files changed, 109 insertions(+), 131 deletions(-) diff --git a/src/ShapeRecogn/Nodes.cxx b/src/ShapeRecogn/Nodes.cxx index 615971ad4..3e884d327 100644 --- a/src/ShapeRecogn/Nodes.cxx +++ b/src/ShapeRecogn/Nodes.cxx @@ -10,13 +10,6 @@ Nodes::Nodes( { } -Nodes::~Nodes() -{ - mesh->decrRef(); - neighbors->decrRef(); - neighborsIdx->decrRef(); -} - mcIdType Nodes::getNbNodes() const { return coords->getNumberOfTuples(); diff --git a/src/ShapeRecogn/Nodes.hxx b/src/ShapeRecogn/Nodes.hxx index 1d47d3060..729a1910e 100644 --- a/src/ShapeRecogn/Nodes.hxx +++ b/src/ShapeRecogn/Nodes.hxx @@ -33,7 +33,7 @@ namespace MEDCoupling Nodes(const MEDCouplingUMesh *mesh, const DataArrayInt64 *neighbors, const DataArrayInt64 *neighborsIdx); - ~Nodes(); + ~Nodes() = default; mcIdType getNbNodes() const; const std::vector &getK1() const; @@ -57,13 +57,13 @@ namespace MEDCoupling std::array getCoordinates(mcIdType nodeId) const; private: - const MEDCouplingUMesh *mesh; + MCConstAuto mesh; const DataArrayDouble *coords; // normals 3 * nbNodes std::vector normals; // neighbors - const DataArrayInt64 *neighbors; - const DataArrayInt64 *neighborsIdx; + MCConstAuto neighbors; + MCConstAuto neighborsIdx; // curvature std::vector k1; std::vector k2; diff --git a/src/ShapeRecogn/NodesBuilder.cxx b/src/ShapeRecogn/NodesBuilder.cxx index 206c97387..a33103f4b 100644 --- a/src/ShapeRecogn/NodesBuilder.cxx +++ b/src/ShapeRecogn/NodesBuilder.cxx @@ -41,8 +41,8 @@ void NodesBuilder::computeNormals() } // nodes->normals.resize(3 * nbNodes, 1.0); - DataArrayInt64 *revNodal = DataArrayInt64::New(); - DataArrayInt64 *revNodalIdx = DataArrayInt64::New(); + MCAuto revNodal = DataArrayInt64::New(); + MCAuto revNodalIdx = DataArrayInt64::New(); mesh->getReverseNodalConnectivity(revNodal, revNodalIdx); for (size_t nodeId = 0; nodeId < (size_t)nbNodes; nodeId++) { @@ -67,8 +67,6 @@ void NodesBuilder::computeNormals() for (size_t i = 0; i < 3; i++) nodes->normals[3 * nodeId + i] /= sqrt(normal); } - revNodal->decrRef(); - revNodalIdx->decrRef(); } void NodesBuilder::computeCurvatures(double tol) diff --git a/src/ShapeRecogn/ShapeRecognMesh.cxx b/src/ShapeRecogn/ShapeRecognMesh.cxx index 4c8ee5f9f..ab76446a6 100644 --- a/src/ShapeRecogn/ShapeRecognMesh.cxx +++ b/src/ShapeRecogn/ShapeRecognMesh.cxx @@ -11,22 +11,6 @@ ShapeRecognMesh::ShapeRecognMesh() angle(0), center(0), axis(0), apex(0) { } -ShapeRecognMesh::~ShapeRecognMesh() -{ - nodeK1->decrRef(); - nodeK2->decrRef(); - nodePrimitiveType->decrRef(); - nodeNormal->decrRef(); - areaId->decrRef(); - areaPrimitiveType->decrRef(); - areaNormal->decrRef(); - minorRadius->decrRef(); - radius->decrRef(); - angle->decrRef(); - center->decrRef(); - axis->decrRef(); - apex->decrRef(); -} std::size_t ShapeRecognMesh::getHeapMemorySizeWithoutChildren() const { @@ -89,67 +73,67 @@ void ShapeRecognMesh::save(const std::string &outputFile, bool writeFromScratch) WriteField(outputFile, apex, false); } -MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK1() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK1() const { return nodeK1; } -MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK2() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK2() const { return nodeK2; } -MEDCouplingFieldDouble *ShapeRecognMesh::getNodePrimitiveType() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getNodePrimitiveType() const { return nodePrimitiveType; } -MEDCouplingFieldDouble *ShapeRecognMesh::getNodeNormal() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getNodeNormal() const { return nodeNormal; } -MEDCouplingFieldDouble *ShapeRecognMesh::getAreaId() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getAreaId() const { return areaId; } -MEDCouplingFieldDouble *ShapeRecognMesh::getAreaPrimitiveType() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getAreaPrimitiveType() const { return areaPrimitiveType; } -MEDCouplingFieldDouble *ShapeRecognMesh::getAreaNormal() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getAreaNormal() const { return areaNormal; } -MEDCouplingFieldDouble *ShapeRecognMesh::getMinorRadius() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getMinorRadius() const { return minorRadius; } -MEDCouplingFieldDouble *ShapeRecognMesh::getRadius() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getRadius() const { return radius; } -MEDCouplingFieldDouble *ShapeRecognMesh::getAngle() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getAngle() const { return angle; } -MEDCouplingFieldDouble *ShapeRecognMesh::getCenter() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getCenter() const { return center; } -MEDCouplingFieldDouble *ShapeRecognMesh::getAxis() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getAxis() const { return axis; } -MEDCouplingFieldDouble *ShapeRecognMesh::getApex() const +const MEDCouplingFieldDouble *ShapeRecognMesh::getApex() const { return apex; } diff --git a/src/ShapeRecogn/ShapeRecognMesh.hxx b/src/ShapeRecogn/ShapeRecognMesh.hxx index 02983e34a..1ab49bf3a 100644 --- a/src/ShapeRecogn/ShapeRecognMesh.hxx +++ b/src/ShapeRecogn/ShapeRecognMesh.hxx @@ -40,40 +40,40 @@ namespace MEDCoupling void save(const std::string &outputFile, bool writeFromScratch = true) const; // Node properties - MEDCoupling::MEDCouplingFieldDouble *getNodeK1() const; - MEDCoupling::MEDCouplingFieldDouble *getNodeK2() const; - MEDCoupling::MEDCouplingFieldDouble *getNodePrimitiveType() const; - MEDCoupling::MEDCouplingFieldDouble *getNodeNormal() const; + const MEDCouplingFieldDouble *getNodeK1() const; + const MEDCouplingFieldDouble *getNodeK2() const; + const MEDCouplingFieldDouble *getNodePrimitiveType() const; + const MEDCouplingFieldDouble *getNodeNormal() const; // Area properties - MEDCoupling::MEDCouplingFieldDouble *getAreaId() const; - MEDCoupling::MEDCouplingFieldDouble *getAreaPrimitiveType() const; - MEDCoupling::MEDCouplingFieldDouble *getAreaNormal() const; - MEDCoupling::MEDCouplingFieldDouble *getMinorRadius() const; - MEDCoupling::MEDCouplingFieldDouble *getRadius() const; - MEDCoupling::MEDCouplingFieldDouble *getAngle() const; - MEDCoupling::MEDCouplingFieldDouble *getCenter() const; - MEDCoupling::MEDCouplingFieldDouble *getAxis() const; - MEDCoupling::MEDCouplingFieldDouble *getApex() const; + const MEDCouplingFieldDouble *getAreaId() const; + const MEDCouplingFieldDouble *getAreaPrimitiveType() const; + const MEDCouplingFieldDouble *getAreaNormal() const; + const MEDCouplingFieldDouble *getMinorRadius() const; + const MEDCouplingFieldDouble *getRadius() const; + const MEDCouplingFieldDouble *getAngle() const; + const MEDCouplingFieldDouble *getCenter() const; + const MEDCouplingFieldDouble *getAxis() const; + const MEDCouplingFieldDouble *getApex() const; protected: ShapeRecognMesh(); - ~ShapeRecognMesh(); + ~ShapeRecognMesh() = default; private: - MEDCoupling::MEDCouplingFieldDouble *nodeK1; - MEDCoupling::MEDCouplingFieldDouble *nodeK2; - MEDCoupling::MEDCouplingFieldDouble *nodePrimitiveType; - MEDCoupling::MEDCouplingFieldDouble *nodeNormal; - MEDCoupling::MEDCouplingFieldDouble *areaId; - MEDCoupling::MEDCouplingFieldDouble *areaPrimitiveType; - MEDCoupling::MEDCouplingFieldDouble *areaNormal; - MEDCoupling::MEDCouplingFieldDouble *minorRadius; - MEDCoupling::MEDCouplingFieldDouble *radius; - MEDCoupling::MEDCouplingFieldDouble *angle; - MEDCoupling::MEDCouplingFieldDouble *center; - MEDCoupling::MEDCouplingFieldDouble *axis; - MEDCoupling::MEDCouplingFieldDouble *apex; + MCAuto nodeK1; + MCAuto nodeK2; + MCAuto nodePrimitiveType; + MCAuto nodeNormal; + MCAuto areaId; + MCAuto areaPrimitiveType; + MCAuto areaNormal; + MCAuto minorRadius; + MCAuto radius; + MCAuto angle; + MCAuto center; + MCAuto axis; + MCAuto apex; }; }; diff --git a/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx b/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx index 9118fa758..826917501 100644 --- a/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx +++ b/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx @@ -17,23 +17,14 @@ ShapeRecognMeshBuilder::ShapeRecognMeshBuilder(const std::string &fileName, int throw INTERP_KERNEL::Exception("Expect a mesh containing exclusively triangular cells"); } -ShapeRecognMeshBuilder::~ShapeRecognMeshBuilder() -{ - if (areas != nullptr) - delete areas; - if (nodes != nullptr) - delete nodes; - mesh->decrRef(); -} - MCAuto ShapeRecognMeshBuilder::recognize() { mesh->incrRef(); NodesBuilder nodesBuilder(mesh); - nodes = nodesBuilder.build(); - AreasBuilder areasBuilder(nodes); + nodes.reset( nodesBuilder.build() ); + AreasBuilder areasBuilder(nodes.get()); areasBuilder.build(); - areas = areasBuilder.getAreas(); + areas.reset( areasBuilder.getAreas() ); MCAuto recognMesh = ShapeRecognMesh::New(); recognMesh->nodeK1 = buildNodeK1(); recognMesh->nodeK2 = buildNodeK2(); @@ -53,52 +44,52 @@ MCAuto ShapeRecognMeshBuilder::recognize() const Nodes *ShapeRecognMeshBuilder::getNodes() const { - return nodes; + return nodes.get(); } const Areas *ShapeRecognMeshBuilder::getAreas() const { - return areas; + return areas.get(); } MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK1() const { - if (nodes == nullptr) + if ( ! nodes.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); return buildField("K1 (Node)", 1, nodes->getK1()); } MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK2() const { - if (nodes == nullptr) + if ( ! nodes.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); return buildField("K2 (Node)", 1, nodes->getK2()); } MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodePrimitiveType() const { - if (nodes == nullptr) + if ( ! nodes.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); return buildField("Primitive Type (Node)", 1, nodes->getPrimitiveType()); } MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeNormal() const { - if (nodes == nullptr) + if ( ! nodes.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); return buildField("Normal (Node)", 3, nodes->getNormals()); } MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaId() const { - if (areas == nullptr) + if ( ! areas.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); return buildField("Area Id", 1, areas->getAreaIdByNodes()); } MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaPrimitiveType() const { - if (areas == nullptr) + if ( ! areas.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double { return (double)areas->getPrimitiveType(areaId); }); @@ -107,7 +98,7 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaPrimitiveType() const MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaNormal() const { - if (areas == nullptr) + if ( ! areas.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array & { return areas->getNormal(areaId); }); @@ -116,7 +107,7 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaNormal() const MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildMinorRadius() const { - if (areas == nullptr) + if ( ! areas.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double { return areas->getMinorRadius(areaId); }); @@ -125,7 +116,7 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildMinorRadius() const MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildRadius() const { - if (areas == nullptr) + if ( ! areas.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double { return areas->getRadius(areaId); }); @@ -134,7 +125,7 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildRadius() const MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAngle() const { - if (areas == nullptr) + if ( ! areas.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double { return areas->getAngle(areaId); }); @@ -143,7 +134,7 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAngle() const MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildCenter() const { - if (areas == nullptr) + if ( ! areas.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array & { return areas->getCenter(areaId); }); @@ -152,7 +143,7 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildCenter() const MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAxis() const { - if (areas == nullptr) + if ( ! areas.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array & { return areas->getAxis(areaId); }); @@ -161,7 +152,7 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAxis() const MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildApex() const { - if (areas == nullptr) + if ( ! areas.get() ) throw INTERP_KERNEL::Exception("recognize must be called before building any fields"); double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array & { return areas->getApex(areaId); }); @@ -174,7 +165,7 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildField( size_t nbOfCompo, const std::vector &values) const { - DataArrayDouble *data = DataArrayDouble::New(); + MCAuto data( DataArrayDouble::New() ); data->setName(name); data->alloc(nodes->getNbNodes(), nbOfCompo); std::copy(values.begin(), values.end(), data->getPointer()); @@ -201,7 +192,7 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildField( MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildField( const std::string &name, size_t nbOfCompo, - DataArrayDouble *data) const + MCAuto data) const { MEDCouplingFieldDouble *field = MEDCouplingFieldDouble::New(ON_NODES); field->setName(name); @@ -213,7 +204,6 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildField( data->setInfoOnComponent(2, "Z"); } field->setArray(data); - data->decrRef(); return field; } @@ -227,7 +217,7 @@ double *ShapeRecognMeshBuilder::buildArea3DArray( mcIdType areaId = areaIdByNodes[nodeId]; if (areaId != -1) { - const std::array &areaValues = areaFunc(areas, areaId); + const std::array &areaValues = areaFunc(areas.get(), areaId); values[3 * nodeId] = areaValues[0]; values[3 * nodeId + 1] = areaValues[1]; values[3 * nodeId + 2] = areaValues[2]; @@ -244,7 +234,7 @@ double *ShapeRecognMeshBuilder::buildAreaArray(double (*areaFunc)(Areas *, mcIdT { mcIdType areaId = areaIdByNodes[nodeId]; if (areaId != -1) - values[nodeId] = areaFunc(areas, areaId); + values[nodeId] = areaFunc(areas.get(), areaId); } return values; } diff --git a/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx b/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx index 6ac42743c..9bc6ce3d8 100644 --- a/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx +++ b/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx @@ -25,17 +25,20 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "Nodes.hxx" +#include "Areas.hxx" + +#include + namespace MEDCoupling { - class Nodes; - class Areas; class ShapeRecognMesh; class ShapeRecognMeshBuilder { public: ShapeRecognMeshBuilder(const std::string &fileName, int meshDimRelToMax = 0); - ~ShapeRecognMeshBuilder(); + ~ShapeRecognMeshBuilder() = default; const Nodes *getNodes() const; const Areas *getAreas() const; @@ -72,13 +75,13 @@ namespace MEDCoupling MEDCouplingFieldDouble *buildField( const std::string &name, size_t nbOfCompo, - DataArrayDouble *values) const; + MCAuto values) const; double *buildArea3DArray(const std::array &(*areaFunc)(Areas *, mcIdType)) const; double *buildAreaArray(double (*areaFunc)(Areas *, mcIdType)) const; - - const MEDCouplingUMesh *mesh; - Nodes *nodes = nullptr; - Areas *areas = nullptr; + private: + MCConstAuto< MEDCouplingUMesh > mesh; + std::unique_ptr nodes; + std::unique_ptr areas; }; }; diff --git a/src/ShapeRecogn/Test/ConeTest.cxx b/src/ShapeRecogn/Test/ConeTest.cxx index b43616c4f..7f2c435ad 100644 --- a/src/ShapeRecogn/Test/ConeTest.cxx +++ b/src/ShapeRecogn/Test/ConeTest.cxx @@ -11,15 +11,13 @@ using namespace MEDCoupling; void ConeTest::setUp() { std::string file = INTERP_TEST::getResourceFile("ShapeRecognCone.med", 3); - srMesh = new ShapeRecognMeshBuilder(file); + srMesh.reset( new ShapeRecognMeshBuilder(file) ); srMesh->recognize(); areas = srMesh->getAreas(); } void ConeTest::tearDown() { - if (srMesh != 0) - delete srMesh; areas = 0; } diff --git a/src/ShapeRecogn/Test/ConeTest.hxx b/src/ShapeRecogn/Test/ConeTest.hxx index 20b1bef3f..b9e577e0f 100644 --- a/src/ShapeRecogn/Test/ConeTest.hxx +++ b/src/ShapeRecogn/Test/ConeTest.hxx @@ -23,6 +23,10 @@ #include #include +#include "ShapeRecognMeshBuilder.hxx" + +#include + namespace MEDCoupling { class ShapeRecognMeshBuilder; @@ -54,7 +58,7 @@ namespace MEDCoupling void testThirdArea(); private: - ShapeRecognMeshBuilder *srMesh = 0; + std::unique_ptr srMesh; const Areas *areas; }; }; diff --git a/src/ShapeRecogn/Test/CylinderTest.cxx b/src/ShapeRecogn/Test/CylinderTest.cxx index abe69828a..256e5d357 100644 --- a/src/ShapeRecogn/Test/CylinderTest.cxx +++ b/src/ShapeRecogn/Test/CylinderTest.cxx @@ -11,15 +11,13 @@ using namespace MEDCoupling; void CylinderTest::setUp() { std::string file = INTERP_TEST::getResourceFile("ShapeRecognCylinder.med", 3); - srMesh = new ShapeRecognMeshBuilder(file); + srMesh.reset( new ShapeRecognMeshBuilder(file) ); srMesh->recognize(); areas = srMesh->getAreas(); } void CylinderTest::tearDown() { - if (srMesh != 0) - delete srMesh; areas = 0; } diff --git a/src/ShapeRecogn/Test/CylinderTest.hxx b/src/ShapeRecogn/Test/CylinderTest.hxx index a35ac1481..9abab65d2 100644 --- a/src/ShapeRecogn/Test/CylinderTest.hxx +++ b/src/ShapeRecogn/Test/CylinderTest.hxx @@ -23,6 +23,10 @@ #include #include +#include "ShapeRecognMeshBuilder.hxx" + +#include + namespace MEDCoupling { class ShapeRecognMeshBuilder; @@ -47,7 +51,7 @@ namespace MEDCoupling void testThirdArea(); private: - ShapeRecognMeshBuilder *srMesh = 0; + std::unique_ptr< ShapeRecognMeshBuilder > srMesh; const Areas *areas; }; }; diff --git a/src/ShapeRecogn/Test/PlaneTest.cxx b/src/ShapeRecogn/Test/PlaneTest.cxx index ea1153252..2e4537f54 100644 --- a/src/ShapeRecogn/Test/PlaneTest.cxx +++ b/src/ShapeRecogn/Test/PlaneTest.cxx @@ -11,15 +11,13 @@ using namespace MEDCoupling; void PlaneTest::setUp() { std::string file = INTERP_TEST::getResourceFile("ShapeRecognPlane.med", 3); - srMesh = new ShapeRecognMeshBuilder(file); + srMesh.reset( new ShapeRecognMeshBuilder(file) ); srMesh->recognize(); areas = srMesh->getAreas(); } void PlaneTest::tearDown() { - if (srMesh != 0) - delete srMesh; areas = 0; } diff --git a/src/ShapeRecogn/Test/PlaneTest.hxx b/src/ShapeRecogn/Test/PlaneTest.hxx index af6eb4755..df75b543f 100644 --- a/src/ShapeRecogn/Test/PlaneTest.hxx +++ b/src/ShapeRecogn/Test/PlaneTest.hxx @@ -23,6 +23,10 @@ #include #include +#include "ShapeRecognMeshBuilder.hxx" + +#include + namespace MEDCoupling { class ShapeRecognMeshBuilder; @@ -41,7 +45,7 @@ namespace MEDCoupling void testArea(); private: - ShapeRecognMeshBuilder *srMesh = 0; + std::unique_ptr srMesh; const Areas *areas; }; }; diff --git a/src/ShapeRecogn/Test/SphereTest.cxx b/src/ShapeRecogn/Test/SphereTest.cxx index f0b824886..b8c686fc8 100644 --- a/src/ShapeRecogn/Test/SphereTest.cxx +++ b/src/ShapeRecogn/Test/SphereTest.cxx @@ -11,15 +11,13 @@ using namespace MEDCoupling; void SphereTest::setUp() { std::string file = INTERP_TEST::getResourceFile("ShapeRecognSphere.med", 3); - srMesh = new ShapeRecognMeshBuilder(file); + srMesh.reset( new ShapeRecognMeshBuilder(file) ); srMesh->recognize(); areas = srMesh->getAreas(); } void SphereTest::tearDown() { - if (srMesh != 0) - delete srMesh; areas = 0; } diff --git a/src/ShapeRecogn/Test/SphereTest.hxx b/src/ShapeRecogn/Test/SphereTest.hxx index 6500def00..c04218fd1 100644 --- a/src/ShapeRecogn/Test/SphereTest.hxx +++ b/src/ShapeRecogn/Test/SphereTest.hxx @@ -23,6 +23,10 @@ #include #include +#include "ShapeRecognMeshBuilder.hxx" + +#include + namespace MEDCoupling { class ShapeRecognMeshBuilder; @@ -41,7 +45,7 @@ namespace MEDCoupling void testArea(); private: - ShapeRecognMeshBuilder *srMesh = 0; + std::unique_ptr srMesh; const Areas *areas; }; }; diff --git a/src/ShapeRecogn/Test/TorusTest.cxx b/src/ShapeRecogn/Test/TorusTest.cxx index 9b55f23d0..60d8fce5a 100644 --- a/src/ShapeRecogn/Test/TorusTest.cxx +++ b/src/ShapeRecogn/Test/TorusTest.cxx @@ -11,15 +11,13 @@ using namespace MEDCoupling; void TorusTest::setUp() { std::string file = INTERP_TEST::getResourceFile("ShapeRecognTorus.med", 3); - srMesh = new ShapeRecognMeshBuilder(file); + srMesh.reset( new ShapeRecognMeshBuilder(file) ); srMesh->recognize(); areas = srMesh->getAreas(); } void TorusTest::tearDown() { - if (srMesh != 0) - delete srMesh; areas = 0; } diff --git a/src/ShapeRecogn/Test/TorusTest.hxx b/src/ShapeRecogn/Test/TorusTest.hxx index 07ae86d3a..9c700c7a3 100644 --- a/src/ShapeRecogn/Test/TorusTest.hxx +++ b/src/ShapeRecogn/Test/TorusTest.hxx @@ -23,6 +23,10 @@ #include #include +#include "ShapeRecognMeshBuilder.hxx" + +#include + namespace MEDCoupling { class ShapeRecognMeshBuilder; @@ -41,7 +45,7 @@ namespace MEDCoupling void testArea(); private: - ShapeRecognMeshBuilder *srMesh = 0; + std::unique_ptr< ShapeRecognMeshBuilder > srMesh; const Areas *areas; }; }; -- 2.39.2