]> https://gitweb.dealii.org/ - dealii.git/commitdiff
BlockSparsityPatternBase: C++11 cleanups.
authorDavid Wells <drwells@email.unc.edu>
Sat, 29 Oct 2022 23:44:39 +0000 (19:44 -0400)
committerDavid Wells <drwells@email.unc.edu>
Sun, 6 Nov 2022 12:49:36 +0000 (07:49 -0500)
include/deal.II/lac/block_sparsity_pattern.h
source/lac/block_sparsity_pattern.cc

index cfff498c8857db9610a69ab569cdd7238974787b..48e89f0b4426fd4e4ae6ff5be36131e38bd1e56e 100644 (file)
@@ -117,11 +117,6 @@ public:
    */
   BlockSparsityPatternBase(const BlockSparsityPatternBase &bsp);
 
-  /**
-   * Destructor.
-   */
-  ~BlockSparsityPatternBase() override;
-
   /**
    * Resize the matrix, by setting the number of block rows and columns. This
    * deletes all blocks and replaces them with uninitialized ones, i.e. ones
@@ -161,7 +156,6 @@ public:
   SparsityPatternType &
   block(const size_type row, const size_type column);
 
-
   /**
    * Access the block with the given coordinates. Version for constant
    * objects.
@@ -357,10 +351,7 @@ protected:
   /**
    * Array of sparsity patterns.
    */
-  Table<2,
-        SmartPointer<SparsityPatternType,
-                     BlockSparsityPatternBase<SparsityPatternType>>>
-    sub_objects;
+  Table<2, std::unique_ptr<SparsityPatternType>> sub_objects;
 
   /**
    * Object storing and managing the transformation of row indices to indices
index 73ef42c281655bd0eefe67c9198914a6aced994b..e927b177dd80d4b0745c529037d2f6b673df88a7 100644 (file)
@@ -33,8 +33,7 @@ template <class SparsityPatternType>
 BlockSparsityPatternBase<SparsityPatternType>::BlockSparsityPatternBase(
   const size_type n_block_rows,
   const size_type n_block_columns)
-  : rows(0)
-  , columns(0)
+  : BlockSparsityPatternBase()
 {
   reinit(n_block_rows, n_block_columns);
 }
@@ -44,9 +43,7 @@ BlockSparsityPatternBase<SparsityPatternType>::BlockSparsityPatternBase(
 template <class SparsityPatternType>
 BlockSparsityPatternBase<SparsityPatternType>::BlockSparsityPatternBase(
   const BlockSparsityPatternBase &s)
-  : Subscriptor()
-  , rows(0)
-  , columns(0)
+  : BlockSparsityPatternBase()
 {
   (void)s;
   Assert(s.rows == 0 && s.columns == 0,
@@ -58,50 +55,21 @@ BlockSparsityPatternBase<SparsityPatternType>::BlockSparsityPatternBase(
 
 
 
-template <class SparsityPatternType>
-BlockSparsityPatternBase<SparsityPatternType>::~BlockSparsityPatternBase()
-{
-  // clear all memory
-  try
-    {
-      reinit(0, 0);
-    }
-  catch (...)
-    {}
-}
-
-
-
 template <class SparsityPatternType>
 void
 BlockSparsityPatternBase<SparsityPatternType>::reinit(
   const size_type n_block_rows,
   const size_type n_block_columns)
 {
-  // delete previous content and
-  // clean the sub_objects array
-  // completely
-  for (size_type i = 0; i < rows; ++i)
-    for (size_type j = 0; j < columns; ++j)
-      {
-        SparsityPatternType *sp = sub_objects[i][j];
-        sub_objects[i][j]       = nullptr;
-        delete sp;
-      }
   sub_objects.reinit(0, 0);
 
-  // then set new sizes
   rows    = n_block_rows;
   columns = n_block_columns;
-  sub_objects.reinit(rows, columns);
 
-  // allocate new objects
+  sub_objects.reinit(rows, columns);
   for (size_type i = 0; i < rows; ++i)
     for (size_type j = 0; j < columns; ++j)
-      {
-        SparsityPatternType *p = new SparsityPatternType;
-        sub_objects[i][j]      = p;
-      }
+      sub_objects[i][j] = std::make_unique<SparsityPatternType>();
 }
 
 

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.