From: Wolfgang Bangerth Date: Wed, 10 Aug 2016 13:40:10 +0000 (-0500) Subject: Convert two more members of Triangulation from raw pointers to std_cxx11::unique_ptrs. X-Git-Tag: v8.5.0-rc1~774^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dba2d0072eaf04843ee351b29d921ad2b36cc502;p=dealii.git Convert two more members of Triangulation from raw pointers to std_cxx11::unique_ptrs. --- diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index c414dff9c7..6c213fa85d 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -3405,7 +3405,7 @@ private: * this field (that can be modified by TriaAccessor::set_boundary_id) were * not a pointer. */ - std::map *vertex_to_boundary_id_map_1d; + std_cxx11::unique_ptr > vertex_to_boundary_id_map_1d; /** @@ -3427,7 +3427,7 @@ private: * this field (that can be modified by TriaAccessor::set_boundary_id) were * not a pointer. */ - std::map *vertex_to_manifold_id_map_1d; + std_cxx11::unique_ptr > vertex_to_manifold_id_map_1d; // make a couple of classes friends template friend class TriaAccessorBase; diff --git a/source/grid/tria.cc b/source/grid/tria.cc index f03cff7cee..c0fa0b5e7a 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -8957,16 +8957,14 @@ Triangulation (const MeshSmoothing smooth_grid, : smooth_grid(smooth_grid), anisotropic_refinement(false), - check_for_distorted_cells(check_for_distorted_cells), - vertex_to_boundary_id_map_1d (0), - vertex_to_manifold_id_map_1d (0) + check_for_distorted_cells(check_for_distorted_cells) { if (dim == 1) { vertex_to_boundary_id_map_1d - = new std::map(); + .reset (new std::map()); vertex_to_manifold_id_map_1d - = new std::map(); + .reset (new std::map()); } // connect the any_change signal to the other top level signals @@ -8984,9 +8982,7 @@ Triangulation (const Triangulation &other) // is an error! : Subscriptor(), - check_for_distorted_cells(other.check_for_distorted_cells), - vertex_to_boundary_id_map_1d (0), - vertex_to_manifold_id_map_1d (0) + check_for_distorted_cells(other.check_for_distorted_cells) { Assert (false, ExcMessage ("You are not allowed to call this constructor " "because copying Triangulation objects is not " @@ -9012,16 +9008,13 @@ Triangulation (Triangulation &&tria) anisotropic_refinement(tria.anisotropic_refinement), check_for_distorted_cells(tria.check_for_distorted_cells), number_cache(tria.number_cache), - vertex_to_boundary_id_map_1d(tria.vertex_to_boundary_id_map_1d), - vertex_to_manifold_id_map_1d(tria.vertex_to_manifold_id_map_1d) + vertex_to_boundary_id_map_1d(std::move(tria.vertex_to_boundary_id_map_1d)), + vertex_to_manifold_id_map_1d(std::move(tria.vertex_to_manifold_id_map_1d)) { for (unsigned int i=0; i(); - - tria.vertex_to_boundary_id_map_1d = nullptr; - tria.vertex_to_manifold_id_map_1d = nullptr; } #endif @@ -9038,29 +9031,21 @@ Triangulation::~Triangulation () } levels.clear (); - // the vertex_to_boundary_id_map_1d field - // should be unused except in 1d + // the vertex_to_boundary_id_map_1d field should be unused except in + // 1d. double check this here, as destruction is a good place to + // ensure that what we've done over the course of the lifetime of + // this object makes sense Assert ((dim == 1) || (vertex_to_boundary_id_map_1d == 0), ExcInternalError()); - if (vertex_to_boundary_id_map_1d) - { - delete vertex_to_boundary_id_map_1d; - vertex_to_boundary_id_map_1d = 0; - } - // the vertex_to_manifold_id_map_1d field - // should be unused except in 1d + // the vertex_to_manifold_id_map_1d field should be also unused + // except in 1d. check this as well Assert ((dim == 1) || (vertex_to_manifold_id_map_1d == 0), ExcInternalError()); - if (vertex_to_manifold_id_map_1d) - { - delete vertex_to_manifold_id_map_1d; - vertex_to_manifold_id_map_1d = 0; - } } @@ -9334,15 +9319,13 @@ copy_triangulation (const Triangulation &old_tria) if (dim == 1) { - delete vertex_to_boundary_id_map_1d; vertex_to_boundary_id_map_1d - = (new std::map - (*old_tria.vertex_to_boundary_id_map_1d)); + .reset(new std::map + (*old_tria.vertex_to_boundary_id_map_1d)); - delete vertex_to_manifold_id_map_1d; vertex_to_manifold_id_map_1d - = (new std::map - (*old_tria.vertex_to_manifold_id_map_1d)); + .reset(new std::map + (*old_tria.vertex_to_manifold_id_map_1d)); } // inform those who are listening on old_tria of the copy operation