]> https://gitweb.dealii.org/ - dealii.git/commitdiff
make the conversion from from Accessor to TriaIterators explicit
authorTimo Heister <timo.heister@gmail.com>
Wed, 17 Jul 2013 20:58:49 +0000 (20:58 +0000)
committerTimo Heister <timo.heister@gmail.com>
Wed, 17 Jul 2013 20:58:49 +0000 (20:58 +0000)
git-svn-id: https://svn.dealii.org/trunk@30027 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/grid/tria_iterator.h
deal.II/source/dofs/dof_renumbering.cc

index eb97f7f5ee94c6e22807fe85016cadde263eaaf2..05cf132def7cefd01acab09bdf8839fd2e22bfa8 100644 (file)
@@ -264,7 +264,7 @@ public:
    *   = accessor;
    * @endcode
    */
-  TriaRawIterator (const Accessor &a);
+  explicit TriaRawIterator (const Accessor &a);
 
   /**
    * Constructor. Assumes that the
@@ -273,7 +273,7 @@ public:
    * one.
    */
   template <typename OtherAccessor>
-  TriaRawIterator (const OtherAccessor &a);
+  explicit TriaRawIterator (const OtherAccessor &a);
 
   /**
    *  Proper constructor, initialized
@@ -685,6 +685,13 @@ public:
                 const int                 index,
                 const typename Accessor::AccessorData *local_data = 0);
 
+  /**
+   * Construct from an accessor of type OtherAccessor that is convertible
+   * to the type Accessor.
+   */
+  template <typename OtherAccessor>
+  explicit TriaIterator (const OtherAccessor &a);
+
   /**
    * This is a conversion operator
    * (constructor) which takes another
@@ -1278,7 +1285,24 @@ TriaIterator<Accessor>::TriaIterator (const TriaRawIterator<OtherAccessor> &i)
 #endif
 }
 
-
+template <typename Accessor>
+template <typename OtherAccessor>
+TriaIterator<Accessor>::TriaIterator (const OtherAccessor &a)
+:
+TriaRawIterator<Accessor> (a)
+{
+#ifdef DEBUG
+  // do this like this, because:
+  // if we write
+  // "Assert (IteratorState::past_the_end || used)"
+  // used() is called anyway, even if
+  // state==IteratorState::past_the_end, and will then
+  // throw the exception!
+  if (this->state() != IteratorState::past_the_end)
+    Assert (this->accessor.used(),
+            ExcAssignmentOfUnusedObject());
+#endif
+}
 
 template <typename Accessor>
 template <typename OtherAccessor>
index 9b89bd44663dd12816fc8a122eb632b2f352c6b4..755104f0aa60a60e38fdcaaeafc6694f5bc2f1d1 100644 (file)
@@ -1552,14 +1552,18 @@ namespace DoFRenumbering
   {
     if (dof_wise_renumbering == false)
       {
-        std::vector<typename DH::active_cell_iterator>
-        ordered_cells(dof.get_tria().n_active_cells());
+        std::vector<typename DH::active_cell_iterator> ordered_cells;
+        ordered_cells.reserve(dof.get_tria().n_active_cells());
         const CompareDownstream<typename DH::active_cell_iterator, DH::space_dimension> comparator(direction);
 
-        typename DH::active_cell_iterator begin = dof.begin_active();
+        typename DH::active_cell_iterator p = dof.begin_active();
         typename DH::active_cell_iterator end = dof.end();
 
-        std::copy (begin, end, ordered_cells.begin());
+        while (p!=end)
+          {
+            ordered_cells.push_back(p);
+            ++p;
+          }
         std::sort (ordered_cells.begin(), ordered_cells.end(), comparator);
 
         compute_cell_wise(new_indices, reverse, dof, ordered_cells);
@@ -1655,14 +1659,18 @@ namespace DoFRenumbering
   {
     if (dof_wise_renumbering == false)
       {
-        std::vector<typename DH::level_cell_iterator>
-        ordered_cells(dof.get_tria().n_cells(level));
+        std::vector<typename DH::level_cell_iterator> ordered_cells;
+        ordered_cells.reserve (dof.get_tria().n_cells(level));
         const CompareDownstream<typename DH::level_cell_iterator, DH::space_dimension> comparator(direction);
 
-        typename DH::level_cell_iterator begin = dof.begin(level);
+        typename DH::level_cell_iterator p = dof.begin(level);
         typename DH::level_cell_iterator end = dof.end(level);
 
-        std::copy (begin, end, ordered_cells.begin());
+        while (p!=end)
+          {
+            ordered_cells.push_back(p);
+            ++p;
+          }
         std::sort (ordered_cells.begin(), ordered_cells.end(), comparator);
 
         compute_cell_wise(new_indices, reverse, dof, level, ordered_cells);
@@ -1808,14 +1816,18 @@ namespace DoFRenumbering
     const Point<DH::space_dimension> &center,
     const bool counter)
   {
-    std::vector<typename DH::active_cell_iterator>
-    ordered_cells(dof.get_tria().n_active_cells());
+    std::vector<typename DH::active_cell_iterator> ordered_cells;
+    ordered_cells.reserve (dof.get_tria().n_active_cells());
     internal::ClockCells<DH::space_dimension> comparator(center, counter);
 
-    typename DH::active_cell_iterator begin = dof.begin_active();
+    typename DH::active_cell_iterator p = dof.begin_active();
     typename DH::active_cell_iterator end = dof.end();
 
-    std::copy (begin, end, ordered_cells.begin());
+    while (p!=end)
+      {
+        ordered_cells.push_back(p);
+        ++p;
+      }
     std::sort (ordered_cells.begin(), ordered_cells.end(), comparator);
 
     std::vector<types::global_dof_index> reverse(new_indices.size());
@@ -1830,14 +1842,18 @@ namespace DoFRenumbering
                      const Point<DH::space_dimension> &center,
                      const bool counter)
   {
-    std::vector<typename DH::level_cell_iterator>
-    ordered_cells(dof.get_tria().n_cells(level));
+    std::vector<typename DH::level_cell_iterator> ordered_cells;
+    ordered_cells.reserve(dof.get_tria().n_active_cells());
     internal::ClockCells<DH::space_dimension> comparator(center, counter);
 
-    typename DH::level_cell_iterator begin = dof.begin(level);
+    typename DH::level_cell_iterator p = dof.begin(level);
     typename DH::level_cell_iterator end = dof.end(level);
 
-    std::copy (begin, end, ordered_cells.begin());
+    while (p!=end)
+      {
+        ordered_cells.push_back(p);
+        ++p;
+      }
     std::sort (ordered_cells.begin(), ordered_cells.end(), comparator);
 
     cell_wise(dof, level, ordered_cells);

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.