From: wolf Date: Mon, 29 Mar 2004 16:57:16 +0000 (+0000) Subject: Rearrange classes so that they can be factored out more simply later on. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1684c925c79dc439fd58ce3238b4e7c0ef1df316;p=dealii-svn.git Rearrange classes so that they can be factored out more simply later on. git-svn-id: https://svn.dealii.org/trunk@8888 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 56d00d0106..6940caf632 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -27,93 +27,88 @@ template class FullMatrix; *@{ */ -/** - * Sparse matrix. This class implements the function to store values in the - * locations of a sparse matrix denoted by a @ref SparsityPattern. The - * separation of sparsity pattern and values is done since one can store data - * elements of different type in these locations without the SparsityPattern - * having to know this, and more importantly one can associate more than one - * matrix with the same sparsity pattern. - * - * @ref Instantiations some - - * @author several, 1994-2003 - */ -template -class SparseMatrix : public virtual Subscriptor + +namespace internals { - public: - /** - * STL conforming iterator. - */ - class const_iterator + namespace SparseMatrixIterators + { + // forward declaration + template class const_iterator; + + + /** + * Accessor class for iterators. + */ + template + class Accessor { - private: + public: /** - * Accessor class for iterators + * Constructor. Since we use + * accessors only for read + * access, a const matrix + * pointer is sufficient. */ - class Accessor - { - public: - /** - * Constructor. Since we use - * accessors only for read - * access, a const matrix - * pointer is sufficient. - */ - Accessor (const SparseMatrix *matrix, - const unsigned int row, - const unsigned int index); - - /** - * Row number of the element - * represented by this - * object. - */ - unsigned int row() const; - - /** - * Index in row of the element - * represented by this - * object. - */ - unsigned int index() const; - - /** - * Column number of the - * element represented by - * this object. - */ - unsigned int column() const; - - /** - * Value of this matrix entry. - */ - number value() const; + Accessor (const SparseMatrix *matrix, + const unsigned int row, + const unsigned int index); + + /** + * Row number of the element + * represented by this + * object. + */ + unsigned int row() const; + + /** + * Index in row of the element + * represented by this + * object. + */ + unsigned int index() const; + + /** + * Column number of the + * element represented by + * this object. + */ + unsigned int column() const; + + /** + * Value of this matrix entry. + */ + number value() const; - protected: - /** - * The matrix accessed. - */ - const SparseMatrix* matrix; - - /** - * Current row number. - */ - unsigned int a_row; - - /** - * Current index in row. - */ - unsigned int a_index; - - /** - * Make enclosing class a - * friend. - */ - friend class const_iterator; - }; - + protected: + /** + * The matrix accessed. + */ + const SparseMatrix * matrix; + + /** + * Current row number. + */ + unsigned int a_row; + + /** + * Current index in row. + */ + unsigned int a_index; + + /** + * Make enclosing class a + * friend. + */ + template + friend class internals::SparseMatrixIterators::const_iterator; + }; + + /** + * STL conforming iterator. + */ + template + class const_iterator + { public: /** * Constructor. Create an iterator @@ -137,12 +132,12 @@ class SparseMatrix : public virtual Subscriptor /** * Dereferencing operator. */ - const Accessor& operator* () const; + const Accessor & operator* () const; /** * Dereferencing operator. */ - const Accessor* operator-> () const; + const Accessor * operator-> () const; /** * Comparison. True, if @@ -173,14 +168,43 @@ class SparseMatrix : public virtual Subscriptor * Store an object of the * accessor class. */ - Accessor accessor; + Accessor accessor; }; + } +} + + +/** + * Sparse matrix. This class implements the function to store values in the + * locations of a sparse matrix denoted by a @ref SparsityPattern. The + * separation of sparsity pattern and values is done since one can store data + * elements of different type in these locations without the SparsityPattern + * having to know this, and more importantly one can associate more than one + * matrix with the same sparsity pattern. + * + * @ref Instantiations some + + * @author several, 1994-2003 + */ +template +class SparseMatrix : public virtual Subscriptor +{ + public: /** * Type of matrix entries. In analogy to * the STL container classes. */ typedef number value_type; + + /** + * Typedef of an STL conforming iterator + * class walking over all the nonzero + * entries of this matrix. + */ + typedef + internals::SparseMatrixIterators::const_iterator + const_iterator; /** * Constructor; initializes the matrix to @@ -1512,154 +1536,163 @@ SparseMatrix::copy_from (const ForwardIterator begin, //----------------------------------------------------------------------// -template -inline -SparseMatrix::const_iterator::Accessor:: -Accessor (const SparseMatrix* matrix, - const unsigned int r, - const unsigned int i) - : - matrix(matrix), - a_row(r), - a_index(i) -{} - -template -inline -unsigned int -SparseMatrix::const_iterator::Accessor::row() const +namespace internals { - return a_row; -} + namespace SparseMatrixIterators + { + + template + inline + Accessor:: + Accessor (const SparseMatrix* matrix, + const unsigned int r, + const unsigned int i) + : + matrix(matrix), + a_row(r), + a_index(i) + {} + + + template + inline + unsigned int + Accessor::row() const + { + return a_row; + } -template -inline -unsigned int -SparseMatrix::const_iterator::Accessor::column() const -{ - const SparsityPattern& pat = matrix->get_sparsity_pattern(); - return pat.get_column_numbers()[pat.get_rowstart_indices()[a_row]+a_index]; -} + template + inline + unsigned int + Accessor::column() const + { + const SparsityPattern& pat = matrix->get_sparsity_pattern(); + return pat.get_column_numbers()[pat.get_rowstart_indices()[a_row]+a_index]; + } -template -inline -unsigned int -SparseMatrix::const_iterator::Accessor::index() const -{ - return a_index; -} + template + inline + unsigned int + Accessor::index() const + { + return a_index; + } -template -inline -number -SparseMatrix::const_iterator::Accessor::value() const -{ - return matrix->raw_entry(a_row, a_index); -} + template + inline + number + Accessor::value() const + { + return matrix->raw_entry(a_row, a_index); + } -template -inline -SparseMatrix::const_iterator:: -const_iterator(const SparseMatrix *matrix, - const unsigned int r, - const unsigned int i) - : - accessor(matrix, r, i) -{} + template + inline + const_iterator:: + const_iterator(const SparseMatrix *matrix, + const unsigned int r, + const unsigned int i) + : + accessor(matrix, r, i) + {} -template -inline -typename SparseMatrix::const_iterator & -SparseMatrix::const_iterator::operator++ () -{ - Assert (accessor.a_row < accessor.matrix->m(), ExcIteratorPastEnd()); - - ++accessor.a_index; - if (accessor.a_index >= - accessor.matrix->get_sparsity_pattern().row_length(accessor.a_row)) + template + inline + const_iterator & + const_iterator::operator++ () { - accessor.a_index = 0; - accessor.a_row++; + Assert (accessor.a_row < accessor.matrix->m(), ExcIteratorPastEnd()); + + ++accessor.a_index; + if (accessor.a_index >= + accessor.matrix->get_sparsity_pattern().row_length(accessor.a_row)) + { + accessor.a_index = 0; + accessor.a_row++; + } + return *this; } - return *this; -} -template -inline -typename SparseMatrix::const_iterator -SparseMatrix::const_iterator::operator++ (int) -{ - Assert (accessor.a_row < accessor.matrix->m(), ExcIteratorPastEnd()); + template + inline + const_iterator + const_iterator::operator++ (int) + { + Assert (accessor.a_row < accessor.matrix->m(), ExcIteratorPastEnd()); - typename SparseMatrix::const_iterator iter=*this; + const_iterator iter=*this; - ++accessor.a_index; - if (accessor.a_index >= - accessor.matrix->get_sparsity_pattern().row_length(accessor.a_row)) - { - accessor.a_index = 0; - accessor.a_row++; + ++accessor.a_index; + if (accessor.a_index >= + accessor.matrix->get_sparsity_pattern().row_length(accessor.a_row)) + { + accessor.a_index = 0; + accessor.a_row++; + } + return iter; } - return iter; -} -template -inline -const typename SparseMatrix::const_iterator::Accessor & -SparseMatrix::const_iterator::operator* () const -{ - return accessor; -} + template + inline + const Accessor & + const_iterator::operator* () const + { + return accessor; + } -template -inline -const typename SparseMatrix::const_iterator::Accessor * -SparseMatrix::const_iterator::operator-> () const -{ - return &accessor; -} + template + inline + const Accessor * + const_iterator::operator-> () const + { + return &accessor; + } -template -inline -bool -SparseMatrix::const_iterator:: -operator == (const const_iterator& other) const -{ - return (accessor.row() == other.accessor.row() && - accessor.index() == other.accessor.index()); -} + template + inline + bool + const_iterator:: + operator == (const const_iterator& other) const + { + return (accessor.row() == other.accessor.row() && + accessor.index() == other.accessor.index()); + } -template -inline -bool -SparseMatrix::const_iterator:: -operator != (const const_iterator& other) const -{ - return ! (*this == other); -} + template + inline + bool + const_iterator:: + operator != (const const_iterator& other) const + { + return ! (*this == other); + } -template -inline -bool -SparseMatrix::const_iterator:: -operator < (const const_iterator& other) const -{ - return (accessor.row() < other.accessor.row() || - (accessor.row() == other.accessor.row() && - accessor.index() < other.accessor.index())); + template + inline + bool + const_iterator:: + operator < (const const_iterator& other) const + { + return (accessor.row() < other.accessor.row() || + (accessor.row() == other.accessor.row() && + accessor.index() < other.accessor.index())); + } + + } }