]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Convert two more members of Triangulation from raw pointers to std_cxx11::unique_ptrs.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 10 Aug 2016 13:40:10 +0000 (08:40 -0500)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 14 Aug 2016 19:17:15 +0000 (14:17 -0500)
include/deal.II/grid/tria.h
source/grid/tria.cc

index c414dff9c7cd8f99a68cb5638a7b4dcedc88efc2..6c213fa85d6824713fa6540746cc42d82b4b49bc 100644 (file)
@@ -3405,7 +3405,7 @@ private:
    * this field (that can be modified by TriaAccessor::set_boundary_id) were
    * not a pointer.
    */
-  std::map<unsigned int, types::boundary_id> *vertex_to_boundary_id_map_1d;
+  std_cxx11::unique_ptr<std::map<unsigned int, types::boundary_id> > 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<unsigned int, types::manifold_id> *vertex_to_manifold_id_map_1d;
+  std_cxx11::unique_ptr<std::map<unsigned int, types::manifold_id> > vertex_to_manifold_id_map_1d;
 
   // make a couple of classes friends
   template <int,int,int> friend class TriaAccessorBase;
index f03cff7cee28fee53e7b4bb6ab4ebb3e86f8d1f8..c0fa0b5e7a90b5338303b6a9d465668df6e5088f 100644 (file)
@@ -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<unsigned int, types::boundary_id>();
+      .reset (new std::map<unsigned int, types::boundary_id>());
       vertex_to_manifold_id_map_1d
-        = new std::map<unsigned int, types::manifold_id>();
+      .reset (new std::map<unsigned int, types::manifold_id>());
     }
 
   // connect the any_change signal to the other top level signals
@@ -8984,9 +8982,7 @@ Triangulation (const Triangulation<dim, spacedim> &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<dim, spacedim> &&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.levels.size(); ++i)
     tria.levels[i] = nullptr;
 
   tria.number_cache = internal::Triangulation::NumberCache<dim>();
-
-  tria.vertex_to_boundary_id_map_1d = nullptr;
-  tria.vertex_to_manifold_id_map_1d = nullptr;
 }
 #endif
 
@@ -9038,29 +9031,21 @@ Triangulation<dim, spacedim>::~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<dim, spacedim> &old_tria)
 
   if (dim == 1)
     {
-      delete vertex_to_boundary_id_map_1d;
       vertex_to_boundary_id_map_1d
-        = (new std::map<unsigned int, types::boundary_id>
-           (*old_tria.vertex_to_boundary_id_map_1d));
+      .reset(new std::map<unsigned int, types::boundary_id>
+             (*old_tria.vertex_to_boundary_id_map_1d));
 
-      delete vertex_to_manifold_id_map_1d;
       vertex_to_manifold_id_map_1d
-        = (new std::map<unsigned int, types::manifold_id>
-           (*old_tria.vertex_to_manifold_id_map_1d));
+      .reset(new std::map<unsigned int, types::manifold_id>
+             (*old_tria.vertex_to_manifold_id_map_1d));
     }
 
   // inform those who are listening on old_tria of the copy operation

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.