Reference documentation for deal.II version 9.0.0
vector_view.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2009 - 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 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 
132 template <typename Number>
133 class DEAL_II_DEPRECATED VectorView : public Vector<Number>
134 {
135 public:
136 
141 
147  VectorView(const size_type new_size, Number *ptr);
148 
159  VectorView(const size_type new_size, const Number *ptr);
160 
165  ~VectorView();
166 
207  virtual void reinit (const size_type N,
208  const bool omit_zeroing_entries=false);
209 
214  void reinit(const size_type N, Number *ptr);
215 
221  void reinit(const size_type N, const Number *ptr);
222 
227  virtual void swap (Vector<Number> &v);
228 };
229 
230 
231 
233 /*----------------------- Inline functions ----------------------------------*/
234 
235 #ifndef DOXYGEN
236 
237 template <typename Number>
238 inline
239 VectorView<Number>::VectorView(const size_type new_size, Number *ptr)
240 {
241  this->vec_size = new_size;
242  this->max_vec_size = new_size;
243  // release the pointer, but do not delete the object pointed to
244  this->values.release();
245  this->values.reset (ptr);
246 }
247 
248 
249 
250 template <typename Number>
251 inline
252 VectorView<Number>::VectorView(const size_type new_size, const Number *ptr)
253 {
254  this->vec_size = new_size;
255  this->max_vec_size = new_size;
256  this->values.reset (const_cast<Number *>(ptr));
257 }
258 
259 
260 
261 template <typename Number>
262 inline
264 {
265  // avoid that the base class releases
266  // memory it doesn't own
267  this->vec_size = 0;
268  this->max_vec_size = 0;
269 
270  // release the pointer, but do not delete the object pointed to
271  this->values.release();
272 }
273 
274 
275 template <typename Number>
276 inline
277 void VectorView<Number>::reinit(const size_type N,
278  const bool omit_zeroing_entries)
279 {
280  this->vec_size = N;
281  this->max_vec_size = N;
282  if (omit_zeroing_entries == false)
283  Vector<Number>::operator=(static_cast<Number>(0));
284 }
285 
286 
287 template <typename Number>
288 inline
289 void VectorView<Number>::reinit(const size_type new_size, Number *ptr)
290 {
291  this->vec_size = new_size;
292  this->max_vec_size = new_size;
293  // release the pointer, but do not delete the object pointed to
294  this->values.release();
295  this->values.reset (ptr);
296 }
297 
298 
299 template <typename Number>
300 inline
301 void VectorView<Number>::reinit(const size_type new_size, const Number *ptr)
302 {
303  this->vec_size = new_size;
304  this->max_vec_size = new_size;
305  // release the pointer, but do not delete the object pointed to
306  this->values.release();
307  this->values.reset (const_cast<Number *>(ptr));
308 }
309 
310 
311 template <typename Number>
312 inline
313 void VectorView<Number>::swap(Vector<Number> &)
314 {
315  AssertThrow(false, ExcMessage("Can't swap a VectorView with a Vector!"));
316 }
317 
318 #endif
319 
320 DEAL_II_NAMESPACE_CLOSE
321 
322 #endif
#define AssertThrow(cond, exc)
Definition: exceptions.h:1221
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)
void swap(Vector< Number > &u, Vector< Number > &v)
Definition: vector.h:1312
types::global_dof_index size_type
Definition: vector_view.h:140
VectorView(const size_type new_size, Number *ptr)
virtual void swap(Vector< Number > &v)