]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add a bunch of functions to the iterator class.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 7 Jan 2013 04:34:50 +0000 (04:34 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 7 Jan 2013 04:34:50 +0000 (04:34 +0000)
git-svn-id: https://svn.dealii.org/trunk@27955 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/sparse_matrix.h

index 7b150ae63886dfa40c0f4ba1c1be06e77d6c5a29..f787951f9eab7cc00f5ddef90e9a0eac1b795b87 100644 (file)
@@ -296,6 +296,13 @@ namespace SparseMatrixIterators
     typename Accessor<number,Constness>::MatrixType
     MatrixType;
 
+    /**
+     * A typedef for the type you get when you dereference an iterator
+     * of the current kind.
+     */
+    typedef
+    const Accessor<number,Constness> & value_type;
+
     /**
      * Constructor. Create an iterator into the matrix @p matrix for the given
      * row and the index within it.
@@ -360,6 +367,19 @@ namespace SparseMatrixIterators
      */
     bool operator > (const Iterator &) const;
 
+    /**
+     * Return the distance between the current iterator and the argument.
+     * The distance is given by how many times one has to apply operator++
+     * to the current iterator to get the argument (for a positive return
+     * value), or operator-- (for a negative return value).
+     */
+    int operator - (const Iterator &p) const;
+
+    /**
+     * Return an iterator that is @p n ahead of the current one.
+     */
+    Iterator operator + (const unsigned int n) const;
+
   private:
     /**
      * Store an object of the accessor class.
@@ -2206,6 +2226,44 @@ namespace SparseMatrixIterators
     return (other < *this);
   }
 
+
+  template <typename number, bool Constness>
+  inline
+  int
+  Iterator<number,Constness>::
+  operator - (const Iterator &other) const
+  {
+    Assert (&accessor.get_matrix() == &other.accessor.get_matrix(),
+            ExcInternalError());
+
+    if ((*this)->row() == other->row())
+      return ((*this)->index() - other->index());
+    else
+      {
+//TODO: this shouldn't be so hard to implement. it could either be done as
+// std::difference(*this, other), but for that we lack a bunch of typedefs
+// in the iterator class; it is also inefficient since it has linear complexity
+// in the distance. alternatively, one should be able to just add up the
+// entries in all of the rows of the matrix between *this and other
+        Assert (false, ExcNotImplemented());
+        return 0;
+      }
+  }
+
+
+  template <typename number, bool Constness>
+  inline
+  Iterator<number,Constness>
+  Iterator<number,Constness>::
+  operator + (const unsigned int n) const
+  {
+    Iterator x = *this;
+    for (unsigned int i=0; i<n; ++i)
+      ++x;
+
+    return x;
+  }
+
 }
 
 

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.