From: bangerth Date: Mon, 7 Jan 2013 04:34:50 +0000 (+0000) Subject: Add a bunch of functions to the iterator class. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a869cfacd9e9cf11bcaddce126869fa48e48405f;p=dealii-svn.git Add a bunch of functions to the iterator class. git-svn-id: https://svn.dealii.org/trunk@27955 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/sparse_matrix.h b/deal.II/include/deal.II/lac/sparse_matrix.h index 7b150ae638..f787951f9e 100644 --- a/deal.II/include/deal.II/lac/sparse_matrix.h +++ b/deal.II/include/deal.II/lac/sparse_matrix.h @@ -296,6 +296,13 @@ namespace SparseMatrixIterators typename Accessor::MatrixType MatrixType; + /** + * A typedef for the type you get when you dereference an iterator + * of the current kind. + */ + typedef + const Accessor & 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 + inline + int + Iterator:: + 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 + inline + Iterator + Iterator:: + operator + (const unsigned int n) const + { + Iterator x = *this; + for (unsigned int i=0; i