Reference documentation for deal.II version 8.4.2
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 
131 template<typename Number>
132 class VectorView : public Vector<Number>
133 {
134 public:
135 
140 
146  VectorView(const size_type new_size, Number *ptr);
147 
158  VectorView(const size_type new_size, const Number *ptr);
159 
164  ~VectorView();
165 
206  virtual void reinit (const size_type N,
207  const bool omit_zeroing_entries=false);
208 
213  void reinit(const size_type N, Number *ptr);
214 
220  void reinit(const size_type N, const Number *ptr);
221 
226  virtual void swap (Vector<Number> &v);
227 };
228 
229 
230 
232 /*----------------------- Inline functions ----------------------------------*/
233 
234 #ifndef DOXYGEN
235 
236 template<typename Number>
237 inline
238 VectorView<Number>::VectorView(const size_type new_size, Number *ptr)
239 {
240  this->vec_size = new_size;
241  this->max_vec_size = new_size;
242  this->val = ptr;
243 }
244 
245 
246 
247 template<typename Number>
248 inline
249 VectorView<Number>::VectorView(const size_type new_size, const Number *ptr)
250 {
251  this->vec_size = new_size;
252  this->max_vec_size = new_size;
253  this->val = const_cast<Number *>(ptr);
254 }
255 
256 
257 
258 template<typename Number>
259 inline
261 {
262  // avoid that the base class releases
263  // memory it doesn't own
264  this->vec_size = 0;
265  this->max_vec_size = 0;
266  this->val = 0;
267 }
268 
269 
270 template<typename Number>
271 inline
272 void VectorView<Number>::reinit(const size_type N,
273  const bool omit_zeroing_entries)
274 {
275  this->vec_size = N;
276  this->max_vec_size = N;
277  if (omit_zeroing_entries == false)
278  Vector<Number>::operator=(static_cast<Number>(0));
279 }
280 
281 
282 template<typename Number>
283 inline
284 void VectorView<Number>::reinit(const size_type new_size, Number *ptr)
285 {
286  this->vec_size = new_size;
287  this->max_vec_size = new_size;
288  this->val = ptr;
289 }
290 
291 
292 template<typename Number>
293 inline
294 void VectorView<Number>::reinit(const size_type new_size, const Number *ptr)
295 {
296  this->vec_size = new_size;
297  this->max_vec_size = new_size;
298  this->val = const_cast<Number *>(ptr);
299 }
300 
301 
302 template<typename Number>
303 inline
305 {
306  AssertThrow(false, ExcMessage("Cant' swap a VectorView with a Vector!"));
307 }
308 
309 #endif
310 
311 DEAL_II_NAMESPACE_CLOSE
312 
313 #endif
::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Definition: exceptions.h:358
Vector< Number > & operator=(const Number s)
size_type max_vec_size
Definition: vector.h:979
unsigned int global_dof_index
Definition: types.h:88
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
size_type vec_size
Definition: vector.h:971
Number * val
Definition: vector.h:984
types::global_dof_index size_type
Definition: vector_view.h:139
VectorView(const size_type new_size, Number *ptr)
virtual void swap(Vector< Number > &v)