yat  0.21pre
Vector.h
1 #ifndef _theplu_yat_utility_vector_
2 #define _theplu_yat_utility_vector_
3 
4 // $Id: Vector.h 3938 2020-07-16 13:16:56Z peter $
5 
6 /*
7  Copyright (C) 2003 Daniel Dalevi, Peter Johansson
8  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér
10  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
11  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
12  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
13  Copyright (C) 2009, 2012, 2017, 2019 Peter Johansson
14 
15  This file is part of the yat library, http://dev.thep.lu.se/yat
16 
17  The yat library is free software; you can redistribute it and/or
18  modify it under the terms of the GNU General Public License as
19  published by the Free Software Foundation; either version 3 of the
20  License, or (at your option) any later version.
21 
22  The yat library is distributed in the hope that it will be useful,
23  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25  General Public License for more details.
26 
27  You should have received a copy of the GNU General Public License
28  along with yat. If not, see <http://www.gnu.org/licenses/>.
29 */
30 
31 #include "config_public.h"
32 
33 #include "VectorMutable.h"
34 #include "Exception.h"
35 
36 #include <cstddef> // size_t
37 #include <iosfwd>
38 #include <stdexcept>
39 
40 #include <gsl/gsl_vector.h>
41 
42 namespace theplu {
43 namespace yat {
44 namespace utility {
45 
59  class Vector : public VectorMutable
60  {
61  public:
65  Vector(void);
66 
73  explicit Vector(size_t n, double init_value=0);
74 
81  Vector(const Vector& other);
82 
86  template<class T>
88  : VectorMutable(detail::create_gsl_vector_copy(other.gsl_vector_p()))
89  {
90  }
91 
97  Vector(Vector&& other) noexcept;
98 
104  template<class T>
106  : VectorMutable(other.gsl_vector_p())
107  {
108  other.gsl_vector_p(NULL);
109  }
110 
117  explicit Vector(const VectorBase& other);
118 
131  explicit Vector(std::istream &, char sep='\0');
132 
136  ~Vector(void);
137 
141  bool isview(void) const;
142 
153  void resize(size_t, double init_value=0);
154 
164  const Vector& operator=(const Vector&);
165 
171  template<class T>
173  {
174  // access rhs before deleting vec_
175  gsl_vector* tmp = detail::create_gsl_vector_copy(rhs.gsl_vector_p());
176  delete_allocated_memory();
177  const_vec_ = vec_ = tmp;
178  return *this;
179  }
180 
190  Vector& operator=(Vector&&);
191 
197  template<class T>
199  {
200  gsl_vector* tmp = rhs.gsl_vector_p();
201  delete_allocated_memory();
202  const_vec_ = vec_ = tmp;
203  rhs.gsl_vector_p(NULL);
204  return *this;
205  }
206 
207 
217  const Vector& operator=(const VectorBase&);
218 
219  private:
220  const Vector& assign(const VectorBase& other);
221  const Vector& assign(const gsl_vector* rhs);
222 
234  gsl_vector* create_gsl_vector_copy(const VectorBase&) const;
235 
236 
237  void delete_allocated_memory(void);
238  };
239 
249  void swap(Vector&, Vector&);
250 
251 }}} // of namespace utility, yat, and theplu
252 
253 #endif
void resize(size_t, double init_value=0)
Resize Vector.
The Department of Theoretical Physics namespace as we define it.
const Vector & operator=(const Vector &)
The assignment operator.
const gsl_vector * const_vec_
pointer to underlying GSL vector
Definition: VectorBase.h:168
Vector & operator=(VectorExpression< T > &&rhs)
move assignment from vector expression
Definition: Vector.h:198
This is the yat interface to GSL vector.
Definition: Vector.h:59
This is the yat interface to GSL vector.
Definition: VectorBase.h:55
Vector(const VectorExpression< T > &other)
Constructor from a vector expression.
Definition: Vector.h:87
gsl_vector * vec_
Definition: VectorMutable.h:269
An expression that can be converted to a Vector.
Definition: VectorExpression.h:67
This is the mutable interface to GSL vector.
Definition: VectorMutable.h:56
Vector(VectorExpression< T > &&other)
Move constructor from Vector expression.
Definition: Vector.h:105
Vector & operator=(const VectorExpression< T > &rhs)
assignment from vector expression
Definition: Vector.h:172
Vector(void)
The default constructor.
const gsl_vector * gsl_vector_p(void) const
return a GSL vector pointer
Definition: VectorExpression.h:110

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14