Reference documentation for deal.II version 8.5.1
vector_view.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2009 - 2016 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__vector_view_h
17 #define dealii__vector_view_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/subscriptor.h>
23 #include <deal.II/lac/vector.h>
24 
25 #include <cstdio>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 
130 template<typename Number>
131 class VectorView : public Vector<Number>
132 {
133 public:
134 
139 
145  VectorView(const size_type new_size, Number *ptr);
146 
157  VectorView(const size_type new_size, const Number *ptr);
158 
163  ~VectorView();
164 
205  virtual void reinit (const size_type N,
206  const bool omit_zeroing_entries=false);
207 
212  void reinit(const size_type N, Number *ptr);
213 
219  void reinit(const size_type N, const Number *ptr);
220 
225  virtual void swap (Vector<Number> &v);
226 };
227 
228 
229 
231 /*----------------------- Inline functions ----------------------------------*/
232 
233 #ifndef DOXYGEN
234 
235 template<typename Number>
236 inline
237 VectorView<Number>::VectorView(const size_type new_size, Number *ptr)
238 {
239  this->vec_size = new_size;
240  this->max_vec_size = new_size;
241  this->val = ptr;
242 }
243 
244 
245 
246 template<typename Number>
247 inline
248 VectorView<Number>::VectorView(const size_type new_size, const Number *ptr)
249 {
250  this->vec_size = new_size;
251  this->max_vec_size = new_size;
252  this->val = const_cast<Number *>(ptr);
253 }
254 
255 
256 
257 template<typename Number>
258 inline
260 {
261  // avoid that the base class releases
262  // memory it doesn't own
263  this->vec_size = 0;
264  this->max_vec_size = 0;
265  this->val = 0;
266 }
267 
268 
269 template<typename Number>
270 inline
271 void VectorView<Number>::reinit(const size_type N,
272  const bool omit_zeroing_entries)
273 {
274  this->vec_size = N;
275  this->max_vec_size = N;
276  if (omit_zeroing_entries == false)
277  Vector<Number>::operator=(static_cast<Number>(0));
278 }
279 
280 
281 template<typename Number>
282 inline
283 void VectorView<Number>::reinit(const size_type new_size, Number *ptr)
284 {
285  this->vec_size = new_size;
286  this->max_vec_size = new_size;
287  this->val = ptr;
288 }
289 
290 
291 template<typename Number>
292 inline
293 void VectorView<Number>::reinit(const size_type new_size, const Number *ptr)
294 {
295  this->vec_size = new_size;
296  this->max_vec_size = new_size;
297  this->val = const_cast<Number *>(ptr);
298 }
299 
300 
301 template<typename Number>
302 inline
304 {
305  AssertThrow(false, ExcMessage("Cant' swap a VectorView with a Vector!"));
306 }
307 
308 #endif
309 
310 DEAL_II_NAMESPACE_CLOSE
311 
312 #endif
#define AssertThrow(cond, exc)
Definition: exceptions.h:369
Vector< Number > & operator=(const Number s)
static ::ExceptionBase & ExcMessage(std::string arg1)
unsigned int global_dof_index
Definition: types.h:88
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
types::global_dof_index size_type
Definition: vector_view.h:138
VectorView(const size_type new_size, Number *ptr)
virtual void swap(Vector< Number > &v)