]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Rename the Table::clear function to Table::reset_entries to make its intent clearer.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 12 May 2004 15:05:22 +0000 (15:05 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 12 May 2004 15:05:22 +0000 (15:05 +0000)
git-svn-id: https://svn.dealii.org/trunk@9238 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/table.h
deal.II/lac/include/lac/block_sparse_matrix.templates.h
deal.II/lac/include/lac/full_matrix.h
deal.II/lac/source/block_sparsity_pattern.cc

index eb4ae087e0bac27b71c7d2b94469ed4a1ff0cb49..b1a17c19cf670e7dfe88ed07700ee113108f736d 100644 (file)
@@ -773,9 +773,10 @@ class TableBase : public Subscriptor
                                       * Set all entries to their
                                       * default value (i.e. copy them
                                       * over with default constructed
-                                      * objects).
+                                      * objects). Do not change the
+                                      * size of the table, though.
                                       */
-    void clear ();
+    void reset_values ();
     
                                      /**
                                       * Set the dimensions of this
@@ -1960,7 +1961,7 @@ TableBase<N,T>::operator = (const TableBase<N,T2>& m)
 template <int N, typename T>
 inline
 void
-TableBase<N,T>::clear ()
+TableBase<N,T>::reset_values ()
 {
   if (n_elements() != 0)
     std::fill_n (val, n_elements(), T());
@@ -1993,7 +1994,7 @@ TableBase<N,T>::reinit (const TableIndices<N> &new_sizes)
       table_size = TableIndices<N>();
 
       return;
-    };
+    }
   
                                    // if new size is nonzero:
                                    // if necessary allocate
@@ -2005,11 +2006,23 @@ TableBase<N,T>::reinit (const TableIndices<N> &new_sizes)
 
       val_size = new_size;
       val      = new T[val_size];
-    };
+    }
 
                                    // reinitialize contents of old or
-                                   // new memory.
-  clear ();
+                                   // new memory. note that we
+                                   // actually need to do this here,
+                                   // even in the case that we
+                                   // reallocated memory, since per
+                                   // C++ standard, clause 5.3.4/15
+                                   // the newly allocated objects are
+                                   // only default initialized by
+                                   // operator new[] if they are
+                                   // non-POD type. In other words, if
+                                   // we have a table of doubles, then
+                                   // their values after calling 'new
+                                   // double[val_size]' is
+                                   // indetermined.
+  reset_values ();
 }
 
 
index 73b80067ac2cb47a692a129b1a0e0de34cf71a87..50bec5d1aab5a3ef28be383f447c97bbc47c7a9a 100644 (file)
@@ -95,7 +95,8 @@ BlockSparseMatrix<number>::
 reinit (const BlockSparsityPattern &sparsity)
 {
                                   // first delete previous content of
-                                  // the subobjects array
+                                  // the subobjects array and delete
+                                  // the table completely
   for (unsigned int r=0; r<rows; ++r)
     for (unsigned int c=0; c<columns; ++c)
       {
@@ -103,8 +104,7 @@ reinit (const BlockSparsityPattern &sparsity)
        sub_objects[r][c] = 0;
        delete p;
       }
-  
-  sub_objects.clear ();
+  sub_objects.reinit (0,0);
 
                                   // then associate new sparsity
                                   // pattern and resize
index dd44ad0256fbb98e025f41954d84cb9215c98d38..9647287bad05b4f9ade4ef1a254331f3914692ab 100644 (file)
@@ -983,9 +983,6 @@ class FullMatrix : public Table<2,number>
     DeclException0 (ExcSourceEqualsDestination);
 
     friend class Accessor;
-
-  private:
-    void clear ();
 };
 
 /*@}*/
index 092d1ca3c58aa067819a229052527c2b211df609..18667288b2d789c69f852761ad838ab8f4fa17ec 100644 (file)
@@ -68,7 +68,9 @@ BlockSparsityPatternBase<SparsityPatternBase>::
 reinit (const unsigned int n_block_rows,
         const unsigned int n_block_columns)
 {
-                                  // delete previous content
+                                  // delete previous content and
+                                  // clean the sub_objects array
+                                  // completely
   for (unsigned int i=0; i<rows; ++i)
     for (unsigned int j=0; j<columns; ++j)
       {
@@ -76,9 +78,9 @@ reinit (const unsigned int n_block_rows,
        sub_objects[i][j] = 0;
        delete sp;
       };
-  sub_objects.clear ();
+  sub_objects.reinit (0,0);
 
-                                  // set new sizes
+                                  // then set new sizes
   rows = n_block_rows;
   columns = n_block_columns;
   sub_objects.reinit (rows, columns);

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.