From 73b3e5276e3402eaf56fb01e99dbad92a7965935 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Tue, 10 May 2016 08:24:02 +0200
Subject: [PATCH] [A/U] Use unique_ptr.

---
 Applications/Utils/FileConverter/FEFLOW2OGS.cpp      |  7 +++----
 Applications/Utils/FileConverter/OGS2VTK.cpp         |  7 ++++---
 .../CreateBoundaryConditionsAlongPolylines.cpp       |  6 +++---
 Applications/Utils/MeshEdit/MoveMesh.cpp             |  5 +----
 Applications/Utils/MeshEdit/checkMesh.cpp            |  7 ++-----
 Applications/Utils/MeshEdit/editMaterialID.cpp       |  4 +++-
 Applications/Utils/MeshEdit/moveMeshNodes.cpp        |  8 +++++---
 Applications/Utils/MeshEdit/reviseMesh.cpp           | 12 ++++++------
 8 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/Applications/Utils/FileConverter/FEFLOW2OGS.cpp b/Applications/Utils/FileConverter/FEFLOW2OGS.cpp
index 7fedd164a14..c9e368f60b8 100644
--- a/Applications/Utils/FileConverter/FEFLOW2OGS.cpp
+++ b/Applications/Utils/FileConverter/FEFLOW2OGS.cpp
@@ -7,8 +7,8 @@
  *
  */
 
-// STL
 #include <string>
+#include <memory>
 
 // ThirdParty
 #include "tclap/CmdLine.h"
@@ -66,7 +66,8 @@ int main (int argc, char* argv[])
 	BaseLib::RunTime run_time;
 	run_time.start();
 	FileIO::FEFLOWInterface feflowIO(nullptr);
-	MeshLib::Mesh const*const mesh(feflowIO.readFEFLOWFile(feflow_mesh_arg.getValue()));
+	std::unique_ptr<MeshLib::Mesh const> mesh(
+	    feflowIO.readFEFLOWFile(feflow_mesh_arg.getValue()));
 
 	if (mesh == nullptr) {
 		INFO("Could not read mesh from %s.", feflow_mesh_arg.getValue().c_str());
@@ -86,7 +87,5 @@ int main (int argc, char* argv[])
 
 	INFO("\tDone.");
 	return EXIT_SUCCESS;
-
-	delete mesh;
 }
 
diff --git a/Applications/Utils/FileConverter/OGS2VTK.cpp b/Applications/Utils/FileConverter/OGS2VTK.cpp
index 2bc957f934d..18f0572363a 100644
--- a/Applications/Utils/FileConverter/OGS2VTK.cpp
+++ b/Applications/Utils/FileConverter/OGS2VTK.cpp
@@ -11,8 +11,8 @@
  *              http://www.opengeosys.org/LICENSE.txt
  */
 
-// STL
 #include <string>
+#include <memory>
 
 // TCLAP
 #include "tclap/CmdLine.h"
@@ -42,10 +42,11 @@ int main (int argc, char* argv[])
 	cmd.add(mesh_out);
 	cmd.parse(argc, argv);
 
-	MeshLib::Mesh* mesh (MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
+	std::unique_ptr<MeshLib::Mesh const> mesh(
+	    MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
 	INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());
 
-	MeshLib::IO::VtuInterface vtu(mesh);
+	MeshLib::IO::VtuInterface vtu(mesh.get());
 	vtu.writeToFile(mesh_out.getValue());
 
 
diff --git a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp
index 4b78f13062f..277f39a03ee 100644
--- a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp
+++ b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp
@@ -170,7 +170,8 @@ int main (int argc, char* argv[])
 
 	// *** read mesh
 	INFO("Reading mesh \"%s\" ... ", mesh_arg.getValue().c_str());
-	MeshLib::Mesh * subsurface_mesh(MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
+	std::unique_ptr<MeshLib::Mesh> subsurface_mesh(
+	    MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
 	INFO("done.");
 	INFO("Extracting top surface of mesh \"%s\" ... ",
 		mesh_arg.getValue().c_str());
@@ -180,8 +181,7 @@ int main (int argc, char* argv[])
 	    MeshLib::MeshSurfaceExtraction::getMeshSurface(*subsurface_mesh, dir,
 	                                                   angle));
 	INFO("done.");
-	delete subsurface_mesh;
-	subsurface_mesh = nullptr;
+	subsurface_mesh.reset(nullptr);
 
 	// *** read geometry
 	GeoLib::GEOObjects geometries;
diff --git a/Applications/Utils/MeshEdit/MoveMesh.cpp b/Applications/Utils/MeshEdit/MoveMesh.cpp
index e92ecbc69d4..c026dff8bb3 100644
--- a/Applications/Utils/MeshEdit/MoveMesh.cpp
+++ b/Applications/Utils/MeshEdit/MoveMesh.cpp
@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
 
 	std::string fname (mesh_arg.getValue());
 
-	MeshLib::Mesh* mesh = MeshLib::IO::readMeshFromFile(fname);
+	std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(fname));
 
 	if (!mesh) {
 		ERR("Could not read mesh from file \"%s\".", fname.c_str());
@@ -97,7 +97,4 @@ int main(int argc, char *argv[])
 	mesh_io.writeToFile(out_fname);
 
 	return EXIT_SUCCESS;
-	delete mesh;
 }
-
-
diff --git a/Applications/Utils/MeshEdit/checkMesh.cpp b/Applications/Utils/MeshEdit/checkMesh.cpp
index 811f72e7ff9..1c51444fa92 100644
--- a/Applications/Utils/MeshEdit/checkMesh.cpp
+++ b/Applications/Utils/MeshEdit/checkMesh.cpp
@@ -44,14 +44,13 @@ int main(int argc, char *argv[])
 
 	cmd.parse( argc, argv );
 
-	const std::string filename(mesh_arg.getValue());
-
 	// read the mesh file
 	BaseLib::MemWatch mem_watch;
 	const unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
 	BaseLib::RunTime run_time;
 	run_time.start();
-	const MeshLib::Mesh* mesh = MeshLib::IO::readMeshFromFile(filename); // FileIO outputs nr. of nodes and elements
+	std::unique_ptr<MeshLib::Mesh> mesh(
+	    MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
 	if (!mesh)
 		return EXIT_FAILURE;
 
@@ -113,6 +112,4 @@ int main(int argc, char *argv[])
 		else
 			INFO ("No holes found within the mesh.");
 	}
-
-	delete mesh;
 }
