Reference documentation for deal.II version 9.1.0-pre
vector_slice.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 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_vector_slice_h
17 #define dealii_vector_slice_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/array_view.h>
22 #include <deal.II/base/exceptions.h>
23 
24 DEAL_II_NAMESPACE_OPEN
25 
26 
49 template <typename VectorType>
51 {
52 public:
59  VectorSlice(VectorType &v);
64  VectorSlice(VectorType &v, unsigned int start, unsigned int length);
65 
71 
77 
82  unsigned int
83  size() const;
84 
89  typename VectorType::reference operator[](unsigned int i);
90 
95  typename VectorType::const_reference operator[](unsigned int i) const;
96 
100  typename VectorType::iterator
101  begin();
102 
106  typename VectorType::const_iterator
107  begin() const;
108 
112  typename VectorType::iterator
113  end();
114 
118  typename VectorType::const_iterator
119  end() const;
120 
121 private:
125  VectorType &v;
129  const unsigned int start;
133  const unsigned int length;
134 };
135 
136 
144 template <typename VectorType>
146 make_slice(VectorType &v)
147 {
149  return r;
150 }
151 
152 
153 
161 template <typename VectorType>
163 make_slice(VectorType &v, const unsigned int start, const unsigned int length)
164 {
165  const VectorSlice<const VectorType> r(v, start, length);
166  return r;
167 }
168 
169 
170 
171 //---------------------------------------------------------------------------
172 
173 template <typename VectorType>
175  : v(v)
176  , start(0)
177  , length(v.size())
178 {}
179 
180 
181 template <typename VectorType>
183  unsigned int start,
184  unsigned int length)
185  : v(v)
186  , start(start)
187  , length(length)
188 {
189  Assert((start + length <= v.size()),
190  ExcIndexRange(length, 0, v.size() - start + 1));
191 }
192 
193 
194 template <typename VectorType>
195 inline unsigned int
197 {
198  return length;
199 }
200 
201 
202 template <typename VectorType>
204 {
206 }
207 
208 
209 template <typename VectorType>
212 {
214 }
215 
216 
217 template <typename VectorType>
218 inline typename VectorType::reference VectorSlice<VectorType>::
219  operator[](unsigned int i)
220 {
221  Assert((i < length), ExcIndexRange(i, 0, length));
222 
223  return v[start + i];
224 }
225 
226 
227 template <typename VectorType>
228 inline typename VectorType::const_reference VectorSlice<VectorType>::
229  operator[](unsigned int i) const
230 {
231  Assert((i < length), ExcIndexRange(i, 0, length));
232 
233  return v[start + i];
234 }
235 
236 
237 template <typename VectorType>
238 inline typename VectorType::const_iterator
240 {
241  return v.begin() + start;
242 }
243 
244 
245 template <typename VectorType>
246 inline typename VectorType::iterator
248 {
249  return v.begin() + start;
250 }
251 
252 
253 template <typename VectorType>
254 inline typename VectorType::const_iterator
256 {
257  return v.begin() + start + length;
258 }
259 
260 
261 template <typename VectorType>
262 inline typename VectorType::iterator
264 {
265  return v.begin() + start + length;
266 }
267 
268 DEAL_II_NAMESPACE_CLOSE
269 
270 #endif
VectorType::iterator begin()
Definition: vector_slice.h:247
static::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
const VectorSlice< const VectorType > make_slice(VectorType &v)
Definition: vector_slice.h:146
const unsigned int start
Definition: vector_slice.h:129
VectorType & v
Definition: vector_slice.h:125
#define Assert(cond, exc)
Definition: exceptions.h:1227
VectorType::reference operator[](unsigned int i)
Definition: vector_slice.h:219
unsigned int size() const
Definition: vector_slice.h:196
VectorType::iterator end()
Definition: vector_slice.h:263
const unsigned int length
Definition: vector_slice.h:133
VectorSlice(VectorType &v)
Definition: vector_slice.h:174
const VectorSlice< const VectorType > make_slice(VectorType &v, const unsigned int start, const unsigned int length)
Definition: vector_slice.h:163