diff --git a/Applications/Utils/FileConverter/FEFLOW2OGS.cpp b/Applications/Utils/FileConverter/FEFLOW2OGS.cpp index 7fedd164a14401b32c9e1edfd8256994f184e2cf..c9e368f60b83eedc740bf22c4e7367b456fff63f 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 2bc957f934de68bf0812f5a98f8d3e02f1883bf7..18f0572363a2adc246b857428780a8d5c3e57cf5 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 4b78f13062f0d7954bdb036d9faecfc54ed2bfa5..277f39a03ee39a9e5f8649599daa631d5f1973ef 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 e92ecbc69d4ada82bd7830da5c11ea9e3847b816..c026dff8bb34bea560626f45918731993dc886d4 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 811f72e7ff9382110643f5c25b696ccae7eda48b..1c51444fa92d51d41ded07c133d827a143ec6ae3 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 0667cf3bdcdd3cbc736ac641a8bfa65bcd6c0004..e211f94e91af8f4fde279db8fe4893890440717e 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 dc03093bdd34282eee3e137e9c8f6fd0eb6bf2cf..1203da3a1f75bd567aaea7541b6d62b22f653ebd 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 67865d3f0a6f435606c92142ab248d630b470637..8d88cd9328325a2902ada8ea63a1aa0568090c56 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; }