diff --git a/Applications/Utils/MeshEdit/editMaterialID.cpp b/Applications/Utils/MeshEdit/editMaterialID.cpp
index 0667cf3bdcd..e211f94e91a 100644
--- a/Applications/Utils/MeshEdit/editMaterialID.cpp
+++ b/Applications/Utils/MeshEdit/editMaterialID.cpp
@@ -6,6 +6,7 @@
  *              http://www.opengeosys.org/LICENSE.txt
  */
 
+#include <memory>
 // TCLAP
 #include "tclap/CmdLine.h"
 
@@ -75,7 +76,8 @@ int main (int argc, char* argv[])
 		}
 	}
 
-	MeshLib::Mesh* mesh (MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
+	std::unique_ptr<MeshLib::Mesh> mesh(
+	    MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
 	INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements());
 
 	if (condenseArg.isSet()) {
diff --git a/Applications/Utils/MeshEdit/moveMeshNodes.cpp b/Applications/Utils/MeshEdit/moveMeshNodes.cpp
index dc03093bdd3..1203da3a1f7 100644
--- a/Applications/Utils/MeshEdit/moveMeshNodes.cpp
+++ b/Applications/Utils/MeshEdit/moveMeshNodes.cpp
@@ -3,6 +3,8 @@
  * 2012/03/07 KR Initial implementation
  */
 
+#include <memory>
+
 #include "Applications/ApplicationsLib/LogogSetup.h"
 
 #include "MeshLib/IO/readMeshFromFile.h"
@@ -94,7 +96,8 @@ int main (int argc, char* argv[])
 		return -1;
 	}
 
-	MeshLib::Mesh* mesh (MeshLib::IO::readMeshFromFile(msh_name));
+	std::unique_ptr<MeshLib::Mesh> mesh(
+	    MeshLib::IO::readMeshFromFile(msh_name));
 	//std::vector<std::size_t> del_nodes;
 
 	// Start keyword-specific selection of nodes
@@ -181,10 +184,9 @@ int main (int argc, char* argv[])
 	/**** add other keywords here ****/
 
 	MeshLib::IO::Legacy::MeshIO meshIO;
-	meshIO.setMesh(mesh);
+	meshIO.setMesh(mesh.get());
 	meshIO.setPrecision(9);
 	meshIO.writeToFile(msh_name.substr(0, msh_name.length()-4) + "_new.msh");
-	delete mesh;
 	return 1;
 
 }
diff --git a/Applications/Utils/MeshEdit/reviseMesh.cpp b/Applications/Utils/MeshEdit/reviseMesh.cpp
index 67865d3f0a6..8d88cd93283 100644
--- a/Applications/Utils/MeshEdit/reviseMesh.cpp
+++ b/Applications/Utils/MeshEdit/reviseMesh.cpp
@@ -8,6 +8,7 @@
  */
 
 #include <array>
+#include <memory>
 #include <string>
 
 #include "tclap/CmdLine.h"
@@ -45,18 +46,20 @@ int main(int argc, char *argv[])
 	cmd.parse( argc, argv );
 
 	// read a mesh file
-	MeshLib::Mesh* org_mesh (MeshLib::IO::readMeshFromFile(input_arg.getValue()));
+	std::unique_ptr<MeshLib::Mesh> org_mesh(
+	    MeshLib::IO::readMeshFromFile(input_arg.getValue()));
 	if (!org_mesh)
 		return EXIT_FAILURE;
 	INFO("Mesh read: %d nodes, %d elements.", org_mesh->getNNodes(), org_mesh->getNElements());
 
 	// revise the mesh
-	MeshLib::Mesh* new_mesh = nullptr;
+	std::unique_ptr<MeshLib::Mesh> new_mesh;
 	if (simplify_arg.getValue()) {
 		INFO("Simplifying the mesh...");
 		MeshLib::MeshRevision rev(const_cast<MeshLib::Mesh&>(*org_mesh));
 		unsigned int minDim = (minDim_arg.isSet() ? minDim_arg.getValue() : org_mesh->getDimension());
-		new_mesh = rev.simplifyMesh("revised_mesh", eps_arg.getValue(), minDim);
+		new_mesh.reset(
+		    rev.simplifyMesh("revised_mesh", eps_arg.getValue(), minDim));
 	}
 
 	// write into a file
@@ -65,8 +68,5 @@ int main(int argc, char *argv[])
 		MeshLib::IO::writeMeshToFile(*new_mesh, output_arg.getValue());
 	}
 
-	delete org_mesh;
-	delete new_mesh;
-
 	return EXIT_SUCCESS;
 }
-- 
GitLab