yat  0.17.3pre
Vector.h
1 #ifndef _theplu_yat_utility_vector_
2 #define _theplu_yat_utility_vector_
3 
4 // $Id: Vector.h 3855 2020-01-02 01:11:34Z 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 
92 #ifdef YAT_HAVE_RVALUE
93 
98  Vector(Vector&& other) noexcept;
99 
105  template<class T>
107  : VectorMutable(other.gsl_vector_p())
108  {
109  other.gsl_vector_p(NULL);
110  }
111 #endif
112 
119  explicit Vector(const VectorBase& other);
120 
133  explicit Vector(std::istream &, char sep='\0');
134 
138  ~Vector(void);
139 
143  bool isview(void) const;
144 
155  void resize(size_t, double init_value=0);
156 
166  const Vector& operator=(const Vector&);
167 
173  template<class T>
175  {
176  // access rhs before deleting vec_
177  gsl_vector* tmp = detail::create_gsl_vector_copy(rhs.gsl_vector_p());
178  delete_allocated_memory();
179  const_vec_ = vec_ = tmp;
180  return *this;
181  }
182 
183 #ifdef YAT_HAVE_RVALUE
184 
193  Vector& operator=(Vector&&);
194 
200  template<class T>
202  {
203  gsl_vector* tmp = rhs.gsl_vector_p();
204  delete_allocated_memory();
205  const_vec_ = vec_ = tmp;
206  rhs.gsl_vector_p(NULL);
207  return *this;
208  }
209 
210 #endif
211 
221  const Vector& operator=(const VectorBase&);
222 
223  private:
224  const Vector& assign(const VectorBase& other);
225  const Vector& assign(const gsl_vector* rhs);
226 
238  gsl_vector* create_gsl_vector_copy(const VectorBase&) const;
239 
240 
241  void delete_allocated_memory(void);
242  };
243 
253  void swap(Vector&, Vector&);
254 
255 }}} // of namespace utility, yat, and theplu
256 
257 #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:201
const gsl_vector * gsl_vector_p(void) const
return a GSL vector pointer
Definition: VectorExpression.h:112
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
void swap(Vector &, Vector &)
Swap Vector elements by copying.
This is the mutable interface to GSL vector.
Definition: VectorMutable.h:56
Vector(VectorExpression< T > &&other)
Move constructor from Vector expression.
Definition: Vector.h:106
Vector & operator=(const VectorExpression< T > &rhs)
assignment from vector expression
Definition: Vector.h:174
Vector(void)
The default constructor.
bool isview(void) const

Generated on Thu Aug 27 2020 03:33:19 for yat by  doxygen 1.8.11