Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
matrix_iterator.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_matrix_iterator_h
17 #define dealii_matrix_iterator_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #include <deal.II/base/exceptions.h>
23 
24 DEAL_II_NAMESPACE_OPEN
25 
34 template <class ACCESSOR>
35 class MatrixIterator
36 {
37 public:
42 
46  using MatrixType = typename ACCESSOR::MatrixType;
47 
52  MatrixIterator(MatrixType * matrix,
53  const size_type row = 0,
54  const size_type index = 0);
55 
62  template <class OtherAccessor>
64 
69  operator++();
70 
75  operator++(int);
76 
80  const ACCESSOR &operator*() const;
81 
85  const ACCESSOR *operator->() const;
86 
90  bool
91  operator==(const MatrixIterator &) const;
92 
96  bool
97  operator!=(const MatrixIterator &) const;
98 
105  bool
106  operator<(const MatrixIterator &) const;
107 
112  bool
113  operator>(const MatrixIterator &) const;
114 
115 private:
119  ACCESSOR accessor;
120 
124  template <class OtherAccessor>
125  friend class MatrixIterator;
126 };
127 
128 
129 //----------------------------------------------------------------------//
130 
131 template <class ACCESSOR>
133  const size_type r,
134  const size_type i)
135  : accessor(matrix, r, i)
136 {}
137 
138 
139 template <class ACCESSOR>
140 template <class OtherAccessor>
142  const MatrixIterator<OtherAccessor> &other)
143  : accessor(other.accessor)
144 {}
145 
146 
147 template <class ACCESSOR>
150 {
151  accessor.advance();
152  return *this;
153 }
154 
155 
156 template <class ACCESSOR>
159 {
160  const MatrixIterator iter = *this;
161  accessor.advance();
162  return iter;
163 }
164 
165 
166 template <class ACCESSOR>
167 inline const ACCESSOR &MatrixIterator<ACCESSOR>::operator*() const
168 {
169  return accessor;
170 }
171 
172 
173 template <class ACCESSOR>
174 inline const ACCESSOR *MatrixIterator<ACCESSOR>::operator->() const
175 {
176  return &accessor;
177 }
178 
179 
180 template <class ACCESSOR>
181 inline bool
183 {
184  return (accessor == other.accessor);
185 }
186 
187 
188 template <class ACCESSOR>
189 inline bool
191 {
192  return !(*this == other);
193 }
194 
195 
196 template <class ACCESSOR>
197 inline bool
199 {
200  Assert(&accessor.get_matrix() == &other.accessor.get_matrix(),
201  ExcInternalError());
202 
203  return (accessor < other.accessor);
204 }
205 
206 
207 template <class ACCESSOR>
208 inline bool
210 {
211  return (other < *this);
212 }
213 
214 DEAL_II_NAMESPACE_CLOSE
215 
216 #endif
bool operator<(const MatrixIterator &) const
bool operator!=(const MatrixIterator &) const
typename ACCESSOR::MatrixType MatrixType
friend class MatrixIterator
const ACCESSOR & operator*() const
#define Assert(cond, exc)
Definition: exceptions.h:1407
MatrixIterator & operator++()
types::global_dof_index size_type
unsigned int global_dof_index
Definition: types.h:89
bool operator>(const MatrixIterator &) const
const ACCESSOR * operator->() const
bool operator==(const MatrixIterator &) const
static ::ExceptionBase & ExcInternalError()