From 35afbcd9707b1bdaace55b78dc211840ff0b962e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 3 May 2004 15:24:36 +0000 Subject: [PATCH] Templatize iterators on matrix instead of number type. git-svn-id: https://svn.dealii.org/trunk@9147 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/block_sparse_matrix.h | 144 +++++++++--------- 1 file changed, 74 insertions(+), 70 deletions(-) diff --git a/deal.II/lac/include/lac/block_sparse_matrix.h b/deal.II/lac/include/lac/block_sparse_matrix.h index 5547148f01..5e86624ae0 100644 --- a/deal.II/lac/include/lac/block_sparse_matrix.h +++ b/deal.II/lac/include/lac/block_sparse_matrix.h @@ -46,7 +46,7 @@ namespace internal /** * Accessor class for iterators */ - template + template class Accessor { public: @@ -54,9 +54,7 @@ namespace internal * Typedef the value type of the * matrix we point into. */ - typedef - typename BlockSparseMatrix::value_type - value_type; + typedef typename BlockMatrix::value_type value_type; /** * Constructor. Since we use @@ -64,9 +62,9 @@ namespace internal * access, a const matrix * pointer is sufficient. */ - Accessor (const BlockSparseMatrix *m, - const unsigned int row, - const unsigned int index); + Accessor (const BlockMatrix *m, + const unsigned int row, + const unsigned int index); /** * Row number of the element @@ -112,15 +110,13 @@ namespace internal /** * The matrix accessed. */ - const BlockSparseMatrix* matrix; + const BlockMatrix * matrix; /** * Iterator of the underlying matrix * class. */ - typename - BlockSparseMatrix::BlockType::const_iterator - base_iterator; + typename BlockMatrix::BlockType::const_iterator base_iterator; /** * Number of block where row lies in. @@ -159,16 +155,16 @@ namespace internal /** * STL conforming iterator. */ - template - class ConstIterator : private Accessor + template + class ConstIterator : private Accessor { public: /** * Constructor. */ - ConstIterator(const BlockSparseMatrix*, - const unsigned int row, - const unsigned int index); + ConstIterator(const BlockMatrix *matrix, + const unsigned int row, + const unsigned int index); /** * Prefix increment. @@ -183,12 +179,12 @@ namespace internal /** * Dereferencing operator. */ - const Accessor & operator* () const; + const Accessor & operator* () const; /** * Dereferencing operator. */ - const Accessor * operator-> () const; + const Accessor * operator-> () const; /** * Comparison. True, if @@ -267,12 +263,19 @@ class BlockSparseMatrix : public Subscriptor typedef typename BlockType::value_type value_type; typedef value_type *pointer; typedef const value_type *const_pointer; - typedef internal::BlockMatrixIterators::ConstIterator iterator; - typedef internal::BlockMatrixIterators::ConstIterator const_iterator; typedef value_type &reference; typedef const value_type &const_reference; typedef size_t size_type; + typedef + internal::BlockMatrixIterators::ConstIterator + iterator; + + typedef + internal::BlockMatrixIterators::ConstIterator + const_iterator; + + /** * Constructor; initializes the * matrix to be empty, without @@ -478,6 +481,18 @@ class BlockSparseMatrix : public Subscriptor const unsigned int j, const number value); + /** + * Add value to the element + * (i,j). Throws an error if + * the entry does not + * exist. Still, it is allowed to + * store zero values in + * non-existent fields. + */ + void add (const unsigned int i, + const unsigned int j, + const number value); + /** * Multiply the entire matrix by a * fixed factor. @@ -490,17 +505,6 @@ class BlockSparseMatrix : public Subscriptor */ BlockSparseMatrix & operator /= (const number factor); - /** - * Add value to the element - * (i,j). Throws an error if - * the entry does not - * exist. Still, it is allowed to - * store zero values in - * non-existent fields. - */ - void add (const unsigned int i, const unsigned int j, - const number value); - /** * Copy the given matrix to this * one. The operation throws an @@ -945,7 +949,7 @@ class BlockSparseMatrix : public Subscriptor template friend class internal::BlockMatrixIterators::ConstIterator; #else - typedef internal::BlockMatrixIterators::Accessor Accessor; + typedef internal::BlockMatrixIterators::Accessor Accessor; friend class Accessor; friend class const_iterator; @@ -962,12 +966,12 @@ namespace internal { namespace BlockMatrixIterators { - template + template inline - Accessor:: - Accessor (const BlockSparseMatrix *matrix, - const unsigned int r, - const unsigned int i) + Accessor:: + Accessor (const BlockMatrix *matrix, + const unsigned int r, + const unsigned int i) : matrix(matrix), base_iterator(matrix->block(0,0).begin()), @@ -996,55 +1000,55 @@ namespace internal } - template + template inline unsigned int - Accessor::row() const + Accessor::row() const { return row_start + base_iterator->row(); } - template + template inline unsigned int - Accessor::index() const + Accessor::index() const { return a_index; } - template + template inline unsigned int - Accessor::column() const + Accessor::column() const { return col_start + base_iterator->column(); } - template + template inline unsigned int - Accessor::block_row() const + Accessor::block_row() const { return row_block; } - template + template inline unsigned int - Accessor::block_column() const + Accessor::block_column() const { return col_block; } - template + template inline - typename Accessor::value_type - Accessor::value () const + typename Accessor::value_type + Accessor::value () const { return base_iterator->value(); } @@ -1053,22 +1057,22 @@ namespace internal //----------------------------------------------------------------------// - template + template inline - ConstIterator:: - ConstIterator (const BlockSparseMatrix* m, + ConstIterator:: + ConstIterator (const BlockMatrix *m, const unsigned int r, const unsigned int i) : - Accessor(m, r, i) + Accessor(m, r, i) {} - template + template inline - ConstIterator & - ConstIterator::operator++ () + ConstIterator & + ConstIterator::operator++ () { Assert (this->row_blockmatrix->n_block_rows(), ExcIteratorPastEnd()); @@ -1131,7 +1135,7 @@ namespace internal -// template +// template // inline // const_iterator& // ConstIterator::operator++ (int) @@ -1142,29 +1146,29 @@ namespace internal - template + template inline - const Accessor & - ConstIterator::operator* () const + const Accessor & + ConstIterator::operator* () const { return *this; } - template + template inline - const Accessor * - ConstIterator::operator-> () const + const Accessor * + ConstIterator::operator-> () const { return this; } - template + template inline bool - ConstIterator:: + ConstIterator:: operator == (const ConstIterator& i) const { if (this->matrix != i->matrix) @@ -1179,10 +1183,10 @@ namespace internal - template + template inline bool - ConstIterator:: + ConstIterator:: operator != (const ConstIterator& i) const { return !(*this == i); @@ -1190,10 +1194,10 @@ namespace internal - template + template inline bool - ConstIterator:: + ConstIterator:: operator < (const ConstIterator& i) const { if (this->row_block < i->row_block) -- 2.39.5