From 8a698bd62b076d3beac05dc5310d6cb51610f907 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Tue, 8 Dec 2015 08:04:33 +0100
Subject: [PATCH] [MeL/MG] LayeredMeshGenerateor::getMesh(): Declare the
 ownership of the mesh.

---
 MeshLib/MeshGenerators/LayeredMeshGenerator.cpp | 11 ++++++-----
 MeshLib/MeshGenerators/LayeredMeshGenerator.h   |  5 +++--
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp b/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp
index 4a7caea00d4..dde814df04b 100644
--- a/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp
+++ b/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp
@@ -55,7 +55,8 @@ bool LayeredMeshGenerator::createLayers(MeshLib::Mesh const& mesh,
     return result;
 }
 
-MeshLib::Mesh* LayeredMeshGenerator::getMesh(std::string const& mesh_name) const
+std::unique_ptr<MeshLib::Mesh>
+LayeredMeshGenerator::getMesh(std::string const& mesh_name) const
 {
 	if (_nodes.empty() || _elements.empty())
 		return nullptr;
@@ -71,11 +72,11 @@ MeshLib::Mesh* LayeredMeshGenerator::getMesh(std::string const& mesh_name) const
 	else
 		WARN ("Skipping MaterialID information, number of entries does not match element number");
 
-	MeshLib::Mesh* result (new MeshLib::Mesh(mesh_name, _nodes, _elements, properties));
-	MeshLib::NodeSearch ns(*result);
+	std::unique_ptr<MeshLib::Mesh> result(new MeshLib::Mesh(mesh_name, _nodes, _elements, properties));
+	MeshLib::NodeSearch ns(*result.get());
 	if (ns.searchUnused() > 0) {
-		auto new_mesh = MeshLib::removeNodes(*result, ns.getSearchedNodeIDs(), mesh_name);
-		delete result;
+		std::unique_ptr<MeshLib::Mesh> new_mesh(MeshLib::removeNodes(
+			*result.get(), ns.getSearchedNodeIDs(), mesh_name));
 		return new_mesh;
 	}
 	return result;
diff --git a/MeshLib/MeshGenerators/LayeredMeshGenerator.h b/MeshLib/MeshGenerators/LayeredMeshGenerator.h
index 958d598d102..1b5a4692ecf 100644
--- a/MeshLib/MeshGenerators/LayeredMeshGenerator.h
+++ b/MeshLib/MeshGenerators/LayeredMeshGenerator.h
@@ -15,9 +15,10 @@
 #ifndef LAYEREDMESHGENERATOR_H
 #define LAYEREDMESHGENERATOR_H
 
+#include <memory>
+#include <limits>
 #include <string>
 #include <vector>
-#include <limits>
 
 namespace GeoLib {
     class Raster;
@@ -62,7 +63,7 @@ public:
 	                                double noDataReplacementValue) = 0;
 
 	/// Returns a mesh of the subsurface representation
-	MeshLib::Mesh* getMesh(std::string const& mesh_name) const;
+	std::unique_ptr<MeshLib::Mesh> getMesh(std::string const& mesh_name) const;
 
 protected:
 	LayeredMeshGenerator();
-- 
GitLab